Skip to content

fix(executors): let CLI options override project.json options - #91

Merged
NathanWalker merged 12 commits into
mainfrom
fix/executor-cli-overrides
Nov 25, 2026
Merged

NathanWalker merged 12 commits into
mainfrom
fix/executor-cli-overrides

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

Stacked on #90 (Nx 24). Base is feat/nx-24; this will be retargeted to main once #90 merges.

Problem

CLI flags passed to the plugin's executors are silently ignored whenever the same key is set in the target's options:

nx run app:debug --noHmr=false   # project.json has "noHmr": true -> ns still gets --no-hmr

Configurations merged after the options still win, so the only workaround today is a named configuration (defaultConfiguration: "default", configurations: { default: {}, hmr: { noHmr: false } }) plus -c hmr.

Root cause

Nx already passes the executor fully resolved options (combineOptionsForExecutor: schema defaults < options < configuration < CLI). commonExecutor then re-read the raw target and ran mergeDeep(options, target.options) followed by mergeDeep(options, target.configurations[name]). mergeDeep lets the source win, so every CLI value for a key present in options was overwritten, and a configuration overwrote CLI values too.

That re-merge exists for a good reason: Nx merges shallowly, so a configuration's android: {...} / ios: {...} replaces the one in options wholesale instead of combining sub-properties.

Precedence after this PR

CLI > configuration (-c, defaultConfiguration, or the one picked at the prompt) > project.json options > schema defaults, deep-merged, so nested android / ios sub-properties from options and the configuration still combine, and a CLI --android.keyStorePassword=... overrides only that sub-property.

Approach

Nx 24 doesn't expose the raw CLI overrides to an executor (ExecutorContext has no overrides; in a forked task they arrive over IPC, not process.argv). Two options:

  1. Add a hidden schema property with $default: { $source: 'unparsed' } to receive __overrides_unparsed__ and parse the raw argv. That means re-implementing Nx/yargs flag parsing (kebab/camel case, aliases, --no-*, dotted keys) and adding an option to every schema.
  2. Infer the CLI keys from what Nx resolved (chosen). The executor knows the target and configuration Nx resolved from, so a key is a CLI override when its resolved value differs (util.isDeepStrictEqual) from what that target's options + configuration produce on their own. The options are then rebuilt as mergeDeep({}, resolved, target.options, configuration, cliOverrides).

