mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-04 07:15:54 +01:00
environment - consistently handle VSCODE_CWD in all our node.js processes
This commit is contained in:
35
src/bootstrap-node.js
vendored
35
src/bootstrap-node.js
vendored
@@ -6,6 +6,41 @@
|
||||
//@ts-check
|
||||
'use strict';
|
||||
|
||||
// Setup current working directory in all our node & electron processes
|
||||
// - Windows: call `process.chdir()` to always set application folder as cwd
|
||||
// - Posix: allow to change the current working dir via `VSCODE_CWD` if defined
|
||||
// - all OS: store the `process.cwd()` inside `VSCODE_CWD` for consistent lookups
|
||||
function setupCurrentWorkingDirectory() {
|
||||
const path = require('path');
|
||||
|
||||
try {
|
||||
let cwd = process.env['VSCODE_CWD'];
|
||||
|
||||
// remember current working directory in environment
|
||||
// unless it was given to us already from outside
|
||||
if (typeof cwd !== 'string') {
|
||||
cwd = process.cwd();
|
||||
process.env['VSCODE_CWD'] = cwd;
|
||||
}
|
||||
|
||||
// Windows: always set application folder as current working dir
|
||||
if (process.platform === 'win32') {
|
||||
process.chdir(path.dirname(process.execPath));
|
||||
}
|
||||
|
||||
// Linux/macOS: allow to change current working dir based on env
|
||||
else {
|
||||
if (cwd !== process.cwd()) {
|
||||
process.chdir(cwd);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
setupCurrentWorkingDirectory();
|
||||
|
||||
/**
|
||||
* Add support for redirecting the loading of node modules
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user