Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!existsSync("./bin/index.node")) writeFileSync("./bin/index.node", "");
// Download binaries from Packem's GitHub release page.
const https = require("https");
const url = require("url");
const { sep: pathSeperator } = require("path");
const { getAbi } = require("node-abi");
const Octokit = require("@octokit/rest");
const { x: extractTarGz } = require("tar");
const AUTH_TOKEN = process.env.NODE_PRE_GYP_GITHUB_TOKEN;
const PREBUILT_REPO_OWNER = process.env.PREBUILT_REPO_OWNER || "packem";
const PREBUILT_REPO_NAME = process.env.PREBUILT_REPO_NAME || "packem";
const PREBUILT_REPO_URL = `https://github.com/${PREBUILT_REPO_OWNER}/${PREBUILT_REPO_NAME}`;
const CWD = process.cwd();
const NODE_ABI = getAbi(process.version.replace(/^v/, ""), "node");
const PLATFORM = process.platform;
const ARCH = process.arch;
const octokit = new Octokit({ auth: AUTH_TOKEN });
octokit.repos
.getLatestRelease({
owner: PREBUILT_REPO_OWNER,
repo: PREBUILT_REPO_NAME
})
.then(({ data: { tag_name: VERSION }, status, headers }) => {
// Handle data.
const TARBALL_URL = `${PREBUILT_REPO_URL}/releases/download/${VERSION}/node-v${NODE_ABI}-${PLATFORM}-${ARCH}.tar.gz`;
https.get(TARBALL_URL, response => {
if (
var pkg = opts.pkg
var buildLog = opts.buildLog || function () {}
opts.target = target
opts.runtime = runtime
if (opts.runtime === 'node-webkit') {
opts.backend = 'nw-gyp'
}
var buildLogMessage = 'Preparing to prebuild ' + pkg.name + '@' + pkg.version + ' for ' + runtime + ' ' + target + ' on ' + opts.platform + '-' + opts.arch + ' using ' + opts.backend
if (opts.libc && opts.libc.length > 0) buildLogMessage += 'using libc ' + opts.libc
buildLog(buildLogMessage)
// --target can be target or abi
if (!napi.isNapiRuntime(runtime)) target = getTarget(target, runtime)
var abi = getAbi(target, runtime)
var tarPath = getTarPath(opts, abi)
fs.stat(tarPath, function (err, st) {
if (!err && !opts.force) {
buildLog(tarPath + ' exists, skipping build')
return callback(null, tarPath)
}
var tasks = [
function (cb) {
build(opts, target, function (err, filenames) {
if (err) return cb(err)
cb(null, filenames)
})
},
function (filenames, cb) {
buildLog('Packing ' + filenames.join(', ') + ' into ' + tarPath)
versions.forEach((version) => {
let abi = nodeAbi.getAbi(version);
let addonPath = `${addonDir}/stackimpact-addon-v${abi}.node`;
if (!fs.existsSync(addonPath)) {
cp.execSync(`node node_modules/node-gyp/bin/node-gyp.js rebuild --target=${version}`, {stdio: [0,1,2]});
fs.copyFileSync('build/Release/stackimpact-addon.node', addonPath);
}
else {
console.log(`Addon with ABI ${abi} exists, skipping.`);
}
abiMap[version] = abi;
});
config.target_defaults.msvs_settings = {
VCCLCompilerTool: {
AdditionalOptions: [
'/arch:AVX2',
],
},
};
} else {
config.target_defaults.defines.push('KRYPTON_DISABLE_NEON');
}
fs.writeFileSync('config.gypi', JSON.stringify(config, undefined, 2));
for (const target of targets) {
const id = abi.getAbi(target, 'node');
execSync(`${path.resolve('node_modules', '.bin', 'node-gyp')} rebuild --target=v${target} --arch=${arch}`, {
stdio: 'inherit',
env: {
...process.env,
...env[arch],
},
});
fs.copyFileSync(path.resolve('build', 'Release', 'krypton.node'), path.resolve('builds', `${process.platform}-${arch}-${id}.node`));
}
}
}
function prebuildName (target, opts) {
var tags = [target.runtime]
if (opts.napi) {
tags.push('napi')
} else {
tags.push('abi' + abi.getAbi(target.target, target.runtime))
}
if (opts.tagUv) {
var uv = opts.tagUv === true ? opts.uv : opts.tagUv
if (uv) tags.push('uv' + uv)
}
if (opts.tagArmv) {
var armv = opts.tagArmv === true ? opts.armv : opts.tagArmv
if (armv) tags.push('armv' + armv)
}
if (opts.tagLibc) {
var libc = opts.tagLibc === true ? opts.libc : opts.tagLibc
if (libc) tags.push(libc)
}
constructor(
public lifecycle: EventEmitter,
public buildPath: string,
public electronVersion: string,
public arch = process.arch,
public extraModules: string[] = [],
public forceRebuild = false,
public headerURL = 'https://atom.io/download/electron',
public types = ['prod', 'optional'],
public mode = defaultMode) {
this.ABI = nodeAbi.getAbi(electronVersion, 'electron');
this.prodDeps = extraModules.reduce((acc, x) => acc.add(x), new Set());
this.rebuilds = [];
this.realModulePaths = new Set();
this.realNodeModulesPaths = new Set();
}
msvs_settings: {
VCCLCompilerTool: {
AdditionalOptions: [
'/arch:AVX2',
],
},
},
},
};
if (arch === 'ia32') config.target_defaults.defines.push('KRYPTON_DISABLE_SODIUM');
fs.writeFileSync('config.gypi', JSON.stringify(config, undefined, 2));
for (const target of targets) {
const id = abi.getAbi(target, 'node');
execSync(`${path.resolve('node_modules', '.bin', 'node-gyp')} configure --target=v${target} --arch=${arch}`, {
stdio: 'inherit',
env: {
...process.env,
...env[arch],
},
});
const vcxproj = xml.xml2js(fs.readFileSync(path.resolve('build', 'krypton.vcxproj'), 'utf8'));
const globals = vcxproj.elements.find(x => x.name === 'Project').elements.find(x => x.name === 'PropertyGroup' && x.attributes.Label === 'Globals');
globals.elements.push({
type: 'element',
name: 'VcpkgTriplet',
download: 'd',
'build-from-source': 'compile',
compile: 'c',
token: 'T'
}
}))
if (rc.path === true) {
delete rc.path
}
if (napi.isNapiRuntime(rc.runtime) && rc.target === process.versions.node) {
rc.target = napi.getBestNapiBuildVersion()
}
rc.abi = napi.isNapiRuntime(rc.runtime) ? rc.target : getAbi(rc.target, rc.runtime)
return rc
}