snyk-nuget-plugin
Version:
Snyk CLI NuGet plugin
52 lines • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.execute = execute;
const child_process_1 = require("child_process");
function makeSpawnOptions(options) {
const spawnOptions = {
shell: false,
env: { ...process.env },
};
if (options?.cwd) {
spawnOptions.cwd = options.cwd;
}
if (options?.env) {
spawnOptions.env = { ...spawnOptions.env, ...options.env };
}
else {
spawnOptions.env = { ...spawnOptions.env };
}
// Before spawning an external process, we check if we need to
// restore the system proxy configuration, which overrides the CLI internal proxy configuration.
if (process.env.SNYK_SYSTEM_HTTP_PROXY !== undefined) {
spawnOptions.env.HTTP_PROXY = process.env.SNYK_SYSTEM_HTTP_PROXY;
}
if (process.env.SNYK_SYSTEM_HTTPS_PROXY !== undefined) {
spawnOptions.env.HTTPS_PROXY = process.env.SNYK_SYSTEM_HTTPS_PROXY;
}
if (process.env.SNYK_SYSTEM_NO_PROXY !== undefined) {
spawnOptions.env.NO_PROXY = process.env.SNYK_SYSTEM_NO_PROXY;
}
return spawnOptions;
}
function execute(command, args, options) {
const spawnOptions = makeSpawnOptions(options);
return new Promise((resolve, reject) => {
let stdout = '';
let stderr = '';
const proc = (0, child_process_1.spawn)(command, args, spawnOptions);
proc.stdout?.on('data', (data) => {
stdout = stdout + data;
});
proc.stderr?.on('data', (data) => {
stderr = stderr + data;
});
proc.on('close', (code) => {
if (code !== 0) {
return reject({ stdout, stderr });
}
resolve({ stdout, stderr });
});
});
}
//# sourceMappingURL=subprocess.js.map