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
    ah ya we probably don't count overrides as "dependencies" if it doesn't also appear in deps/dev_deps
    Alan Knight
    @alanknight-wk
    But part of the original weirdness was that if I had the dependency override to a normal hosted one it worked, but if I used a path or a git dependency override then it went slow
    So maybe there's an issue that those are being treated more like direct dependencies
    We
    We're going to try explicitly disabling it
    Jacob MacDonald
    @jakemac53
    ya that sounds good, if you think there is a bug on our end (it sounds like maybe?) please file one :)
    Alan Knight
    @alanknight-wk
    Roger. Thanks.
    Chandra Sekhar Kode
    @chandu0101
    In my codegen project , i am using PartBuilder with two generators (gen1,gen2) ,gen2 depends on types generated by gen1 , i am getting types as dynamic for all things generated by gen1 on first run after that further generations by gen2 getting types of gen1 generated, how can i make sure that gen1 ran before gen2 on first build run?
    Simon Binder
    @simolus3
    @chandu0101 You could use runs_before to specify that gen1 runs before gen2.
    Jacob MacDonald
    @jakemac53
    You also would need to not use the SharedPartBuilder but the regular PartBuilder - otherwise no part is included in the lib until all parts are created and merged together.
    Chandra Sekhar Kode
    @chandu0101
    @simolus3 thanks for reply , if i understand correctly runs_before takes different builder name! but my two gens are in same builder ..
    class Gen1 extends GeneratorForAnnotation<Anno1> {
    }
    class Gen2 extends GeneratorForAnnotation<Anno2> {
    }
    Builder myBuilder(BuilderOptions options) {
      return PartBuilder([Gen1(),Gen2()],".example.dart");
    }
    Jacob MacDonald
    @jakemac53
    These would have to be split into separate builders to see the output of each other. Or you could do one builder with multiple outputs potentially.
    Chandra Sekhar Kode
    @chandu0101

    @jakemac53 thank you, looks like i need to create two builders .

    you could do one builder with multiple outputs potentially.

    could you please elaborate on this ... , link me to some examples ?

    Jacob MacDonald
    @jakemac53
    Looking at it the source_gen package really doesn't support this well. I would just split it into two builders. If you did want to use source_gen you would declare an extra output file with the additionalOutputExtensions option and then manually output that file inside your generator. Then you would need to re-resolve the library using the build step (and not use the LibraryReader you are passed), you could create a new LibraryReader from that newly resolved Library though.
    Chandra Sekhar Kode
    @chandu0101
    @jakemac53 thanks for info :)
    Michael Vetter
    @jubalh
    Hi. I'm not sure this is the right channel to ask this question. I'm a packager for a Linux distro and wondered where I can see the build instructions to build dart itself
    I would like to create a package
    I found https://github.com/dart-lang/sdk/wiki/Building and it seems like kind of a problem that still python2 is required. I think most distros removed that now
    Simon Binder
    @simolus3
    @jubalh I think that python script just wraps ninja and bazel, which is what's actually used to build the SDK. It might be possible to extract the right ninja commands and just run them without python. And I see you've already found the issue to upgrade to Python 3 :)
    Denis Bakhtin
    @tabula-rasa
    Hello. Can anyone point me into the right direction, please. I have created my own builder that implements Builder interface, it parses all html files in a specific directory and creates corresponding dart files. Everything works ok, but I need to generate a 'manifest' file (in the same folder) that exports all my newly generated files for easy imports. Do I need to create another builder and where can I find an example...
    Or is there any kind of hook I could use
    Simon Binder
    @simolus3
    @tabula-rasa Hi, I think what you're looking for is an aggregate builder. You can write another builder taking lib/$lib$ as input and manifest.dart as output. It could then use buildStep.findAssets to find the Dart files emitted by your first builder. You also need to add a runs_before to the first builder to ensure all Dart files are ready when the aggregate builder runs.
    Denis Bakhtin
    @tabula-rasa
    @simolus3 thank you for quick response, looks like this is what I needed!
    Denis Bakhtin
    @tabula-rasa

    I have another question: how do I force a build_runner to process nested files. I have the following build.yaml:

    targets:
      $default:
        builders:
          dirk_code_builder:
            enabled: True
    builders:
      dirk_code_builder:
        import: "package:dirk/builder.dart"
        builder_factories: ["dirkCodeBuilder"]
        build_extensions: 
          '$lib$': [".dirk.dart"]
        auto_apply: dependents
        build_to: source
        defaults:
          options:
            input_folder: lib/views/
            output_folder: lib/views/code/
            start_file: _start.dirk.html
            layout_file: layout.dirk.html

    My builder source code is the following:

    const String _inputFileExtension = '.dirk.html';
    const String _outputFileExtension = '.dirk.dart';
    
    class DirkCodeGenerator implements Builder {
      Map<String, List<String>> _buildExtensionsCopy;
    
      @override
      Map<String, List<String>> get buildExtensions =>
          _buildExtensionsCopy ??= generateExtensions(_options);
    ...
    }
    
    Map<String, List<String>> generateExtensions(Map<String, dynamic> options) {
      final filesList = Directory(options['input_folder'])
          .listSync(recursive: true)
          .where(
              (FileSystemEntity file) => file.path.endsWith(_inputFileExtension));
    
      final result = <String, List<String>>{};
    
      filesList.forEach((FileSystemEntity element) {
        final name = split(element.path).last.split('.').first.replaceAll('-', '_');
        result[element.path] = <String>[
          '${options["output_folder"]}$name$_outputFileExtension',
        ];
      });
    
      print(result);
      return result;
    }

    The problem is: generateExtensions sees nested files in /lib/views/, for example /lib/views/shared/menu.dirk.html, but in the build method they are absent, only direct children of /lib/views/ are present. Thank you.

    Simon Binder
    @simolus3

    There are a bunch of things that are looking off here: First, buildExtensions should almost always be a constant. There are a few exceptions for builders re-usable across projects, but that's not what you have here. Also, don't ever use File or Directory inside a builder. The build package generalizes over the way assets are stored (there could be build implementations fetching assets over a network, and build implementations might write some assets to a hidden folder in .dart_tool). It also breaks mechanisms like incremental rebuilds.

    I'm not sure what exactly your builder is doing. Does it create one .dirk.dart file from a .dirk.html input, but in another folder? If you tell us a bit more about what your builder is doing we can find a way to express that without using raw io or dynamic build extensions.

    Denis Bakhtin
    @tabula-rasa
    Good notes :) Tbh, the generateExtensions part was taken from a swagger-dart-code-generator, and comes from insufficient understanding of the build process, I will read the docs to find a better way, since you pointed that build abstractions are more powerful regarding the source of the files. I uploaded the project to github dirk repo for future reference. Simply put, I'm developing a view engine with code interpolation, and it, yes, creates a .dirk.dart file for each .dirk.html. For now, the source folder is /lib/views and the output is /lib/views/code. I'm still learning dart and its ecosystem, so my work may be far from a masterpiece :)
    Denis Bakhtin
    @tabula-rasa
    The problem is - /lib/views/shared folder is ignored and I don't know what to do about this.
    Simon Binder
    @simolus3

    Ah, I see. It sounds like your builder essentially operates on each file independently, right? In that case, I would probably ditch the aggregate builder in favor of a regular builder - take .dirk.html as input and .dirk.dart as output. To only run on files in /lib/views by default, you don't need a build option with globs. Instead, you can configure this when you define your builder:

    builders:
      dirk_code_builder:
        build_extensions: {'.dirk.html': '.dirk.dart'}
        # ...
        defaults:
          generate_for: ['lib/views/**']

    Users can override generate_for if they want to. And in general, a single build step is the smallest unit of invalidation in the build system. So if you want to process more than one file, doing that in multiple build steps enables fast and incremental rebuilds. If you have a single build step where you do everything by matching a glob, you'd have to re-process every file on every edit. With those simple extensions, your builder gets a new build step for each file.
    The builder definition from above has the problem that generated code goes to lib/views as well (not in lib/views/code). Allowing directory moves in builders is not well supported at the moment (dart-lang/build#1689 ), so I think it might be reasonable to just generate the files in lib/views as well. You could implement directory moves with a combination of three builders:

    1. An invisible (build_to: cache) builder from .dirk.html to .dirk.dart. Users would never see the generated files in lib/views since this is only for intermediate results
    2. An aggregate builder (build_extensions: {'lib/$lib$': ['views.tar']}, build_to: cache) that writes all the generated files into a tar file
    3. A post-process builder that extracts the tar file into lib/views/code/.

    In addition to being complicated, this approach has downsides as well (other builders couldn't read the final .dirk.dart files for instance). Each regular (non post-processing) builders may only have a fixed amount of outputs per primary input, and they must be relative to the input file. This might sound very limiting, but it's exactly what enables build_runner to do fast and incremental rebuilds. So everything that prevents fast units of work tends to be a little bit more complicated :)

    Denis Bakhtin
    @tabula-rasa
    Awesome, thank you for guidance, really appreciate that. Yes, I process each file independently. Will try that options without directory moves and see how it goes)
    bekoswe
    @bek0swe
    hello guys i'm new on flutter&dart . I'm getting this error when i'm trying to put build_runner , freeze packages into pubspec_yaml : Because freezed >=0.13.0-nullsafety.0 depends on build ^1.6.0 and build_runner >=1.12.0 depends on build >=2.0.0 <2.1.0, freezed >=0.13.0-nullsafety.0 is incompatible with build_runner >=1.12.0.
    can someone help?
    Jacob MacDonald
    @jakemac53
    You should file an issue on freezed to update to build version 2.0.0. In the meantime lower your build_runner requirement to something like ^1.11.0.
    bekoswe
    @bek0swe
    @jakemac53 thank u a lot
    Matias Meno
    @enyo
    When I build my project with webdev or build_runner all dart files and sourcemaps are copied to the build directory as well. How can I avoid that from happening? I don't want to expose the source code
    I already provide the --production flag
    Simon Binder
    @simolus3
    @enyo I also ran into similar issues with build directories, sometimes there were even missing some assets... I ended up using this. It works, but it feels very hacky. You could adapt _shouldSkipNode to manually exclude nodes that were generated and don't end in .dart.js.
    Jacob MacDonald
    @jakemac53
    The --release flag should be cleaning up any Dart files and source maps, if you are using build_web_compilers. Please file an issue if it isn't.
    Caio Granero
    @caiogranero

    Hi everyone, i have a question. I'm using json_serializable and firestore. json_serializable creates a factory method with Map<String, dynamic> as parameter but after nullsafety changes, firestore start to return a Map<String, dynamic>? as document data and now i can't call json_serializable factory to map my firestore types. can someone help me with this?

    I wrote this example:

    class Entity {
      const Entity({required this.id});
    
      final String id;
    
      factory Entity.fromJson(Map<String, dynamic> json) => _$EntityFromJson(json);
      Map<String, dynamic> toJson() => _$EntityToJson(this);
    }
    
    class Repository {
      Stream<List<Entity>> list() {
        return FirebaseFirestore.instance.collection('entity').snapshots().map((event) {
          return event.docs.map((e) {
            return Entity.fromJson(
              e.data() // The argument type 'Map<String, dynamic>?' can't be assigned to the parameter type 'Map<String, dynamic>'
            );
          }).toList();
        });
      }
    }
    Emilio Dalla Torre
    @emiliodallatorre

    Hi everyone,
    I noticed that - after json_serializable 4.0 update - I cannot use it to generate JSON for my project anymore (needless to say, my project is not null-safe).

    As the main option (downgrading json_serializable) is not available for me (I have other packages conflicts that needs me to keep latest version), I'm currently trying to make json_serializable >= 4.0 work on an unsafe nullable environment.

    Should I raise an issue on GitHub?
    Do someone has any ideas?

    Caio Granero
    @caiogranero
    @emiliodallatorre Your problem sound like mine, i figure out that i need to check if Firestore response is not null before mapping with json_serializable so i think you could try to check this and make all methods nullable.
    Emilio Dalla Torre
    @emiliodallatorre

    Hi @caiogranero. Unfortunately, this is not the problem... I forgot to say that I cannot even generate my .g.dart files as I cannot use json_serializable >=4.0 in a nullable environment.

    Your problem can easily be solved by regenerating your files with latest json_serializable: if you, for instance, declare a string like final String uid;, then json_serializable will act as if it's surely not null on Firebase and will throw an error otherwise.
    If you make that string nullable, json_serializable will generate a nullable deserializer and let the string null if it's null on Firebase.

    Jacob MacDonald
    @jakemac53

    @caiogranero You can either assert the map you got is non-null:

    e.data()!

    or provide a default map:

    e.data() ?? const {}
    or otherwise handle the null map in some other way
    Nick Meinhold
    @nickmeinhold
    Hi! I’m new to package:build and trying write an openapi client generator which generates Dart from markdown, then uses that generated Dart in the next step in combination with a json file to generate a Dart client for that API. My problem is that I can’t seem to get the second builder to wait for the first builder to finish so the output Dart is available. I’ve read the docs and tried various combinations of runs_beforeand applies_builders but nothing seems to work… any suggestions? Thanks!
    This is my build.yaml, I’m trying to make clientBuilder only run when schemaBuilder is done:
    targets:
      openapi_client_builder:
        builders:
          openapi_client_builder:schemaBuilder:
            enabled: true
          openapi_client_builder:clientBuilder:
            enabled: true
    
    builders:
      schemaBuilder:
        import: package:openapi_client_builder/openapi_schema_builder.dart
        builder_factories: [ schemaBuilder ]
        build_extensions:
          input/openapi_spec.md: [ output/schema_classes.dart ]
        build_to: source
        auto_apply: root_package
        runs_before: [ openapi_client_builder:clientBuilder ]
      clientBuilder:
        import: package:openapi_client_builder/openapi_client_builder.dart
        builder_factories: [ clientBuilder ]
        build_extensions:
          input/app-store-connect-openapi.json: [ output/client.dart ]
        build_to: source
        auto_apply: root_package
    Nick Meinhold
    @nickmeinhold
    Actually thinking about it more, I guess I’m trying to do something weird here in wanting Dart code generated in a build step to be part of the running program in a later step… I hadn’t thought it through properly sorry... so I guess I would need to have separate packages, one dependent on the other, and run build_runner separately on each in this case? Thanks!
    Simon Binder
    @simolus3

    wanting Dart code generated in a build step to be part of the running program in a later step

    Yup, that doesn't work. The build script is compiled ahead of time, so builders can't generate themselves :D The runs_before option only reflects that assets generated by schemaBuilder can be read by clientBuilder.

    so I guess I would need to have separate packages, one dependent on the other, and run build_runner separately on each in this case

    That would be a solution, but really I would try to avoid a situation where you need to run build_runner in a specific order for each change. That will be very annoying in practice. Maybe you can rewrite your builders in such a way that none depends on generated code? I could envision a build setup like this:

    1. Have a build_to: cache builder transforming the markdown into a json structure that your builders can pick up
    2. Make the schemaBuilder take that json as input and use that to write the schema classes
    3. Let the clientBuilder take the two jsons to figure out the right client code without importing it itself.
    Nick Meinhold
    @nickmeinhold
    Awesome thanks for that @simolus3! And thanks for taking the time to explain an alternate strategy - I will see if I can rewrite the builders in such a way that none depends on generated code, as you suggest. Thanks again!
    sunbreak
    @sunbreak:matrix.org
    [m]
    I'm trying to add argments to protoc_plugin according to dart-lang/protobuf#497
    I've found the useGrpc flag, but not found others. Could anyone shed some light?