Skip to content

Commit e5a9bbf

Browse files
committed
feat: Patch the NodeJS subshell launch in the bin script as well. Replace with exec
1 parent bb00362 commit e5a9bbf

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

scripts/patch-oclif.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,19 @@ const PATCH = ` # CODIFY_PATCH_START — do not remove this marker
8484
# CODIFY_PATCH_END — do not remove this marker
8585
`;
8686

87-
await fs.writeFile(BIN_JS, content.slice(0, idx) + PATCH + content.slice(idx), 'utf8');
87+
const patched = content.slice(0, idx) + PATCH + content.slice(idx);
88+
89+
// Use exec to replace the shell process with Node rather than spawning a child.
90+
// This avoids an extra process in memory and ensures signals go directly to Node.
91+
const NODE_LAUNCH = ' "\\$NODE" ';
92+
const NODE_LAUNCH_EXEC = ' exec "\\$NODE" ';
93+
let withExec = patched;
94+
if (patched.includes(NODE_LAUNCH) && !patched.includes(NODE_LAUNCH_EXEC)) {
95+
withExec = patched.replace(NODE_LAUNCH, NODE_LAUNCH_EXEC);
96+
} else if (!patched.includes(NODE_LAUNCH_EXEC)) {
97+
console.error('ERROR: Could not find Node launch line to add exec. The oclif version may have changed.');
98+
process.exit(1);
99+
}
100+
101+
await fs.writeFile(BIN_JS, withExec, 'utf8');
88102
console.log('Successfully patched oclif bin.js');

0 commit comments

Comments
 (0)