fix: load blueprint options before command validation (fixes #10872) by AyushKashyapII · Pull Request #10879 · ember-cli/ember-cli
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
- Execution Order: Modified
lib/models/command.jsto execute thebeforeRunhook (which callsmergeBlueprintOptions) insidevalidateAndRunbefore the argument validation/parsing occurs. - Blueprint Lookup: Updated
lib/utilities/merge-blueprint-options.js. Sincenoptparsing hasn't happened yet at this stage, the helper now manually parsesrawArgsto find the blueprint name (handling-b,--blueprint, and defaulting toapp/addon), ensuring the correct options are merged. - Regression Fix: Fixed a crash in
mergeDuplicateOptionthat was exposed by this timing change. Previously, if a blueprint option had undefined aliases,flatMapwould throw an error. Added a fallback|| []to prevent this.
Reproduction
- Create a blueprint that has a custom option (e.g.,
--pizzainavailableOptions). - Run
ember new my-app --pizza=cheese. - Before: The CLI warns:
The option '--pizza' is not registered with the 'new' command. - 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.jsto verifybeforeRunis called before argument parsing. - Verified manually that
ember newandember addonno longer emit warnings for valid blueprint flags.
…i#10872) and also handle missing aliases when merging duplicate options
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
@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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters