Repository navigation
fix(executors): let CLI options override project.json options - #91
Merged
Merged
Conversation
- 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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-hmrConfigurations 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).commonExecutorthen re-read the raw target and ranmergeDeep(options, target.options)followed bymergeDeep(options, target.configurations[name]).mergeDeeplets the source win, so every CLI value for a key present inoptionswas 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 inoptionswholesale instead of combining sub-properties.Precedence after this PR
CLI > configuration (
-c,defaultConfiguration, or the one picked at the prompt) > project.jsonoptions> schema defaults, deep-merged, so nestedandroid/iossub-properties fromoptionsand 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 (
ExecutorContexthas nooverrides; in a forked task they arrive over IPC, notprocess.argv). Two options:$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.util.isDeepStrictEqual) from what that target'soptions+ configuration produce on their own. The options are then rebuilt asmergeDeep({}, resolved, target.options, configuration, cliOverrides).For the normal path (no prompt) this is exact. The one approximation is a key set in neither
optionsnor 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:
context.targetName). The deep-merge source is stilltargets[options.command]as before, so workspaces whose target name differs from the command name keep their current merge behaviour.options/configurationsobjects in the project graph.selectConfiguration/selectPlatformfrom feat: migrate to Nx 24 #90 are unchanged (module scope, TTY-safe).Behaviour change for users
optionsand in the selected configuration. Previously it was dropped.apps/toolboxin the NativeScript repo:defaultConfiguration: "default",hmr: { noHmr: false }) keeps working unchanged, but it's no longer needed:nx debug toolbox ios --noHmr=falsenow works directly.nscommand as before.Tests
New
packages/nx/src/utils/executor-options.spec.tsrunscommonExecutorend to end with options built by Nx's realcombineOptionsForExecutorand the generatedprepare.schema.json. It mockschild_process.spawnand asserts on thensargument list:falseon the CLI overridestruein options (noHmr,release)provision)uglify,provision,noHmr)androidsub-properties from options + configuration combine, and a CLI sub-property overrides only that sub-propertyWithout 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 buildpasses.Verification (real runs)
Packed
dist/packages/nx, installed it into a fresh Nx 24.0.7 workspace, rannx g @nativescript/nx:app apps/demo --framework=vanilla, and added adev: { uglify: false, release: false }configuration to thepreparetarget (options:noHmr, production, uglify, release, forDevice: true). NativeScript CLI 9.1.2; every run below exited 0 (full webpack prepare). Thensline is the one the executor prints.Before (#90 baseline):
After: