Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jacob MacDonald
    @jakemac53
    As far as the invalidation goes yes if the definition file doesn't change, then any step that reads that definition file only won't be re-ran. I am not sure if it is smart enough to not even do the write to that file or not, in theory it could be.
    Jacob Phillips
    @jifalops
    Thanks that's very helpful. The .gql => dart part isn't totally fleshed out, but the way it is above will have A => B, C and A, B => C as a dependency relationship. That seems a little wonky.
    Jacob MacDonald
    @jakemac53

    For the 2nd case if I follow correctly I think that could work but would require at least 2 builders - one to generate those import.txt files first, and then the next builder to actually generate the dart files (which read those). So you probably end up reading the .gql files multiple times, once in each builder? But I don't have all the context really.

    In general you are probably over-optimizing here a bit and it would be simpler/better to just accept the slightly less than ideal invalidation. If you are not using a Resolver, then build steps are generally quite fast. It might make it slower just by making the build more complex.

    Jacob Phillips
    @jifalops
    The imports thing is so that ever y.gql doesn't need read each time one is modified (if watching for changes). I'm not sure if that's over optimization or not. Reading the same file twice doesn't seem bad.
    Jacob MacDonald
    @jakemac53
    You could also use a Resourcehttps://pub.dev/documentation/build/latest/build/Resource-class.html - that would allow you to avoid re-parsing those files and to just cache the info
    You still would get a dependency on them and get invalidated more often. It depends how many of those files you expect I suppose.
    I don't think we much in terms of docs for using Resources, but here is a sort of similar example one https://github.com/dart-lang/build/blob/372dce1d7d04deb254d1db5ad433bbcaf3a7c471/build_modules/lib/src/module_cache.dart
    Jacob Phillips
    @jifalops
    Cool I had tried to use a Resource before but wasn't sure if it would help.
    Jacob MacDonald
    @jakemac53
    You need to be careful as you can abuse them to break invalidation and such - make sure to at least call canRead when reading from your cache like here https://github.com/dart-lang/build/blob/372dce1d7d04deb254d1db5ad433bbcaf3a7c471/build_modules/lib/src/module_cache.dart#L61.
    That will give the caller a dependency on that file that is actually being fetch from your cache (and ensure it has access to it also)
    Olzhas Suleimen
    @ykmnkmi
    Anyone know how to analyzer files with analyzer without using parseFile, parseString? with session and context.
    Simon Binder
    @simolus3
    @ykmnkmi You mean regular files outside of a build? You can follow the basic tutorial here.
    Olzhas Suleimen
    @ykmnkmi
    @simolus3 thanks.
    GTMS
    @gtms_gitlab
    Is there a way i can run tests and serve my app without collisions? Now they are trying to rebuild in endless loop.
    rockyoung
    @rockyoung
    sdk issue dart-lang/language#1297 metioned about the generic metadata annotations, how do we get the generic type as the annotation is provided as a ConstantReader?
    Simon Binder
    @simolus3
    @rockyoung Call typeValue on the ConstantReader to get a DartType. If it's an InterfaceType, you can get the instantiation through typeArguments.
    rockyoung
    @rockyoung
    @simolus3 thanks for the reply, i tried calling typeValue on the ConstantReader, but it failed with the 'FormatException: Not an instance of Type.'
    that make sense, cause the ConstantReader annotation is actually an instance of the annotation defined by myself.
    rockyoung
    @rockyoung
    @simolus3 ok, i solved this with your solution, but use objectValue.type instead of typeValue, thanks bro :)
    rockyoung
    @rockyoung

    But there is a point to note that the const annotation instance must have explicit type declaration like:

    const MyAnnotation<MyType> myAnnotation = MyAnnotation<MyType>(...); // pseudocode
    
    @myAnnotation
    class Balabala {}

    and if i write like this:

    const myAnnotation = MyAnnotation<MyType>(...); // pseudocode

    the typeArgument is always dynamic...

    mtc-jed
    @mtc-jed
    Hi, why does json_annotation need to be specified under dependencies and not dev_dependencies ? Is it for the building process to work ?
    1 reply
    Simon Binder
    @simolus3

    the typeArgument is always dynamic...

    That's surprising, the analyzer should be able to figure it out either way. Is there an error in the definition of the annotation?

    1 reply
    @mtc-jed There's no direct technical reason for that, but the general rule is that things you import and use in lib/ should be a regular dependency. If you're writing a package, dev-dependencies won't be passed to downstream users. Since your package's code needs the classes from json_annotation in lib/, downstream users should get the json_annotation package as well. So, we put it under dependencies :)
    mtc-jed
    @mtc-jed
    @simolus3 Thanks for the clarification !
    vexcat
    @vexcat
    Hello! I'd like to manually compile a simple .dart file using dartdevc, as I have found a bug that seems to only affect dartdevc and not dart2js. Is there an easy way to do this? I've been trying various build_runner commands to no avail.
    This is the code i'm trying to compile btw: https://pastebin.com/Nts65Kmk
    Simon Binder
    @simolus3
    @vexcat My understanding is that dartdevc compiles individual Dart files into modular JavaScript, and requires a custom loading strategy to load deps like the SDK itself. It should work if you create a new project, depend on build_runner and build_web_compilers and put the source file into web/. Then you can just run build_runner serve to serve compiled JS modules.
    (But async* is broken in so many different ways across Dart implementations it's ridiculous)
    Jonathan Rezende
    @jodinathan
    it seems that my builder is only being ran at first time when using webdev serve. Is there any config to make webdev also behave like the build watcher?
    Jacob MacDonald
    @jakemac53
    webdev serve should run like watch mode
    Jonathan Rezende
    @jodinathan
    but when I add a class with an annotation that has a builder from other package, it doesn't run the builder to create the part files
    Jacob MacDonald
    @jakemac53
    can you confirm if you do the same thing in watch mode (via build_runner) it does work?
    both things go through almost the same code path
    Jonathan Rezende
    @jodinathan
    from the logs of build_runner watch the builder is called but the file is not updated
    as I am not in null safety it may be a bug that have been corrected in newer versions
    mtc-jed
    @mtc-jed
    Try the --delete-conflicting-outputs option
    Jonathan Rezende
    @jodinathan
    that did the trick for build_runner watch @mtc-jed
    do you know how can I use this with webdev serve?
    stefyk
    @stefyk:matrix.org
    [m]
    Hello, is there a way to serialize private fields with https://pub.dev/packages/json_serializable without getters/setters? I currently have public fields and use methods to get the value, for example, getPublicField() => publicField. I want to make the fields private, without changing the code in every place where I use those methods. Any help would be appreciated. Ty.
    Özcan Esnaf
    @ozc_gitlab

    Hi. I'm trying to parse and convert .md files to .dart files. I've been able to run extended Builder.build() method.

    The problem is, I only get .md files in / and /lib folders. I'm trying to fetch only package:/stories/*.md files

    Simon Binder
    @simolus3
    @ozc_gitlab The default target doesn't contain custom directories, so your builder is not invoked for files in say stories/. You can configure which sources to include with a build target configuration in a build.yaml file.
    Özcan Esnaf
    @ozc_gitlab
    Tried adding sources but still it does not include files in /stories folder.
    What I've found is, it does include /web folder by default. So until I dig deeper to find the real issue, I'm continuing my development using /web folder for now. Thanks.
    Hesam
    @Hesamedin

    Hello guys, I have a question regarding json_annotation.
    My. problem is that whenever I run the following command, then it compiles all of my models.

    flutter pub run build_runner build --delete-conflicting-outputs

    Is there any way to tell the above command that build for a defined model only?
    something like this command:

    flutter pub run build_runner build --delete-conflicting-outputs --file=/lib/model/api_response.dart
    Simon Binder
    @simolus3
    @Hesamedin Use build_runner build --build-filter lib/model/api_response.g.dart. Be sure to specify the file that you want to generate. The build system will figure out the necessary inputs by itself.
    Hesam
    @Hesamedin
    @simolus3 Awesome. Works like a charm. Thank you for your help and reply.
    cjcdev
    @cjcdev
    Is there a way to get the package version from pubspec.yaml in source code?
    Simon Binder
    @simolus3
    @cjcdev Inside a builder, yes. You could take a look at how build_version is implemented for that (basically, just parse the pubspec and extract the version). At runtime without extracting the version into a field, not really.
    cjcdev
    @cjcdev

    @simolus3 Thanks! I actually found the "build_version" package. At build time it creates a 'version.dart' file with a const String defined with the version number. This works for me. I'm still new to flutter/dart, so one thing I'm unclear about is how to integrate this into the build automatically.

    The instructions say to do a build as:

    dart pub run build_runner build

    And this will generate the version.dart - great.

    However, this dart package I am trying to get the version from is actually a library I am developing that is accessed from a Flutter app I'm developing. Now, when I build the app (with this library included), it does not execute that 'build_runner' step above. How can I make the Flutter app build trigger that step in the library?

    Simon Binder
    @simolus3

    If you control the library, I'd just add build_version as a dependency to the library, run build_runner build and ship the generated version.dart file with the library. A downside is that you mustn't forget to run the build in the library everytime you prepare a new version.

    Since you're also developing the app depending on those libraries, you could also write a builder that emits a version.dart file for all the packages that you depend on. I'm not aware of an existing builder doing that, but you could take a look at my license collector and change that code to write the version instead of the license.

    cjcdev
    @cjcdev
    @simolus3 I think I was focusing on my current development process where the app includes the package as a relative path (because I'm actively building the test app and library at the same time). But the normal release cycle will probably be creating a tag in git with matching package version. This will probably automated in a script, so as part of that I can run build_runner build. Thanks again for helping me work through this!