Skip to content

fix: load blueprint options before command validation (fixes #10872)#10879

Open
AyushKashyapII wants to merge 2 commits intoember-cli:masterfrom
AyushKashyapII:fix-blueprint-options-warning#10872
Open

fix: load blueprint options before command validation (fixes #10872)#10879
AyushKashyapII wants to merge 2 commits intoember-cli:masterfrom
AyushKashyapII:fix-blueprint-options-warning#10872

Conversation

@AyushKashyapII
Copy link

Description

Fixes #10872.

Currently, commands like new and addon validate their arguments before loading the options defined in the target blueprint. This causes the CLI to warn that "The option 'x' is not registered" even if the blueprint explicitly defines that option in its availableOptions.

The Fix

  1. Execution Order: Modified lib/models/command.js to execute the beforeRun hook (which calls mergeBlueprintOptions) inside validateAndRun before the argument validation/parsing occurs.
  2. Blueprint Lookup: Updated lib/utilities/merge-blueprint-options.js. Since nopt parsing hasn't happened yet at this stage, the helper now manually parses rawArgs to find the blueprint name (handling -b, --blueprint, and defaulting to app/addon), ensuring the correct options are merged.
  3. Regression Fix: Fixed a crash in mergeDuplicateOption that was exposed by this timing change. Previously, if a blueprint option had undefined aliases, flatMap would throw an error. Added a fallback || [] to prevent this.

Reproduction

  1. Create a blueprint that has a custom option (e.g., --pizza in availableOptions).
  2. Run ember new my-app --pizza=cheese.
  3. Before: The CLI warns: The option '--pizza' is not registered with the 'new' command.
  4. After: The CLI accepts the option silently and passes it to the blueprint as expected.

Testing

  • Added a unit test in tests/unit/models/command-test.js to verify beforeRun is called before argument parsing.
  • Verified manually that ember new and ember addon no longer emit warnings for valid blueprint flags.

…i#10872) and also handle missing aliases when merging duplicate options
@NullVoxPopuli
Copy link
Contributor

Needs some work <3

❯ node bin/ember new my-app --blueprint /✂️/emberjs/ember-app-blueprint --minimal
The option '--minimal' is not registered with the 'new' command. Run `ember new --help` for a list of supported options.
installing ember-app-blueprint
✨  Creating a new Ember app in <repo>/my-app:
The "path" argument must be of type string. Received an instance of Array


Stack Trace and Error Report: /tmp/error.dump.795192316a8a0de9cf025525534b229f.log

@AyushKashyapII
Copy link
Author

@NullVoxPopuli Thanks for the review!

I have addressed the feedback:
Fixed Path Resolution: I added normalizeBlueprint to the early lookup in merge-blueprint-options.js. This ensures that when passing a path (e.g., --blueprint ./local/path), it resolves correctly instead of crashing.
Fixed Alias Crash: I verified that mergeDuplicateOption could crash if a blueprint option had aliases: undefined. I updated command.js to handle this defensively (aliases || []).
I verified this locally using a test blueprint at a relative path (./blueprints/test) with custom flags, and confirmed both the warnings and the crash are gone. Ready for review!

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.

Blueprints should be allowed to have their own flags

2 participants