Skip to content

Commit 0a5b939

Browse files
committed
Simplify & fix node interception approach
Previously we injected into $PATH directly so that we could take complete control. With NODE_OPTIONS this isn't actually necessary, since the only option we care about can be set just from env vars directly. This would've been more difficult to set up back when this was written, since it was only included in node 8, but it's been backported to 6.12 and node 6 and 8 are both EOL now, so I think we can handle that. This notably also fixes interception issues with anything that respawns node using process.execPath (i.e. Yarn) which previously skipped the hooks setup. Using these env vars instead lets us punch right through that.
1 parent 28ddd7b commit 0a5b939

File tree

4 files changed

+6
-40
lines changed

4 files changed

+6
-40
lines changed

overrides/js/prepend-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* plus tweaks various other HTTP clients that need nudges, so they
55
* all correctly pick up the proxy from the environment.
66
*
7-
* Tested against Node 6, 8, 10 and 12.
7+
* Tested against Node 6, 8, 10, 12 and 14.
88
*/
99

1010
const wrapModule = require('./wrap-require');

overrides/path/node

Lines changed: 0 additions & 16 deletions
This file was deleted.

overrides/path/node.bat

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/interceptors/terminal/terminal-env-overrides.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const PATH_VAR_SEPARATOR = process.platform === 'win32' ? ';' : ':';
99
export const OVERRIDES_DIR = path.join(APP_ROOT, 'overrides');
1010
const OVERRIDE_RUBYGEMS_PATH = path.join(OVERRIDES_DIR, 'gems');
1111
const OVERRIDE_PYTHONPATH = path.join(OVERRIDES_DIR, 'pythonpath');
12+
const OVERRIDE_JS_SCRIPT = path.join(OVERRIDES_DIR, 'js', 'prepend-node.js');
1213

1314
export const OVERRIDE_BIN_PATH = path.join(OVERRIDES_DIR, 'path');
1415

@@ -69,8 +70,9 @@ export function getTerminalEnvVars(
6970
? `${OVERRIDE_PYTHONPATH}:${currentEnv.PYTHONPATH}`
7071
: OVERRIDE_PYTHONPATH,
7172

72-
// Clear NODE_OPTIONS - it's meant for _us_, not subprocesses.
73-
// Otherwise e.g. --max-http-header-size can break old Node/Electron
74-
NODE_OPTIONS: ""
73+
// We use $NODE_OPTIONS to prepend our script into node. Notably this also
74+
// clears it, which is important, as _our_ NODE_OPTIONS aren't meant for
75+
// subprocesses. Otherwise e.g. --max-http-header-size breaks old Node/Electron.
76+
NODE_OPTIONS: `--require "${OVERRIDE_JS_SCRIPT}"`
7577
};
7678
}

0 commit comments

Comments
 (0)