Skip to content

Add --enable-experiment to jaspr build and jaspr serve - #895

Merged
schultek merged 1 commit into
schultek:mainfrom
diegolopezrm:feat/enable-experiment
Nov 12, 2026
Merged

schultek merged 1 commit into
schultek:mainfrom
diegolopezrm:feat/enable-experiment

Conversation

@diegolopezrm

Copy link
Copy Markdown
Contributor

Description

Adds --enable-experiment to jaspr build and jaspr serve, which is what #877 needs.

There was no way for an app to turn a Dart language experiment on. An experiment has to be enabled in three places for a Jaspr app, and the app cannot reach any of them from its own analysis_options.yaml:

  • the analyzer behind buildStep.resolver, which is what Jaspr's own builders see — that is the one that fails in Support primary constructors in @client components #877, with This requires the 'primary-constructors' language feature to be enabled from jaspr_builder:client_module
  • the web compilers, since the code still has to compile
  • the Dart command that runs or compiles the server

build_runner already covers the first two: it takes --enable-experiment and puts the list in a zone (withEnabledExperiments), which build_resolvers turns into the analyzer's feature set and build_web_compilers reads for kernel, ddc, dart2js and dart2wasm. build_web_compilers even points at that flag when it sees an experiment in dart2js_args:

`dart run build_runner --enable-experiment=<experiment> ...`

Since jaspr launches build_runner rather than the user, the flag had nowhere to come from. It now does, and it is passed on in the same shape to the Dart VM invocation in jaspr serve and to dart compile in jaspr build, so server code may use the experiment as well.

jaspr serve --enable-experiment=primary-constructors
jaspr build --enable-experiment=primary-constructors,other-experiment

Type of Change

  • ✨ New feature or improvement

Tests

packages/jaspr_cli/test/helpers/experiment_helpers_test.dart, following the shape of the --dart-define tests: no experiments by default, one experiment, the option repeated, and a comma separated list — asserting both what is parsed and the --enable-experiment=<name> flags that get handed on.

dart test test/helpers is green in packages/jaspr_cli (28 tests), and the option shows up in jaspr build --help and jaspr serve --help.

What I could not verify here is the end of the chain for #877 specifically: primary constructors need Dart 3.13 and this machine is on 3.12.2, so I confirmed the flag reaches build_runner and follows its documented path rather than watching that component build. Worth a check by @tomwyr or anyone on 3.13.

Fixes #877

@diegolopezrm

diegolopezrm commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@tomwyr tried this on his end and the build passes with the flag. Thanks for checking, that's the part I couldn't test from 3.12.2.

One odd thing in his output: Dart prints 'primary-constructors' is now enabled by default; this flag is no longer required, but without the flag the build still fails anyway. I think the analyzer that build_runner resolves is older than his SDK, so as far as it's concerned the feature is still off, and the flag is what turns it on. Doesn't change anything here, since the option is for experiments in general and not just this one, but worth knowing this case will keep needing it until build_resolvers catches up.

@diegolopezrm

diegolopezrm commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Same question as #896: want this one on next too? It adds a flag rather than fixing something, so I'd guess yes. Say the word and I'll rebase and retarget.

For context, @tomwyr confirmed on #877 that the build passes against this branch with --enable-experiment=primary-constructors, on the SDK where it originally failed.

@schultek

Copy link
Copy Markdown
Owner

Yes lets also rebase this onto next.

As I wrote in #877 the specific issue is probably already fixed on next (at least I couldn't reproduce on next), but this flag is still a nice feature for future dart language experiments.

@diegolopezrm
diegolopezrm changed the base branch from main to next September 25, 2026 03:41
@diegolopezrm

diegolopezrm commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto next and retargeted. The changelog was the only conflict; the entry is under New features now.

Good to know it doesn't reproduce on next, that makes sense with the analyzer bump there. The flag still earns its place for the next experiment, and for anyone who needs one before that lands.

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Package Version Report

