cobalt_generator 1.7.0
cobalt_generator: ^1.7.0 copied to clipboard
Code generator for Cobalt dependency injection. Annotate classes with @cobaltInject and build_runner writes the container, failing the build when a dependency is missing.
1.7.0 #
- The generated names lose the
$:CobaltRootis the class,startCobalt,cobaltBootstrapSteps,cobaltRootScopeNameandNoteEditorArgsthe functions, constant and records. The bootstrap list iscobaltBootstrapStepsbecausecobaltBootstrapis the annotation. - The
$names are still written, as@Deprecatedaliases, and go in 2.0. Code that uses them gets a deprecation hint; with--fatal-infosthat fails the analysis, so rename:$CobaltRootScopetoCobaltRoot,$startCobalttostartCobalt,$cobaltBootstraptocobaltBootstrapSteps,$cobaltRootScopeNametocobaltRootScopeName,$XArgstoXArgs. - A decorator of a class only child scopes register is applied in each of those scopes and may inject what that scope sees. Before, the build refused it.
1.6.0 #
- Each call-site record also gets a name without the
$:typedef NoteEditorArgs = $NoteEditorArgs;. Left out when two classes would share the name or a class of the package already has it. The$name stays until 2.0. - The generated root overrides
hasBootstrapwhen the package has bootstrap steps, which needscobalt1.6.0.
1.5.0 #
- Child scopes. Each
@CobaltChildScopemarker gets a builder,final class SessionScope implements CobaltScopeBuilder, that registers the marker's values and every class withscope: Session. The completeness check runs per scope along itsparentchain: a registration may inject what its scope, the scopes above it and the root register, and the root injecting what only a child scope registers fails the build naming that scope. Decorators and hooks stay in the root. $CobaltRootScope, and with itCobaltRoot, extendsCobaltRootBuilder: it carries the name from@CobaltScopeRootand, when the package has bootstrap steps, abootstrap()that returns new ones.CobaltAppScope.builder(root: const CobaltRoot())starts under that name. The root takes anenvironmentwhenever the bootstrap list depends on one.- The root promises each type in
provideswithscope.promise, so a promise the wrapping builder does not keep is reported at startup. - The generated code needs
cobalt1.5.0, whichcobalt_analyzer1.5.0 requires.
1.4.0 #
- A constructor parameter with a default value is left out of the call when nothing in the graph registers its type, so the default applies. One that is positional and comes before an injected parameter is still a build error, which now says to make it named.
@CobaltInject(exposeAs: Store, instantiations: [...])registers each instantiation under its ownStore<Note>,Store<User>.cobalt.g.dartalso declaresCobaltRoot, the root scope under a name without a dollar. Requirescobalt_analyzer1.4.0.
1.3.0 #
@injectedfields work on a generic class with@CobaltInject(instantiations: [...]). The class mixes in one_$Cache<T>carrying its type parameters, bounds included; each instantiation resolves the field under its own type arguments, and a dependency missing for one instantiation fails the build for that one alone. Requirescobalt_analyzer1.3.0.
1.2.0 #
- Generic classes:
@CobaltInject(instantiations: [Cache<Note>, Cache<Tag>])registers each listed instantiation with its own factory, named after its type arguments (_CacheOfNoteFactory;Pair<String, int>becomes_PairOfStringAndIntFactory), and each constructor resolves its ownStore<Note>orStore<Tag>. A raw type, a duplicate entry,exposeAsor an@injectedfield next toinstantiationsis a build error. - A type argument keeps its
?in a registration's key:Cache<Note?>andCache<Note>are two registrations, as they are two types at runtime. Before, the?inside type arguments was dropped. - Requires
cobalt_analyzerandcobalt_annotations1.2.0. - The README opens with how to install it and a Quick start, and the pubspec description says what the generator does.
1.1.1 #
- No code changes in this package. Republished in lockstep with 1.1.1:
a shorter README with a Quick start,
examples/helloas the smallest app,docs/OVERVIEW.mdfor everything the README no longer holds, anddocs/TROUBLESHOOTING.md, one entry per error.
1.1.0 #
- No code changes in this package. Republished in lockstep with 1.1.0, which adds Korean to the inspector and to the documentation.
1.0.0 #
- The API is stable: from here on, only a major release breaks it — see Compatibility in the README. No code changes in this package since 0.9.0; coming from an older 0.x, MIGRATION lists what to change.
0.9.0 #
$startCobalt(initTimeout:), passed through toCobaltApplication.start.- Every generated factory implements
CobaltDescribedFactory, naming the class it builds, sodescribeGraphshows it —ApiClient — lazySingleton, as LiveApiClient. The generated file changes accordingly. - A hook class is
final class … extends CobaltHook<T>now thatCobaltHookis a base class.
0.8.0 #
- Emits
scope.hookAll<T>(...)for every@cobaltHookAllclass, first in the root scope — ahead of every registration, so an eager one passes through it — byorder, then class name, and guarded by@CobaltEnvironmentlike any registration. CobaltGenerationErrorisfinal.
0.7.0 #
- No code changes in this package. Republished in lockstep with 0.7.0, which
makes
CobaltResolvera base class (breaking), adds getters toCobaltRegistrationKindand lets the inspector open on a chosen tab — seecobalt's changelog.
0.6.0 #
- No code changes in this package. Republished in lockstep with 0.6.0, which
adds build times to observers and the inspector, a graph snapshot in
cobalt_testand a lint rule — seecobalt's changelog.
0.5.0 #
- Async transients: a transient
@CobaltInitclass, or a transient module member returning aFuture, becomes aCobaltAsyncFactoryregistered withregisterAsyncFactory, awaiting lazy dependencies throughgetAsync. A synchronous or eager dependent, an@injectedfield of its type, a decorator taking it and adependsOnnaming it are build errors. @CobaltDecorates(allNames: true)is emitted asscope.decorateAll. Decorators are emitted by type and then byorder, and a decorator of every name counts for each key of its type in the order check, graph edges and cycles, and deriveddependsOn; any registration of the type — or aprovides:of it — satisfies its target.@injectedfields on a decorator class: the property injection builder writes its_$ClassNamemixin, and the generated decorator builds it asClass(inner, ...)..onInject(resolver).
0.4.0 #
- Async parameterized factories: an
@CobaltInitclass taking an@CobaltParambecomes aCobaltAsyncParamFactorythat constructs, awaitsinit()and awaits any lazy dependency throughgetAsync, registered withregisterAsyncParamFactory. AdependsOnnaming one is a build error, and it takes no deriveddependsOnof its own.
0.3.0 #
- Decorators. Each
@CobaltDecoratesclass becomes a constCobaltDecoratorand ascope.decorate<Target>(...)after the registrations inbuild(), guarded by its environments, with the annotated class as itsdebugLabel. - The build refuses a target nothing registers in some environment of the decorator, a decorator dependency nothing registers, two decorators of one registration without distinct orders, a decorator taking a lazy async registration, and a cycle through a decorator.
- An eager async class that resolves a decorated registration while phase 1
runs — directly or through synchronous registrations — waits in its
dependsOnfor the async dependencies of those decorators. The wait sits on the consumer, not the target, so an override of the target keeps it.
0.2.1 #
- Accepts
analyzerup to 14.x (>=10.0.1 <15.0.0, was<13.0.0) anddart_styleup to 3.1.x (>=3.1.7 <3.2.0, was<3.1.9). Flutter 3.38.9 stays the floor. - The container is formatted at language version 3.10 rather than at
DartFormatter.latestLanguageVersion, which moves with eachdart_stylerelease and gates its style changes. Every analyzer row emits identical bytes, and a future formatter release cannot change the committed output. Generated code does not change with this release.
0.2.0 #
- Lazy async registrations are emitted with
registerLazyAsyncSingleton, and their factoriesawait resolver.getAsync<T>()for every dependency that is lazy too —isRegisteredfirst for a nullable one. - Build errors for what would fail on the device instead: a synchronous or
eager async class injecting a lazy one, an
@injectedfield of a lazy type on any class, anddependsOnnaming a lazy registration. A lazy module member is not given a deriveddependsOn. - An eager singleton is emitted as
registerEagerSingleton, so the scope builds it and an override can skip it; before, the instance existed before the registration was made. $startCobalttakesoverrides:and hands them toCobaltApplication.start.
0.1.2 #
- No code changes in this package. Republished in lockstep with a
packaging fix in
cobalt0.1.2 (a stray file removed from its archive) — see its changelog. A fix in one package still ships as a patch for all fifteen, because publishing a subset is what lets the set drift.
0.1.1 #
- No code changes in this package. Republished in lockstep with the fix
in
cobalt_lint0.1.1 — see its changelog. Lockstep is the whole versioning policy: a fix in one package still ships as a patch for all fifteen, because publishing a subset is what lets the set drift.
0.1.0 #
-
Requires Dart
^3.10.0— Flutter 3.38 — instead of^3.13.0, and movesanalyzerto>=10.0.1 <13.0.0withdart_styleto>=3.1.6 <3.1.9. The two formatters that range admits emit identical bytes for generated code, so no generated file changed; the floor job regenerates and diffs to keep that true. -
A nullable
@CobaltParamkeeps its?in the generated record. It used to be dropped, narrowing an argument the constructor was willing to take as null. -
A module member may take named parameters. They were refused because the emitter passed everything positionally; it no longer does. An optional parameter is still refused, for the reason it always was.
-
A class with
@CobaltParamparameters is generated as a parameterized factory, with a named record type emitted beside the container. Marked parameters are not dependencies: they are skipped by the completeness check and are no edge in the ordering. -
Constructors with named parameters are called the way they were declared. Every argument used to go in positionally, producing a file that did not compile.
-
The
_$ClassNameinjection mixin is written for every class the container registers,@CobaltInitincluded. Such a class used to be registered and left with its@injectedfields unassigned. -
@CobaltInit(dependsOn:)naming a registration that is not itself@CobaltInitfails the build, listing every such edge at once. -
Two libraries in one package declaring classes of the same name no longer emit two factories of the same name. Every claimant of a contested base name gets a suffix from its own library; uncontested names are untouched, so the fix renames nothing in an existing file.
-
Initial release.
-
Three builders:
cobalt_property_injection(per-file mixins viaSharedPartBuilder),cobalt_scan(per-library IR to.cobalt.json, cached) andcobalt_container(aggregates every IR intolib/cobalt.g.dart). All areauto_apply: dependents— declaring the dev dependency is the setup. -
Emits named const factory classes, never closures, and orders registrations by a compile-time topological sort in which property-injected fields count as dependency edges.
-
Import aliases come from a hash of the URL, so adding one import does not renumber the rest and produce a whole-file diff.
-
Rejects a graph with a dependency nothing registers, listing every gap in one message and checking each environment separately. Registrations made by hand are declared through
@CobaltScopeRoot(provides: [...]). -
Rejects at build time what would otherwise be silent: a dependency cycle, two registrations of one key whose environments overlap, and
@CobaltInjecton a class with type parameters. -
Generic types work as dependencies and as
exposeAstargets:Repository<User>andRepository<Order>are separate registrations. -
Emits factories for
@CobaltModulemembers, calling the member on a const module instance. Async ordering between module members is derived from the graph rather than declared. -
A nullable dependency is optional: it is emitted as
getOrNulland skipped by the completeness check, while still ordering registration when the type is present.@CobaltInit(dependsOn:)is never optional, and a module member may not return a nullable type.