mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 01:25:38 -05:00
Merge from master
This commit is contained in:
@@ -3,16 +3,13 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as cp from 'child_process';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
function getUnixShellEnvironment(): TPromise<typeof process.env> {
|
||||
const promise = new TPromise((c, e) => {
|
||||
function getUnixShellEnvironment(): Promise<typeof process.env> {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const runAsNode = process.env['ELECTRON_RUN_AS_NODE'];
|
||||
const noAttach = process.env['ELECTRON_NO_ATTACH_CONSOLE'];
|
||||
const mark = generateUuid().replace(/-/g, '').substr(0, 12);
|
||||
@@ -24,19 +21,19 @@ function getUnixShellEnvironment(): TPromise<typeof process.env> {
|
||||
});
|
||||
|
||||
const command = `'${process.execPath}' -p '"${mark}" + JSON.stringify(process.env) + "${mark}"'`;
|
||||
const child = cp.spawn(process.env.SHELL, ['-ilc', command], {
|
||||
const child = cp.spawn(process.env.SHELL!, ['-ilc', command], {
|
||||
detached: true,
|
||||
stdio: ['ignore', 'pipe', process.stderr],
|
||||
env
|
||||
});
|
||||
|
||||
const buffers: Buffer[] = [];
|
||||
child.on('error', () => c({}));
|
||||
child.on('error', () => resolve({}));
|
||||
child.stdout.on('data', b => buffers.push(b as Buffer));
|
||||
|
||||
child.on('close', (code: number, signal: any) => {
|
||||
if (code !== 0) {
|
||||
return e(new Error('Failed to get environment'));
|
||||
return reject(new Error('Failed to get environment'));
|
||||
}
|
||||
|
||||
const raw = Buffer.concat(buffers).toString('utf8');
|
||||
@@ -61,31 +58,31 @@ function getUnixShellEnvironment(): TPromise<typeof process.env> {
|
||||
// https://github.com/Microsoft/vscode/issues/22593#issuecomment-336050758
|
||||
delete env['XDG_RUNTIME_DIR'];
|
||||
|
||||
c(env);
|
||||
resolve(env);
|
||||
} catch (err) {
|
||||
e(err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// swallow errors
|
||||
return promise.then(null, () => ({}));
|
||||
return promise.then(undefined, () => ({}));
|
||||
}
|
||||
|
||||
|
||||
let _shellEnv: TPromise<typeof process.env>;
|
||||
let _shellEnv: Promise<typeof process.env>;
|
||||
|
||||
/**
|
||||
* We need to get the environment from a user's shell.
|
||||
* This should only be done when Code itself is not launched
|
||||
* from within a shell.
|
||||
*/
|
||||
export function getShellEnvironment(): TPromise<typeof process.env> {
|
||||
export function getShellEnvironment(): Promise<typeof process.env> {
|
||||
if (_shellEnv === undefined) {
|
||||
if (isWindows) {
|
||||
_shellEnv = TPromise.as({});
|
||||
_shellEnv = Promise.resolve({});
|
||||
} else if (process.env['VSCODE_CLI'] === '1') {
|
||||
_shellEnv = TPromise.as({});
|
||||
_shellEnv = Promise.resolve({});
|
||||
} else {
|
||||
_shellEnv = getUnixShellEnvironment();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user