The following packages have been updated:
jaspr_test : 0.23.5 -> 0.24.0-beta.0
jaspr : 0.23.5 -> 0.24.0-beta.0
jaspr_builder : 0.23.5 -> 0.24.0-beta.0
jaspr_cli : 0.23.5 -> 0.24.0-beta.0
jaspr_router : 0.9.0 -> 0.10.0-beta.0
jaspr_content : 0.5.4 -> 0.6.0-beta.0
jaspr_flutter_embed : 0.4.11 -> 0.5.0-beta.0
jaspr_lints : 0.7.2 -> 0.8.0-beta.0
jaspr_riverpod : 0.4.6 -> 0.5.0-beta-0
jaspr_serverpod : 0.6.1 -> 0.7.0-beta.0

Jaspr launches `build_runner` itself, so an app had no way to turn on a Dart
language experiment. `build_runner` takes `--enable-experiment` and puts it in
a zone that everything inside the build reads: the analyzer behind
`buildStep.resolver`, which is what Jaspr's own builders see, and
`build_web_compilers` for kernel, ddc, dart2js and dart2wasm. Nothing of that
can be reached from the app's `analysis_options.yaml`, which is why a
`@client` component written with a primary constructor failed the build while
the same component built fine unannotated.

The option now goes to `build_runner` from both commands, and to the other
places the CLI compiles or runs the app's code: the server, whether
`jaspr serve` runs it or `jaspr build` compiles it or runs it to generate a
static site, the compiler that generates the stylesheets, and the expression
evaluation DWDS does for the debugger.

Fixes schultek#877
@diegolopezrm
diegolopezrm force-pushed the feat/enable-experiment branch from 6eed874 to d9d67f8 Compare October 22, 2026 17:49
@diegolopezrm

Copy link
Copy Markdown
Contributor Author

Rebased onto next. With the CLI refactor there are a few more places that compile the app's code, so the flag now also goes to the CSS runner, the static generation server and DWDS (for expression evaluation). Added a test for build and one for serve.

@schultek
schultek changed the base branch from next to main October 23, 2026 09:38
@schultek
schultek requested a balanced review from Copilot October 23, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused argument-forwarding changes have regression coverage and no identified blocking defects, though end-to-end validation of primary constructors remains outstanding.

No open issues 🎉

What changed in this PR

Adds --enable-experiment to jaspr build and jaspr serve, enabling applications to pass Dart language experiments through Jaspr’s build and development workflows for cases such as #877.

Changes:

  • Adds shared parsing for repeated and comma-separated experiment options.
  • Forwards experiments to build_runner, server execution and compilation, stylesheet compilation, and development compiler settings.
  • Adds parsing and command-forwarding tests, plus a changelog entry.
File Description
packages/​jaspr/​CHANGELOG.md Documents the new option.
packages/​jaspr_cli/​test/​src/​commands/​serve_command_test.dart Tests forwarding to build_runner and the development server.
packages/​jaspr_cli/​test/​src/​commands/​build_command_test.dart Tests forwarding to build_runner and server compilation.
packages/​jaspr_cli/​test/​helpers/​experiment_helpers_test.dart Tests default, single, repeated, and comma-separated options.
packages/​jaspr_cli/​lib/​src/​helpers/​experiment_helpers.dart Defines shared experiment parsing, help text, and argument formatting.
packages/​jaspr_cli/​lib/​src/​dev/​server_runner.dart Passes experiments to development and static-rendering servers.
packages/​jaspr_cli/​lib/​src/​dev/​dev_workflow.dart Passes experiments to stylesheet generation and development compiler settings.
packages/​jaspr_cli/​lib/​src/​dev/​css_runner.dart Enables experiments during stylesheet compilation.
packages/​jaspr_cli/​lib/​src/​commands/​dev_command.dart Registers the option and forwards experiments through development workflows.
packages/​jaspr_cli/​lib/​src/​commands/​build_command.dart Registers the option and forwards experiments through production builds.

Review effort: Balanced

@schultek schultek left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this contribution!

@schultek
schultek merged commit 1444402 into schultek:main Nov 12, 2026
11 checks passed
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

Successfully merging this pull request may close these issues.

Support primary constructors in @client components

3 participants