fix(nx): fall back to workspace cwd when run-commands target has no cwd#1638
fix(nx): fall back to workspace cwd when run-commands target has no cwd#1638webpro merged 3 commits intowebpro-nl:mainfrom
Conversation
|
Why add a different type of test? Please see other (Nx) tests. Running |
74e6cb1 to
b686101
Compare
|
Removed the redundant The fix itself is a one-line defensive correctness change: |
|
You're right, let's just roll with it 🛼 |
commit: |
When an nx:run-commands target does not specify options.cwd (which is the
common case), the Nx plugin was passing `cwd: undefined` to
getInputsFromScripts. Because the spread in WorkspaceWorker
(`{ ...baseOptions, ...options }`) includes undefined-valued properties,
this overrides the valid baseOptions.cwd, causing a crash in the bash
parser's error handler: `path.relative(undefined, ...)` throws
ERR_INVALID_ARG_TYPE.
Fall back to `options.cwd` (the workspace root) instead of `undefined`.
Fixes webpro-nl#1637
Remove separate unit test file. Instead, add a `bun run` command in an nx:run-commands target without explicit cwd to the existing fixture. This exercises the fix end-to-end — crashes without it, passes with it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The existing fixture already has multiple nx:run-commands targets without options.cwd (webpack, ls-project-root, generate-docs, lint). Adding another one doesn't exercise any new code path.
fe1124a to
fc24af6
Compare
|
Thanks. Waiting on your approval 🙏 |
|
🚀 This pull request is included in v6.0.5. See Release 6.0.5 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
|
Thanks Lior! |
Summary
Fixes #1637
When an
nx:run-commandstarget does not specifyoptions.cwd(which is the common case), the Nx plugin passescwd: undefinedtogetInputsFromScripts. Because the spread inWorkspaceWorker({ ...baseOptions, ...options }) includes undefined-valued properties, this overrides the validbaseOptions.cwd, causing a crash in the bash parser's error handler —path.relative(undefined, ...)throwsERR_INVALID_ARG_TYPE.Root cause
Fix
Fall back to
options.cwd(the workspace root) instead ofundefined:Tests
Added
test/plugins/nx-run-commands-no-cwd.test.tswith two test cases:getInputsFromScriptsreceives the workspacecwd(notundefined)cwdis properly joined with the workspace rootBoth tests are verified to fail without the fix and pass with it. Existing Nx plugin tests continue to pass.