mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Merge pull request #15165 from segevfiner/sf-windows-update-process-env
Recognize Windows cmd or powershell environment in updateProcessEnv
This commit is contained in:
@@ -36,7 +36,7 @@ describe('updateProcessEnv(launchEnv)', function () {
|
||||
})
|
||||
|
||||
describe('when the launch environment appears to come from a shell', function () {
|
||||
it('updates process.env to match the launch environment', async function () {
|
||||
it('updates process.env to match the launch environment because PWD is set', async function () {
|
||||
process.env = {
|
||||
WILL_BE_DELETED: 'hi',
|
||||
NODE_ENV: 'the-node-env',
|
||||
@@ -64,6 +64,65 @@ describe('updateProcessEnv(launchEnv)', function () {
|
||||
expect(process.env).toBe(initialProcessEnv)
|
||||
})
|
||||
|
||||
it('updates process.env to match the launch environment because PROMPT is set', async function () {
|
||||
process.env = {
|
||||
WILL_BE_DELETED: 'hi',
|
||||
NODE_ENV: 'the-node-env',
|
||||
NODE_PATH: '/the/node/path',
|
||||
ATOM_HOME: '/the/atom/home'
|
||||
}
|
||||
|
||||
const initialProcessEnv = process.env
|
||||
|
||||
await updateProcessEnv({ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT: 'true', PROMPT: '$P$G', KEY1: 'value1', KEY2: 'value2'})
|
||||
expect(process.env).toEqual({
|
||||
ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT: 'true',
|
||||
PROMPT: '$P$G',
|
||||
KEY1: 'value1',
|
||||
KEY2: 'value2',
|
||||
NODE_ENV: 'the-node-env',
|
||||
NODE_PATH: '/the/node/path',
|
||||
ATOM_HOME: '/the/atom/home'
|
||||
})
|
||||
|
||||
// See #11302. On Windows, `process.env` is a magic object that offers
|
||||
// case-insensitive environment variable matching, so we cannot replace it
|
||||
// with another object.
|
||||
expect(process.env).toBe(initialProcessEnv)
|
||||
})
|
||||
|
||||
it('updates process.env to match the launch environment because PSModulePath is set', async function () {
|
||||
process.env = {
|
||||
WILL_BE_DELETED: 'hi',
|
||||
NODE_ENV: 'the-node-env',
|
||||
NODE_PATH: '/the/node/path',
|
||||
ATOM_HOME: '/the/atom/home'
|
||||
}
|
||||
|
||||
const initialProcessEnv = process.env
|
||||
|
||||
await updateProcessEnv({
|
||||
ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT: 'true',
|
||||
PSModulePath: 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\',
|
||||
KEY1: 'value1',
|
||||
KEY2: 'value2'
|
||||
})
|
||||
expect(process.env).toEqual({
|
||||
ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT: 'true',
|
||||
PSModulePath: 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\',
|
||||
KEY1: 'value1',
|
||||
KEY2: 'value2',
|
||||
NODE_ENV: 'the-node-env',
|
||||
NODE_PATH: '/the/node/path',
|
||||
ATOM_HOME: '/the/atom/home'
|
||||
})
|
||||
|
||||
// See #11302. On Windows, `process.env` is a magic object that offers
|
||||
// case-insensitive environment variable matching, so we cannot replace it
|
||||
// with another object.
|
||||
expect(process.env).toBe(initialProcessEnv)
|
||||
})
|
||||
|
||||
it('allows ATOM_HOME to be overwritten only if the new value is a valid path', async function () {
|
||||
let newAtomHomePath = temp.mkdirSync('atom-home')
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ async function updateProcessEnv (launchEnv) {
|
||||
if (launchEnv) {
|
||||
if (shouldGetEnvFromShell(launchEnv)) {
|
||||
envToAssign = await getEnvFromShell(launchEnv)
|
||||
} else if (launchEnv.PWD) {
|
||||
} else if (launchEnv.PWD || launchEnv.PROMPT || launchEnv.PSModulePath) {
|
||||
envToAssign = launchEnv
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user