Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');
const fetch = require('pkg-fetch');
assert(!module.parent);
assert(__dirname === process.cwd());
const host = 'node' + process.version.match(/^v(\d+)/)[1];
const target = process.argv[2] || host;
let right;
fetch.need({
nodeRange: target,
platform: fetch.system.hostPlatform,
arch: fetch.system.hostArch
}).then(function (needed) {
right = utils.spawn.sync(
'./' + path.basename(needed),
[ '--expose-gc',
'-e', 'if (global.gc) console.log("ok");' ],
{ cwd: path.dirname(needed),
env: { PKG_EXECPATH: 'PKG_INVOKE_NODEJS' } }
);
assert.equal(right, 'ok\n');
}).catch(function (error) {
console.error(`> ${error.message}`);
process.exit(2);
p = p.then(() => fetch.need(item));
});
async function needViaCache (target) {
const s = stringifyTarget(target);
let c = targetsCache[s];
if (c) return c;
c = await need(target);
targetsCache[s] = c;
return c;
}
async function needWithDryRun (target) {
const target2 = Object.assign({ dryRun: true }, target);
const result = await need(target2);
assert([ 'exists', 'fetched', 'built' ].indexOf(result) >= 0);
dryRunResults[result] = true;
}