Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running injectable_generator from a pub workspace root package #487

Open
ryanhanks-bestow opened this issue Jan 8, 2025 · 0 comments
Open

Comments

@ryanhanks-bestow
Copy link

Hey @Milad-Akarie,

I'm trying to run the injectable_generator builders from my pub workspace's root package against the packages included within the workspace. With the following in my root package's pubspec.yaml:

name: workspace_example

environment:
  sdk: ^3.6.0

workspace:
  - packages/a
  - packages/b

dependencies: # I don't notice much difference in behavior if a,b are included as dependencies of the root or not
  a:
  b:
dev_dependencies:
  build_runner:
  injectable_generator:

and a build.yaml as follows:

targets:
  $default:
    sources:
      include:
        - '$package$'
        - lib/$lib$
        - packages/**.dart

I'm noticing a couple issues trying to build micro packages for a,b:

  1. The generateForDir paths supplied to @InjectableInit.microPackage don't seem to allow for any value that will cause the builder to recognize dependencies I have marked within a given package (I tried the default config, '.', and 'packages/a/lib' for package a)
  2. The builder does produces a .module.dart file for micro packages in packages a and b, but the produced MicroPackageModule is given a name based on the resolution of the root packages package-name, i.e.,
//@GeneratedMicroModule;WorkspaceExamplePackageModule;asset:workspace_example/packages/a/lib/package.module.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// coverage:ignore-file

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i687;

import 'package:injectable/injectable.dart' as _i526;

class WorkspaceExamplePackageModule extends _i526.MicroPackageModule {
// initializes the registration of main-scope dependencies inside of GetIt
  @override
  _i687.FutureOr<void> init(_i526.GetItHelper gh) {}
}

I've configured some of my other builders to run from here and it's convenient, but also started noticing some curious behavior when running injectable_generator from packages I've now included into a workspace. I don't have the particular warnings I was seeing on-hand, as I haven't found a way to reliably reproduce this, but in scenarios where I'm generating for a package with no other dependencies inside of their defined workspace (i.e., only dependent on 'external' packages from outside the workspace), the builder seemed to be doing a lot of "inspection" of assets from other packages within the workspace that I would normally assume it to have no interest in being concerned with.

Is there a way to run the injectable_generator builders from a pub workspace package root? Or if not, have you given any thought to supporting this use case?

Looking forward to trying to get this working, lmk if you've any thoughts, ideas, or solutions I'm missing.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant