Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
options = defaultsDeep({}, options, {
// 子进程继承父进程的环境变量
env: process.env
}, {
// 使用 npm 的 PATH
env: npmRunPath.env({
cwd: options.cwd || process.cwd()
})
});
let child;
let closed;
let timer = null;
try {
child = childProcess.exec(command, options);
} catch (errors) {
callback(errors);
}
child.stdout.on('data', content => {
}
opts = Object.assign({
maxBuffer: TEN_MEGABYTES,
stripEof: true,
preferLocal: true,
localDir: parsed.options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
cleanup: true
}, parsed.options);
opts.stdio = stdio(opts);
if (opts.preferLocal) {
opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir}));
}
if (opts.detached) {
// #115
opts.cleanup = false;
}
if (process.platform === 'win32' && path.basename(parsed.command) === 'cmd.exe') {
// #116
parsed.args.unshift('/q');
}
return {
cmd: parsed.command,
args: parsed.args,
opts,
}
opts = Object.assign({
maxBuffer: TEN_MEGABYTES,
stripEof: true,
preferLocal: true,
localDir: parsed.options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
cleanup: true
}, parsed.options);
opts.stdio = stdio(opts);
if (opts.preferLocal) {
opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir}));
}
return {
cmd: parsed.command,
args: parsed.args,
opts,
parsed
};
}
const getEnv = ({env: envOption, extendEnv, preferLocal, localDir}) => {
const env = extendEnv ? {...process.env, ...envOption} : envOption;
if (preferLocal) {
return npmRunPath.env({env, cwd: localDir});
}
return env;
};
}
opts = Object.assign({
maxBuffer: TEN_MEGABYTES,
stripEof: true,
preferLocal: true,
localDir: parsed.options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
cleanup: true
}, parsed.options);
opts.stdio = stdio(opts);
if (opts.preferLocal) {
opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir}));
}
return {
cmd: parsed.command,
args: parsed.args,
opts,
parsed
};
}
}
opts = Object.assign({
maxBuffer: TEN_MEGABYTES,
stripEof: true,
preferLocal: true,
localDir: parsed.options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
cleanup: true
}, parsed.options);
opts.stdio = stdio(opts);
if (opts.preferLocal) {
opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir}));
}
return {
cmd: parsed.command,
args: parsed.args,
opts,
parsed
};
}
}
opts = Object.assign({
maxBuffer: TEN_MEGABYTES,
stripEof: true,
preferLocal: true,
localDir: parsed.options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
cleanup: true
}, parsed.options);
opts.stdio = stdio(opts);
if (opts.preferLocal) {
opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir}));
}
return {
cmd: parsed.command,
args: parsed.args,
opts,
parsed
};
}
return new Promise((resolve, reject) => {
options = defaultsDeep({}, options, {
env: npmRunPath.env({
cwd: options.cwd || process.cwd(),
env: defaultsDeep({}, options.env, process.env)
})
});
let timer = null;
const callback = (errors, data) => {
clearTimeout(timer);
if (errors) {
errors.message = `run "${command}" failed: ${errors.message}`;
reject(errors);
} else {
resolve(data);
}
};
export const fixPath = function({
nodePath,
spawnOptions,
spawnOptions: { env, cwd },
}) {
const npmRunPathOpts = filterObj({ env, cwd, execPath: nodePath }, isDefined)
const envA = npmRunPath.env(npmRunPathOpts)
return { ...spawnOptions, env: envA, preferLocal: false }
}