For the normal path (no prompt) this is exact. The one approximation is a key set in neither options nor the Nx-applied configuration: it could be a CLI flag or a schema default. It only matters when a configuration was picked at the interactive prompt (which Nx didn't apply), and there the configuration wins, the same as before this PR.

Other details:

  • The baseline is the target Nx actually invoked (context.targetName). The deep-merge source is still targets[options.command] as before, so workspaces whose target name differs from the command name keep their current merge behaviour.
  • The merge no longer mutates the options / configurations objects in the project graph.
  • selectConfiguration / selectPlatform from feat: migrate to Nx 24 #90 are unchanged (module scope, TTY-safe).

Behaviour change for users

  • A CLI flag now wins over the same key in options and in the selected configuration. Previously it was dropped.
  • The named-configuration workaround (e.g. apps/toolbox in the NativeScript repo: defaultConfiguration: "default", hmr: { noHmr: false }) keeps working unchanged, but it's no longer needed: nx debug toolbox ios --noHmr=false now works directly.
  • Runs with no CLI overrides produce the same ns command as before.

Tests

New packages/nx/src/utils/executor-options.spec.ts runs commonExecutor end to end with options built by Nx's real combineOptionsForExecutor and the generated prepare.schema.json. It mocks child_process.spawn and asserts on the ns argument list:

  • project.json options apply when nothing is passed on the CLI
  • boolean false on the CLI overrides true in options (noHmr, release)
  • string on the CLI overrides options (provision)
  • configuration overrides options
  • CLI overrides configuration (uglify, provision, noHmr)
  • nested android sub-properties from options + configuration combine, and a CLI sub-property overrides only that sub-property
  • CLI overrides a configuration chosen at the interactive prompt

Without the fix, 5 of these 7 fail, including the boolean one. npm test: 6 files / 33 tests pass. npm run lint: 0 errors. npm run build passes.

Verification (real runs)

Packed dist/packages/nx, installed it into a fresh Nx 24.0.7 workspace, ran nx g @nativescript/nx:app apps/demo --framework=vanilla, and added a dev: { uglify: false, release: false } configuration to the prepare target (options: noHmr, production, uglify, release, forDevice: true). NativeScript CLI 9.1.2; every run below exited 0 (full webpack prepare). The ns line is the one the executor prints.

Before (#90 baseline):

nx run nativescript-demo:prepare --platform=ios --noHmr=false
  ns prepare ios --no-hmr --env.uglify --env.production --for-device --release --force
nx run nativescript-demo:prepare --platform=ios --release=false --uglify=false
  ns prepare ios --no-hmr --env.uglify --env.production --for-device --release --force
nx run nativescript-demo:prepare --platform=ios -c dev --uglify=true
  ns prepare ios --no-hmr --env.production --for-device --force

After:

nx run nativescript-demo:prepare --platform=ios
  ns prepare ios --no-hmr --env.uglify --env.production --for-device --release --force
nx run nativescript-demo:prepare --platform=ios --noHmr=false
  ns prepare ios --env.uglify --env.production --for-device --release --force
nx run nativescript-demo:prepare --platform=ios --release=false --uglify=false
  ns prepare ios --no-hmr --env.production --for-device --force
nx run nativescript-demo:prepare -c prod --platform=ios
  ns prepare ios --no-hmr --env.uglify --env.production --for-device --release --force --env.replace="./src/environments/environment.ts:./src/environments/environment.prod.ts"
nx run nativescript-demo:prepare --platform=ios -c dev
  ns prepare ios --no-hmr --env.production --for-device --force
nx run nativescript-demo:prepare --platform=ios -c dev --uglify=true --noHmr=false
  ns prepare ios --env.uglify --env.production --for-device --force

- nx and @nx/* 23.1.0 -> 24.0.7, nx-cloud 19.1.3 -> 19.1.5; typescript stays 6.0.3, vitest stays 3.2.x
- nx migrate: set affected.legacy, convert the removed @nx/eslint:lint executor to the @nx/eslint/plugin inferred target
- exclude generator template dirs from @nx/eslint/plugin so their package.json files are not picked up as projects
- library spec: Nx 24 lint is inferred via @nx/eslint/plugin instead of an explicit executor target
Nx 24 turns eslintFilePatterns into an explicit `eslint <glob>` command that fails on the brace pattern when no spec files exist. Let @nx/eslint/plugin infer `eslint .` and add flat-config ignores for platforms/, hooks/ and references.d.ts instead.
The triple-slash references in references.d.ts fail @typescript-eslint/triple-slash-reference, so a freshly generated library did not lint clean.
Without a TTY, the configuration and platform prompts crashed with ERR_USE_AFTER_CLOSE. A missing configuration now falls back to no configuration, the same as answering "No" interactively and the same as Nx's own behavior without -c, and logs the existing warning. A missing platform has no sensible default, so it fails with an error pointing at --platform or --silent (which already defaults to iOS).
workspace-lint, workspace-generator, affected:apps, affected:libs and help no longer exist, so npm run lint failed. Use run-many/affected -t, show projects and graph, including for the affected:<target> and dep-graph aliases that still work. Drop start (no project has a serve target).
The vanilla template has no src/main.ts; its entry is src/app.ts.
Both app templates ship tailwind.config.js and an app.css with tailwind directives, but only the Angular app added @nativescript/tailwind and tailwindcss to the root package.json, so a vanilla app failed to prepare.
@nativescript/core, types, ios and android ~9.0.0 -> ~9.1.0 (latest 9.1.4 / 9.1.4 / 9.1.1 / 9.1.2). @nativescript/webpack ~5.0.0 is already current; @nativescript/tailwind stays on the 2.x line with tailwindcss 3.
nx.json keeps the Nx 24 eslint plugin and affected.legacy settings and takes the release config and nx-release-publish target default from main. package-lock.json is this branch's Nx 24 lockfile; npm install against the merged package.json leaves it unchanged.
nx release reads the current version from packages/nx/package.json, so a prerelease bump on main yields 24.0.0-next.N and a manual major release yields 24.0.0.
Nx hands the executor options already resolved as schema defaults <
target options < configuration < CLI, but the executor deep-merged the
raw target options and configuration back on top, so any CLI flag for a
key set in project.json was discarded (e.g. --noHmr=false against
"noHmr": true).

Rebuild the options with a deep merge in Nx's precedence order and
re-apply the CLI-provided keys last. Nx does not expose which keys came
from the CLI, so a key is treated as a CLI override when its value
differs from what the invoked target and configuration produce. Nested
android/ios sub-properties from options and configuration still combine.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d019cd7-cf74-406e-b8fc-582df3bd33f2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@NathanWalker
NathanWalker changed the base branch from feat/nx-24 to main November 25, 2026 23:26
@NathanWalker
NathanWalker merged commit f9b4c25 into main Nov 25, 2026
4 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.

1 participant