Skip to content

fix(@angular/cli): keep schematic positional arguments in index order - #34445

Merged
clydin merged 3 commits into
angular:mainfrom
thekhegay:fix-positional-argument-order
Oct 20, 2026
Merged

clydin merged 3 commits into
angular:mainfrom
thekhegay:fix-positional-argument-order

Conversation

@thekhegay

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

My library ngwr ships page schematic with two positionals, preset at index 0 (required, has x-prompt) and name at index 1
Command from its docs fails on 22.2.3:

$ ng g ngwr:page form signup
Error: Invalid values:
  Argument: preset, Given: "signup", Choices: "dashboard", "form", "table"

Help prints page [name] [preset]

Sort at end of parseJsonSchemaToOptions checks a.positional for truthiness, so index 0 is ordered like plain option and lands after index 1, and generate builds its comand string from that order
With x-prompt both positionals are optional for yargs and values get swapped, without it only help order is wrong since yargs fills <required> first

What is the new behavior?

Positionals are sorted by index (checked with !== undefined), plain options stay sorted by name after them
ng g ngwr:page form signup works and help prints page [preset] [name]

New case in json-schema_spec.ts has preset at index 0 with x-prompt and name at index 1, it fails on main
Also added fake-reversed schematic to generate/help-output.ts e2e, it gets [a] <b> on main
Existing <a> [b] case passes on main only becasue index order and alphabetical order are same there

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

In @schematics/angular only interface has two positionals (name 0, type 1), they already sort same way, so nothing changes there
Built CLI from this branch and ran documented ngwr:page commands with --dry-run, all pass

sort checked `positional` for truthiness, so argument at index 0 was ordered like plain option and help showed it after index 1
when that argument has `x-prompt` both are optional for yargs and values go to wrong argumnets, now positionals are sorted by index

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request fixes a bug in the JSON schema option parser where positional arguments with an index of 0 were incorrectly sorted because 0 is falsy. The sorting logic has been updated to explicitly check for undefined rather than relying on truthiness. Additionally, unit and E2E tests have been added to verify that positional arguments are sorted correctly by their index. There are no review comments, and I have no feedback to provide.

@alan-agius4 alan-agius4 added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Oct 20, 2026
Comment thread packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts Outdated
Comment thread tests/e2e/tests/generate/help-output.ts Outdated
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Oct 20, 2026

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@thekhegay
thekhegay requested a review from alan-agius4 October 20, 2026 13:49
@clydin
clydin merged commit d69dcec into angular:main Oct 20, 2026
40 checks passed
@clydin

clydin commented Oct 20, 2026

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

@thekhegay
thekhegay deleted the fix-positional-argument-order branch October 21, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants