fix(batch): export NODE_OPTIONS as a statement so compound shell commands work (#925)#934
Open
hakanbaysal wants to merge 1 commit into
Open
fix(batch): export NODE_OPTIONS as a statement so compound shell commands work (#925)#934hakanbaysal wants to merge 1 commit into
hakanbaysal wants to merge 1 commit into
Conversation
…ands work (mksglu#925) The POSIX branch of buildBatchNodeOptionsPrefix emitted an inline `NODE_OPTIONS='...' <command>` assignment. That form is only valid before a *simple* command, so any batch command starting with a compound construct (`if`, `for`, `while`, a `(...)` subshell, or a `{ ...; }` group) was rewritten into invalid shell and failed with `syntax error near unexpected token`. The failed run was then indexed, surfacing the syntax error instead of the intended output. Emit a standalone `export NODE_OPTIONS='...'; ` statement instead. This mirrors the PowerShell (`$env:...; `) and cmd (`set "..." && `) branches, which already use a separate statement, and composes with any following command. As a bonus the exported value now also reaches `node` invocations *inside* compound constructs (e.g. a `for` loop body), which the inline form could not do. Updates the POSIX prefix test and adds real-compound-command coverage.
21 tasks
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.
What / Why / How
Fixes #925.
Batch shell commands that start with a compound construct (
if,for,while, a(...)subshell, or a{ ...; }group) failed withsyntax error near unexpected token. The failed run was then indexed, soctx_searchsurfaced the syntax error instead of the intended output.Root cause: the POSIX branch of
buildBatchNodeOptionsPrefixemitted an inlineNODE_OPTIONS='...' <command>assignment. That form is only valid before asimple command, so prefixing
if .../for .../(...)produced invalidshell.
Fix: emit a standalone
export NODE_OPTIONS='...';statement instead. Thismirrors the PowerShell (
$env:...;) and cmd (set "..." &&) branches, whichalready use a separate statement, and composes with any following command. As a
bonus, the exported value now also reaches
nodeinvocations inside compoundconstructs (e.g. a
forloop body), which the inline form could not do.Affected platforms
Test plan
NODE_OPTIONS='...' if ...; then ...; fierrors at
then; the newexport NODE_OPTIONS='...'; if ...runs, as doforloops and(...) | sedsubshell pipes. ConfirmedexportpropagatesNODE_OPTIONSto childnodeprocesses.composes with the three compound examples from the issue.
npx vitest run tests/core/server.test.ts -t "buildBatchNodeOptionsPrefix"→ 4 passed;
runBatchCommandssuite → 25 passed.npx tsc --noEmit→ clean.Checklist
npm testpasses (server suite; full build requires Node >=22.5)npm run typecheckpassesnextbranch