Skip to content

Commit cfb7370

Browse files
authored
fix: inheriting NODE_OPTIONS on macOS with integrated terminal (microsoft#204682)
1 parent 249a951 commit cfb7370

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

resources/darwin/bin/code.sh

+4
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ fi
3131
CONTENTS="$APP_PATH/Contents"
3232
ELECTRON="$CONTENTS/MacOS/Electron"
3333
CLI="$CONTENTS/Resources/app/out/cli.js"
34+
export VSCODE_NODE_OPTIONS=$NODE_OPTIONS
35+
export VSCODE_NODE_REPL_EXTERNAL_MODULE=$NODE_REPL_EXTERNAL_MODULE
36+
unset NODE_OPTIONS
37+
unset NODE_REPL_EXTERNAL_MODULE
3438
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
3539
exit $?

src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspac
1313
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
1414
import { sanitizeProcessEnvironment } from 'vs/base/common/processes';
1515
import { IShellLaunchConfig, ITerminalBackend, ITerminalEnvironment, TerminalShellType, WindowsShellType } from 'vs/platform/terminal/common/terminal';
16-
import { IProcessEnvironment, isWindows, language, OperatingSystem } from 'vs/base/common/platform';
16+
import { IProcessEnvironment, isWindows, isMacintosh, language, OperatingSystem } from 'vs/base/common/platform';
1717
import { escapeNonWindowsPath, sanitizeCwd } from 'vs/platform/terminal/common/terminalEnvironment';
1818
import { isString } from 'vs/base/common/types';
1919
import { IHistoryService } from 'vs/workbench/services/history/common/history';
@@ -269,6 +269,26 @@ export async function createTerminalEnvironment(
269269
}
270270
}
271271

272+
// Workaround for https://github.com/microsoft/vscode/issues/204005
273+
// We should restore the following environment variables when a user
274+
// launches the application using the CLI so that integrated terminal
275+
// can still inherit these variables.
276+
// We are not bypassing the restrictions implied in https://github.com/electron/electron/pull/40770
277+
// since this only affects integrated terminal and not the application itself.
278+
if (isMacintosh) {
279+
// Restore NODE_OPTIONS if it was set
280+
if (env['VSCODE_NODE_OPTIONS']) {
281+
env['NODE_OPTIONS'] = env['VSCODE_NODE_OPTIONS'];
282+
delete env['VSCODE_NODE_OPTIONS'];
283+
}
284+
285+
// Restore NODE_REPL_EXTERNAL_MODULE if it was set
286+
if (env['VSCODE_NODE_REPL_EXTERNAL_MODULE']) {
287+
env['NODE_REPL_EXTERNAL_MODULE'] = env['VSCODE_NODE_REPL_EXTERNAL_MODULE'];
288+
delete env['VSCODE_NODE_REPL_EXTERNAL_MODULE'];
289+
}
290+
}
291+
272292
// Sanitize the environment, removing any undesirable VS Code and Electron environment
273293
// variables
274294
sanitizeProcessEnvironment(env, 'VSCODE_IPC_HOOK_CLI');

0 commit comments

Comments
 (0)