Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inheriting NODE_OPTIONS on macOS with integrated terminal #205070

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions resources/darwin/bin/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ fi
CONTENTS="$APP_PATH/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
export VSCODE_NODE_OPTIONS=$NODE_OPTIONS
export VSCODE_NODE_REPL_EXTERNAL_MODULE=$NODE_REPL_EXTERNAL_MODULE
unset NODE_OPTIONS
unset NODE_REPL_EXTERNAL_MODULE
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
22 changes: 21 additions & 1 deletion src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspac
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { sanitizeProcessEnvironment } from 'vs/base/common/processes';
import { IShellLaunchConfig, ITerminalBackend, ITerminalEnvironment, TerminalShellType, WindowsShellType } from 'vs/platform/terminal/common/terminal';
import { IProcessEnvironment, isWindows, language, OperatingSystem } from 'vs/base/common/platform';
import { IProcessEnvironment, isWindows, isMacintosh, language, OperatingSystem } from 'vs/base/common/platform';
import { escapeNonWindowsPath, sanitizeCwd } from 'vs/platform/terminal/common/terminalEnvironment';
import { isString } from 'vs/base/common/types';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
Expand Down Expand Up @@ -269,6 +269,26 @@ export async function createTerminalEnvironment(
}
}

// Workaround for https://github.com/microsoft/vscode/issues/204005
// We should restore the following environment variables when a user
// launches the application using the CLI so that integrated terminal
// can still inherit these variables.
// We are not bypassing the restrictions implied in https://github.com/electron/electron/pull/40770
// since this only affects integrated terminal and not the application itself.
if (isMacintosh) {
// Restore NODE_OPTIONS if it was set
if (env['VSCODE_NODE_OPTIONS']) {
env['NODE_OPTIONS'] = env['VSCODE_NODE_OPTIONS'];
delete env['VSCODE_NODE_OPTIONS'];
}

// Restore NODE_REPL_EXTERNAL_MODULE if it was set
if (env['VSCODE_NODE_REPL_EXTERNAL_MODULE']) {
env['NODE_REPL_EXTERNAL_MODULE'] = env['VSCODE_NODE_REPL_EXTERNAL_MODULE'];
delete env['VSCODE_NODE_REPL_EXTERNAL_MODULE'];
}
}

// Sanitize the environment, removing any undesirable VS Code and Electron environment
// variables
sanitizeProcessEnvironment(env, 'VSCODE_IPC_HOOK_CLI');
Expand Down