Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cmake-js

Package Overview
Dependencies
Maintainers
2
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmake-js - npm Package Compare versions

Comparing version 6.3.0 to 7.0.0-0

bin/cmake-js-prebuildify.mjs

12

lib/appCMakeJSConfig.js
"use strict";
let path = require("path");
let _ = require("lodash");
const path = require("path");
const isPlainObject = require("lodash.isplainobject");
function getConfig(lookPath, log) {
let pjsonPath = path.join(lookPath, "package.json");
const pjsonPath = path.join(lookPath, "package.json");
log.silly("CFG", "Looking for package.json in: '" + pjsonPath + "'.");
try {
let json = require(pjsonPath);
const json = require(pjsonPath);
log.silly("CFG", "Loaded:\n" + JSON.stringify(json));
if (_.isPlainObject(json) && _.isPlainObject(json["cmake-js"])) {
if (isPlainObject(json) && isPlainObject(json["cmake-js"])) {
log.silly("CFG", "Config found.");

@@ -38,3 +38,3 @@ return json["cmake-js"];

log.silly("CFG", "Looking for parent path.");
let lastPath = currPath;
const lastPath = currPath;
currPath = path.normalize(path.join(currPath, ".."));

@@ -41,0 +41,0 @@ if (lastPath === currPath) {

"use strict";
let CMake = require("./cMake");
let Dist = require("./dist");
let CMLog = require("./cmLog");
let appCMakeJSConfig = require("./appCMakeJSConfig");
let npmConfig = require("./npmConfig");
let path = require("path");
let _ = require("lodash");
let Toolset = require("./toolset");
const CMake = require("./cMake");
const Dist = require("./dist");
const CMLog = require("./cmLog");
const appCMakeJSConfig = require("./appCMakeJSConfig");
const npmConfig = require("./npmConfig");
const path = require("path");
const isPlainObject = require("lodash.isplainobject");
const Toolset = require("./toolset");

@@ -15,10 +15,10 @@ function BuildSystem(options) {

this.log = new CMLog(this.options);
let appConfig = appCMakeJSConfig(this.options.directory, this.log);
let npmOptions = npmConfig(this.log);
const appConfig = appCMakeJSConfig(this.options.directory, this.log);
const npmOptions = npmConfig(this.log);
if (_.isPlainObject(npmOptions) && _.keys(npmOptions).length) {
if (isPlainObject(npmOptions) && Object.keys(npmOptions).length) {
this.options.runtimeDirectory = npmOptions["nodedir"];
}
if (_.isPlainObject(appConfig)) {
if (_.keys(appConfig).length) {
if (isPlainObject(appConfig)) {
if (Object.keys(appConfig).length) {
this.log.verbose("CFG", "Applying CMake.js config from root package.json:");

@@ -25,0 +25,0 @@ this.log.verbose("CFG", JSON.stringify(appConfig));

"use strict";
let splitargs = require("splitargs");
let which = require("which");
let fs = require("fs-extra");
let path = require("path");
let _ = require("lodash");
let environment = require("./environment");
let Dist = require("./dist");
let CMLog = require("./cmLog");
let vsDetect = require("./vsDetect");
let TargetOptions = require("./targetOptions");
let processHelpers = require("./processHelpers");
let locateNAN = require("./locateNAN");
let npmConfigData = require("rc")("npm");
let Toolset = require("./toolset");
const which = require("which");
const fs = require("fs-extra");
const path = require("path");
const environment = require("./environment");
const Dist = require("./dist");
const CMLog = require("./cmLog");
const TargetOptions = require("./targetOptions");
const processHelpers = require("./processHelpers");
const locateNAN = require("./locateNAN");
const npmConfigData = require("rc")("npm");
const Toolset = require("./toolset");

@@ -52,3 +49,3 @@ function CMake(options) {

if (options.cmakePath) {
let stat = fs.lstatSync(options.cmakePath);
const stat = fs.lstatSync(options.cmakePath);
return !stat.isDirectory();

@@ -62,3 +59,3 @@ }

catch (e) {
_.noop(e);
// Ignore
}

@@ -69,10 +66,10 @@ return false;

CMake.getGenerators = async function (options, log) {
let arch = " [arch]";
const arch = " [arch]";
options = options || {};
let gens = [];
const gens = [];
if (CMake.isAvailable(options)) {
// try parsing machine-readable capabilities (available since CMake 3.7)
try {
let stdout = await processHelpers.execFile([options.cmakePath || "cmake", "-E", "capabilities"]);
let capabilities = JSON.parse(stdout);
const stdout = await processHelpers.execFile([options.cmakePath || "cmake", "-E", "capabilities"]);
const capabilities = JSON.parse(stdout);
return capabilities.generators.map(x => x.name);

@@ -87,13 +84,13 @@ }

// fall back to parsing help text
let stdout = await processHelpers.execFile([options.cmakePath || "cmake", "--help"]);
let hasCr = stdout.includes("\r\n");
let output = hasCr ? stdout.split("\r\n") : stdout.split("\n");
const stdout = await processHelpers.execFile([options.cmakePath || "cmake", "--help"]);
const hasCr = stdout.includes("\r\n");
const output = hasCr ? stdout.split("\r\n") : stdout.split("\n");
let on = false;
output.forEach(function (line, i) {
if (on) {
let parts = line.split("=");
const parts = line.split("=");
if ((parts.length === 2 && parts[0].trim()) ||
(parts.length === 1 && i !== output.length - 1 && output[i + 1].trim()[0] === "=")) {
let gen = parts[0].trim();
if (_.endsWith(gen, arch)) {
if (gen.endsWith(arch)) {
gen = gen.substr(0, gen.length - arch.length);

@@ -129,3 +126,3 @@ }

let D = [];
const D = [];

@@ -150,5 +147,5 @@ // CMake.js watermark

else {
let nodeH = path.join(this.dist.internalPath, "/src");
let v8H = path.join(this.dist.internalPath, "/deps/v8/include");
let uvH = path.join(this.dist.internalPath, "/deps/uv/include");
const nodeH = path.join(this.dist.internalPath, "/src");
const v8H = path.join(this.dist.internalPath, "/deps/v8/include");
const uvH = path.join(this.dist.internalPath, "/deps/uv/include");
incPaths = [nodeH, v8H, uvH];

@@ -158,3 +155,3 @@ }

// NAN
let nanH = await locateNAN(this.projectRoot);
const nanH = await locateNAN(this.projectRoot);
if (nanH) {

@@ -168,5 +165,5 @@ incPaths.push(nanH);

// Sources:
let srcPaths = [];
const srcPaths = [];
if (environment.isWin) {
let delayHook = path.normalize(path.join(__dirname, 'cpp', 'win_delay_load_hook.cc'));
const delayHook = path.normalize(path.join(__dirname, 'cpp', 'win_delay_load_hook.cc'));

@@ -185,11 +182,17 @@ srcPaths.push(delayHook.replace(/\\/gm, '/'));

// Win
let libs = this.dist.winLibs;
const libs = this.dist.winLibs;
if (libs.length) {
D.push({"CMAKE_JS_LIB": libs.join(";")});
}
} else if (environment.isOSX) {
if (this.targetOptions.arch) {
let xcodeArch = this.targetOptions.arch
if (xcodeArch === 'x64') xcodeArch = 'x86_64'
D.push({CMAKE_OSX_ARCHITECTURES: xcodeArch})
}
}
// Custom options
for (let k of _.keys(this.cMakeOptions)) {
D.push({[k]: this.cMakeOptions[k]});
for (const [key, value] of Object.entries(this.cMakeOptions)) {
D.push({ [key]: value });
}

@@ -226,11 +229,7 @@

// Load NPM config
for (let key of _.keys(npmConfigData)) {
if (_.startsWith(key, "cmake_")) {
let s = {};
let sk = key.substr(6);
if (sk) {
s[sk] = npmConfigData[key];
if (s[sk]) {
D.push(s);
}
for (const [key, value] of Object.entries(npmConfigData)) {
if (key.startsWith("cmake_")) {
const sk = key.substr(6);
if (sk && value) {
D.push({ [sk]: value });
}

@@ -241,3 +240,3 @@ }

command = command.concat(D.map(function (p) {
return "-D" + _.keys(p)[0] + "=" + _.values(p)[0];
return "-D" + Object.keys(p)[0] + "=" + Object.values(p)[0];
}));

@@ -252,4 +251,4 @@

this.log.info("CMD", "CONFIGURE");
let listPath = path.join(this.projectRoot, "CMakeLists.txt");
let command = await this.getConfigureCommand();
const listPath = path.join(this.projectRoot, "CMakeLists.txt");
const command = await this.getConfigureCommand();

@@ -267,6 +266,6 @@ try {

catch (e) {
_.noop(e);
// Ignore
}
let cwd = process.cwd();
const cwd = process.cwd();
process.chdir(this.workDir);

@@ -286,3 +285,2 @@ try {

catch (e) {
_.noop(e);
await this.configure();

@@ -293,6 +291,9 @@ }

CMake.prototype.getBuildCommand = function () {
var command = [this.path, "--build", this.workDir, "--config", this.config];
const command = [this.path, "--build", this.workDir, "--config", this.config];
if (this.options.target) {
command.push("--target", this.options.target);
}
if (this.options.parallel) {
command.push("--parallel", this.options.parallel);
}
return Promise.resolve(command);

@@ -305,3 +306,3 @@ };

await this.ensureConfigured();
let buildCommand = await this.getBuildCommand();
const buildCommand = await this.getBuildCommand();
this.log.info("CMD", "BUILD");

@@ -337,3 +338,2 @@ await this._run(buildCommand);

catch (e) {
_.noop(e);
this.log.info("REP", "Build has been failed, trying to do a full rebuild.");

@@ -340,0 +340,0 @@ await this.rebuild();

"use strict";
let log = require("npmlog");
const log = require("npmlog");

@@ -4,0 +4,0 @@ function CMLog(options) {

"use strict";
let environment = require("./environment");
let path = require("path");
let urljoin = require("url-join");
let fs = require("fs-extra");
let _ = require("lodash");
let CMLog = require("./cmLog");
let TargetOptions = require("./targetOptions");
let runtimePaths = require("./runtimePaths");
let Downloader = require("./downloader");
const environment = require("./environment");
const path = require("path");
const urljoin = require("url-join");
const fs = require("fs-extra");
const CMLog = require("./cmLog");
const TargetOptions = require("./targetOptions");
const runtimePaths = require("./runtimePaths");
const Downloader = require("./downloader");
function testSum(sums, sum, fPath) {
let serverSum = _.first(sums.filter(function (s) {
const serverSum = sums.find(function (s) {
return s.getPath === fPath;
}));
});
if (serverSum && serverSum.sum === sum) {

@@ -33,5 +32,5 @@ return;

get: function () {
let cacheDirectory = ".cmake-js";
let runtimeArchDirectory = (this.targetOptions.runtime) + "-" + this.targetOptions.arch;
let runtimeVersionDirectory = "v" + this.targetOptions.runtimeVersion;
const cacheDirectory = ".cmake-js";
const runtimeArchDirectory = (this.targetOptions.runtime) + "-" + this.targetOptions.arch;
const runtimeVersionDirectory = "v" + this.targetOptions.runtimeVersion;

@@ -68,3 +67,3 @@ return this.options.runtimeDirectory ||

if (environment.isWin) {
for (let libPath of this.winLibs) {
for (const libPath of this.winLibs) {
stat = getStat(libPath);

@@ -83,4 +82,4 @@ libs = libs && stat.isFile();

return {
isFile: _.constant(false),
isDirectory: _.constant(false)
isFile: () => false,
isDirectory: () => false
};

@@ -93,5 +92,5 @@ }

get: function () {
let libs = runtimePaths.get(this.targetOptions).winLibs;
let result = [];
for (let lib of libs) {
const libs = runtimePaths.get(this.targetOptions).winLibs;
const result = [];
for (const lib of libs) {
result.push(path.join(this.internalPath, lib.dir, lib.name));

@@ -117,6 +116,6 @@ }

Dist.prototype.download = async function () {
let log = this.log;
const log = this.log;
log.info("DIST", "Downloading distribution files to: " + this.internalPath);
await fs.ensureDir(this.internalPath);
let sums = await this._downloadShaSums();
const sums = await this._downloadShaSums();
await Promise.all([this._downloadLibs(sums), this._downloadTar(sums)]);

@@ -126,5 +125,5 @@ };

Dist.prototype._downloadShaSums = async function () {
if (this.targetOptions.runtime === "node" || this.targetOptions.runtime === "iojs") {
let sumUrl = urljoin(this.externalPath, "SHASUMS256.txt");
let log = this.log;
if (this.targetOptions.runtime === "node") {
const sumUrl = urljoin(this.externalPath, "SHASUMS256.txt");
const log = this.log;
log.http("DIST", "\t- " + sumUrl);

@@ -134,3 +133,3 @@ return (await this.downloader.downloadString(sumUrl))

.map(function (line) {
let parts = line.split(/\s+/);
const parts = line.split(/\s+/);
return {

@@ -151,9 +150,9 @@ getPath: parts[1],

Dist.prototype._downloadTar = async function (sums) {
let log = this.log;
let self = this;
let tarLocalPath = runtimePaths.get(self.targetOptions).tarPath;
let tarUrl = urljoin(self.externalPath, tarLocalPath);
const log = this.log;
const self = this;
const tarLocalPath = runtimePaths.get(self.targetOptions).tarPath;
const tarUrl = urljoin(self.externalPath, tarLocalPath);
log.http("DIST", "\t- " + tarUrl);
let sum = await this.downloader.downloadTgz(tarUrl, {
const sum = await this.downloader.downloadTgz(tarUrl, {
hash: sums ? "sha256" : null,

@@ -166,3 +165,3 @@ cwd: self.internalPath,

}
let ext = path.extname(entryPath);
const ext = path.extname(entryPath);
return ext && ext.toLowerCase() === ".h";

@@ -169,0 +168,0 @@ }

"use strict";
let Promise = require("bluebird");
let crypto = require("crypto");
let axios = require("axios");
let MemoryStream = require("memory-stream");
let zlib = require("zlib");
let tar = require("tar");
let fs = require("fs");
let _ = require("lodash");
let unzip = require("unzipper");
let CMLog = require("./cmLog");
const crypto = require("crypto");
const axios = require("axios");
const MemoryStream = require("memory-stream");
const zlib = require("zlib");
const tar = require("tar");
const fs = require("fs");
const CMLog = require("./cmLog");

@@ -19,4 +16,4 @@ function Downloader(options) {

Downloader.prototype.downloadToStream = function(url, stream, hash) {
let self = this;
let shasum = hash ? crypto.createHash(hash) : null;
const self = this;
const shasum = hash ? crypto.createHash(hash) : null;
return new Promise(function (resolve, reject) {

@@ -30,3 +27,3 @@ let length = 0;

length = parseInt(response.headers["content-length"]);
if (!_.isNumber(length)) {
if (typeof length !== 'number') {
length = 0;

@@ -48,9 +45,9 @@ }

}
})
});
response.data.pipe(stream)
response.data.pipe(stream);
})
.catch(function (err) {
reject(err);
})
});

@@ -68,3 +65,3 @@ stream.once("error", function (err) {

Downloader.prototype.downloadString = async function (url) {
let result = new MemoryStream();
const result = new MemoryStream();
await this.downloadToStream(url, result);

@@ -75,7 +72,7 @@ return result.toString();

Downloader.prototype.downloadFile = async function (url, options) {
if (_.isString(options)) {
if (typeof options === 'string') {
options.path = options;
}
let result = fs.createWriteStream(options.path);
let sum = await this.downloadToStream(url, result, options.hash);
const result = fs.createWriteStream(options.path);
const sum = await this.downloadToStream(url, result, options.hash);
this.testSum(url, sum, options);

@@ -86,9 +83,9 @@ return sum;

Downloader.prototype.downloadTgz = async function (url, options) {
if (_.isString(options)) {
if (typeof options === 'string') {
options.cwd = options;
}
let gunzip = zlib.createGunzip();
let extractor = tar.extract(options);
const gunzip = zlib.createGunzip();
const extractor = tar.extract(options);
gunzip.pipe(extractor);
let sum = await this.downloadToStream(url, gunzip, options.hash);
const sum = await this.downloadToStream(url, gunzip, options.hash);
this.testSum(url, sum, options);

@@ -98,12 +95,2 @@ return sum;

Downloader.prototype.downloadZip = async function (url, options) {
if (_.isString(options)) {
options.path = options;
}
let extractor = new unzip.Extract(options);
let sum = await this.downloadToStream(url, extractor, options.hash);
this.testSum(url, sum, options);
return sum;
};
Downloader.prototype.testSum = function(url, sum, options) {

@@ -110,0 +97,0 @@ if (options.hash && sum && options.sum && options.sum !== sum) {

"use strict";
let os = require("os");
let isIOJS = require("is-iojs");
let which = require("which");
let _ = require("lodash");
const os = require("os");
const which = require("which");
let environment = module.exports = {
moduleVersion: require("../package.json").version,
const environment = module.exports = {
cmakeJsVersion: require("../package.json").version,
platform: os.platform(),

@@ -17,3 +15,3 @@ isWin: os.platform() === "win32",

isArm: os.arch() === "arm",
runtime: isIOJS ? "iojs" : "node",
runtime: "node",
runtimeVersion: process.versions.node,

@@ -44,3 +42,3 @@ home: process.env[(os.platform() === "win32") ? "USERPROFILE" : "HOME"],

catch (e) {
_.noop(e);
// Ignore
}

@@ -65,3 +63,3 @@ }

catch (e) {
_.noop(e);
// Ignore
}

@@ -86,3 +84,3 @@ }

catch (e) {
_.noop(e);
// Ignore
}

@@ -107,3 +105,3 @@ }

catch (e) {
_.noop(e);
// Ignore
}

@@ -110,0 +108,0 @@ }

@@ -13,3 +13,2 @@ "use strict";

processHelpers: require("./processHelpers"),
locateNAN: require("./locateNAN")
};
"use strict";
let fs = require("fs-extra");
let path = require("path");
let _ = require("lodash");
const fs = require("fs-extra");
const path = require("path");
let isNANModule = async function (dir) {
let h = path.join(dir, "nan.h");
const isNANModule = async function (dir) {
const h = path.join(dir, "nan.h");
try {
let stat = await fs.stat(h);
const stat = await fs.stat(h);
return stat.isFile();
}
catch (e) {
_.noop(e);
return false;

@@ -18,5 +16,5 @@ }

let isNodeJSProject = async function (dir) {
let pjson = path.join(dir, "package.json");
let node_modules = path.join(dir, "node_modules");
async function isNodeJSProject (dir) {
const pjson = path.join(dir, "package.json");
const node_modules = path.join(dir, "node_modules");
try {

@@ -33,3 +31,3 @@ let stat = await fs.stat(pjson);

catch (e) {
_.noop(e);
// Ignore
}

@@ -39,6 +37,8 @@ return false;

let locateNAN = module.exports = async function (projectRoot) {
const locateNAN = module.exports = async function (projectRoot) {
if (locateNAN.__projectRoot) {
// Override for unit tests
projectRoot = locateNAN.__projectRoot;
}
let result = await isNodeJSProject(projectRoot);

@@ -48,3 +48,4 @@ if (!result) {

}
let nanModulePath = path.join(projectRoot, "node_modules", "nan");
const nanModulePath = path.join(projectRoot, "node_modules", "nan");
result = await isNANModule(nanModulePath);

@@ -60,4 +61,4 @@ if (result) {

function goUp(dir) {
let items = dir.split(path.sep);
let scopeItem = items[items.length - 2];
const items = dir.split(path.sep);
const scopeItem = items[items.length - 2];
if (scopeItem && scopeItem[0] === "@") {

@@ -64,0 +65,0 @@ // skip scope

"use strict";
function getNpmConfig() {
let npmOptions = {};
let npmConfigPrefix = 'npm_config_'
const npmOptions = {};
const npmConfigPrefix = 'npm_config_';
Object.keys(process.env).forEach(function (name) {
if (name.indexOf(npmConfigPrefix) !== 0) {
return
return;
}
let value = process.env[name]
name = name.substring(npmConfigPrefix.length)
const value = process.env[name];
name = name.substring(npmConfigPrefix.length);
if (name) {
npmOptions[name] = value
npmOptions[name] = value;
}
}, this)
}, this);

@@ -22,3 +22,3 @@ return npmOptions;

log.verbose("CFG", "Looking for NPM config.");
let options = getNpmConfig();
const options = getNpmConfig();

@@ -25,0 +25,0 @@ if (options) {

"use strict";
let Promise = require("bluebird");
let splitargs = require("splitargs");
let _ = require("lodash");
let spawn = require("child_process").spawn;
let execFile = require("child_process").execFile;
const spawn = require("child_process").spawn;
const execFile = require("child_process").execFile;
let processHelpers = {
const processHelpers = {
run: function (command, options) {
options = _.defaults(options, {silent: false});
if (!options) options = {};
return new Promise(function (resolve, reject) {

@@ -17,3 +15,3 @@ const env = Object.assign({}, process.env);

}
let child = spawn(command[0], command.slice(1), {
const child = spawn(command[0], command.slice(1), {
stdio: options.silent ? "ignore" : "inherit",

@@ -20,0 +18,0 @@ env

"use strict";
let _ = require("lodash");
let assert = require("assert");
let semver = require("semver");
const assert = require("assert");
const semver = require("semver");
const isPlainObject = require("lodash.isplainobject");
let NODE_MIRROR = process.env.NVM_NODEJS_ORG_MIRROR || "https://nodejs.org/dist";
let IOJS_MIRROR = process.env.NVM_IOJS_ORG_MIRROR || "https://iojs.org/dist";
let ELECTRON_MIRROR = process.env.ELECTRON_MIRROR || "https://atom.io/download/atom-shell";
const NODE_MIRROR = process.env.NVM_NODEJS_ORG_MIRROR || "https://nodejs.org/dist";
const ELECTRON_MIRROR = process.env.ELECTRON_MIRROR || "https://atom.io/download/atom-shell";
let runtimePaths = {
const runtimePaths = {
node: function (targetOptions) {

@@ -35,13 +34,2 @@ if (semver.lt(targetOptions.runtimeVersion, "4.0.0")) {

},
iojs: function (targetOptions) {
return {
externalPath: IOJS_MIRROR + "/v" + targetOptions.runtimeVersion + "/",
winLibs: [{
dir: targetOptions.isX64 ? "win-x64" : "win-x86",
name: targetOptions.runtime + ".lib"
}],
tarPath: targetOptions.runtime + "-v" + targetOptions.runtimeVersion + ".tar.gz",
headerOnly: false
};
},
nw: function (targetOptions) {

@@ -87,8 +75,8 @@ if (semver.gte(targetOptions.runtimeVersion, "0.13.0")) {

get: function (targetOptions) {
assert(_.isObject(targetOptions));
assert(targetOptions && typeof targetOptions === 'object');
let runtime = targetOptions.runtime;
let func = runtimePaths[runtime];
const runtime = targetOptions.runtime;
const func = runtimePaths[runtime];
let paths;
if (_.isFunction(func) && _.isPlainObject(paths = func(targetOptions))) {
if (typeof func === 'function' && isPlainObject(paths = func(targetOptions))) {
return paths;

@@ -95,0 +83,0 @@ }

"use strict";
let environment = require("./environment");
let _ = require("lodash");
const environment = require("./environment");

@@ -6,0 +5,0 @@ function TargetOptions(options) {

"use strict";
let Promise = require("bluebird");
let async = Promise.coroutine;
let _ = require("lodash");
let TargetOptions = require("./targetOptions");
let environment = require("./environment");
let assert = require("assert");
let vsDetect = require("./vsDetect");
let path = require("path");
let CMLog = require("./cmLog");
let processHelpers = require("./processHelpers");
const TargetOptions = require("./targetOptions");
const environment = require("./environment");
const assert = require("assert");
const vsDetect = require("./vsDetect");
const path = require("path");
const CMLog = require("./cmLog");
const processHelpers = require("./processHelpers");

@@ -159,3 +156,3 @@ function Toolset(options) {

}
let topVS = await this._getTopSupportedVisualStudioGenerator();
const topVS = await this._getTopSupportedVisualStudioGenerator();
if (topVS) {

@@ -176,6 +173,13 @@ if (install) {

let ver = 0;
const found = /^visual studio (\d+)/i.exec(topVS);
if (found) {
ver = parseInt(found[1]);
}
const isAboveVS16 = ver >= 16;
// The CMake Visual Studio Generator does not support the Win64 or ARM suffix on
// the generator name. Instead the generator platform must be set explicitly via
// the platform parameter
if (!this.platform && this.generator.startsWith("Visual Studio 16")) {
if (!this.platform && isAboveVS16) {
switch(this.targetOptions.arch) {

@@ -206,12 +210,12 @@ case "ia32":

Toolset.prototype._getTopSupportedVisualStudioGenerator = async function () {
let CMake = require("./cMake");
const CMake = require("./cMake");
assert(environment.isWin);
let vswhereVersion = await this._getVersionFromVSWhere();
const vswhereVersion = await this._getVersionFromVSWhere();
let list = await CMake.getGenerators(this.options, this.log);
const list = await CMake.getGenerators(this.options, this.log);
let maxVer = 0;
let result = null;
for (let gen of list) {
let found = /^visual studio (\d+)/i.exec(gen);
for (const gen of list) {
const found = /^visual studio (\d+)/i.exec(gen);
if (!found) {

@@ -221,3 +225,3 @@ continue;

let ver = parseInt(found[1]);
const ver = parseInt(found[1]);
if (ver <= maxVer) {

@@ -245,4 +249,4 @@ continue;

Toolset.prototype._getVersionFromVSWhere = async function () {
let programFilesPath = _.get(process.env, "ProgramFiles(x86)", _.get(process.env, "ProgramFiles"));
let vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe");
const programFilesPath = process.env["ProgramFiles(x86)"] || process.env["ProgramFiles"];
const vswhereCommand = path.resolve(programFilesPath, "Microsoft Visual Studio", "Installer", "vswhere.exe");
let vswhereOutput = null;

@@ -249,0 +253,0 @@

"use strict";
let processHelpers = require("./processHelpers");
let _ = require("lodash");
let path = require("path");
const processHelpers = require("./processHelpers");
let vsDetect = {
const vsDetect = {
isInstalled: async function (version) {
let vsInstalled = await this._isVSInstalled(version);
let vsvNextInstalled = await this._isVSvNextInstalled(version);
let buildToolsInstalled = await this._isBuildToolsInstalled(version);
let foundByVSWhere = await this._isFoundByVSWhere(version);
const vsInstalled = await this._isVSInstalled(version);
const vsvNextInstalled = await this._isVSvNextInstalled(version);
const buildToolsInstalled = await this._isBuildToolsInstalled(version);
const foundByVSWhere = await this._isFoundByVSWhere(version);

@@ -26,3 +24,3 @@ return vsInstalled || vsvNextInstalled || buildToolsInstalled || foundByVSWhere;

catch (e) {
_.noop(e);
// Ignore
}

@@ -34,3 +32,3 @@ */

_isBuildToolsInstalled: async function (version) {
let mainVer = version.split(".")[0];
const mainVer = version.split(".")[0];
let key;

@@ -46,9 +44,9 @@ let testPhrase;

}
let command = ["reg", "query", key];
const command = ["reg", "query", key];
try {
let stdout = await processHelpers.execFile(command);
const stdout = await processHelpers.execFile(command);
return stdout && stdout.indexOf(testPhrase) > 0;
}
catch (e) {
_.noop(e);
// Ignore
}

@@ -61,7 +59,7 @@ return false;

// it will write it's keys to 64 bit registry as well.
let command = ["reg", "query", "HKLM\\Software\\Microsoft\\VisualStudio\\" + version];
const command = ["reg", "query", "HKLM\\Software\\Microsoft\\VisualStudio\\" + version];
try {
let stdout = await processHelpers.execFile(command);
const stdout = await processHelpers.execFile(command);
if (stdout) {
let lines = stdout.split("\r\n").filter(function (line) {
const lines = stdout.split("\r\n").filter(function (line) {
return line.length > 10;

@@ -75,3 +73,3 @@ });

catch (e) {
_.noop(e);
// Ignore
}

@@ -82,8 +80,8 @@ return false;

_isVSvNextInstalled: async function (version) {
let mainVer = version.split(".")[0];
let command = ["reg", "query", "HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VisualStudio.MinShell.Msi,v" + mainVer];
const mainVer = version.split(".")[0];
const command = ["reg", "query", "HKLM\\SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VisualStudio.MinShell.Msi,v" + mainVer];
try {
let stdout = await processHelpers.execFile(command);
const stdout = await processHelpers.execFile(command);
if (stdout) {
let lines = stdout.split("\r\n").filter(function (line) {
const lines = stdout.split("\r\n").filter(function (line) {
return line.length > 10;

@@ -97,3 +95,3 @@ });

catch (e) {
_.noop(e);
// Ignore
}

@@ -100,0 +98,0 @@ return false;

{
"name": "cmake-js",
"description": "CMake.js - a Node.js/io.js native addon build tool",
"description": "CMake.js - a Node.js native addon build tool",
"license": "MIT",

@@ -19,28 +19,36 @@ "keywords": [

"main": "lib",
"version": "6.3.0",
"version": "7.0.0-0",
"author": "Gábor Mező aka unbornchikken",
"maintainers": [
{
"name" : "Julian Waller",
"email" : "git@julusian.co.uk",
"url" : "https://github.com/julusian/"
}
],
"repository": {
"type": "git",
"url": "git://github.com/unbornchikken/cmake-js.git"
"url": "git://github.com/cmake-js/cmake-js.git"
},
"bin": "./bin/cmake-js",
"bin": {
"cmake-js": "./bin/cmake-js",
"cmake-js-prebuildify": "./bin/cmake-js-prebuildify.mjs",
"cmake-js-verify": "./bin/cmake-js-verify.mjs"
},
"engines": {
"node": ">= 10.0.0"
"node": ">= 14.15.0"
},
"dependencies": {
"axios": "^0.21.1",
"axios": "^0.27.2",
"debug": "^4",
"fs-extra": "^5.0.0",
"is-iojs": "^1.0.1",
"lodash": "^4",
"memory-stream": "0",
"npmlog": "^1.2.0",
"fs-extra": "^10.1.0",
"lodash.isplainobject": "^4.0.6",
"memory-stream": "^1.0.0",
"npmlog": "^6.0.2",
"rc": "^1.2.7",
"semver": "^5.0.3",
"splitargs": "0",
"tar": "^4",
"unzipper": "^0.8.13",
"url-join": "0",
"which": "^1.0.9",
"yargs": "^3.6.0"
"semver": "^7.3.7",
"tar": "^6.1.11",
"url-join": "^4.0.1",
"which": "^2.0.2",
"yargs": "^17.4.1"
},

@@ -50,7 +58,13 @@ "devDependencies": {

"nan": "^2.1.0",
"natives": "^1.1.6"
"node-addon-api": "^5.0.0"
},
"scripts": {
"test": "mocha tests"
}
"test": "mocha tests",
"lint": "eslint lib bin/cmake-js tests"
},
"files": [
"lib",
"bin",
"*.md"
]
}
# CMake.js (MIT)
## About
CMake.js is a Node.js/io.js native addon build tool which works (almost) *exactly* like [node-gyp](https://github.com/TooTallNate/node-gyp), but instead of [gyp](http://en.wikipedia.org/wiki/GYP_%28software%29), it is based on [CMake](http://cmake.org) build system. It's compatible with the following runtimes:
CMake.js is a Node.js native addon build tool which works (almost) *exactly* like [node-gyp](https://github.com/TooTallNate/node-gyp), but instead of [gyp](http://en.wikipedia.org/wiki/GYP_%28software%29), it is based on [CMake](http://cmake.org) build system. It's compatible with the following runtimes:
- Node.js 10+ since CMake.js v6.0.0 (for older runtimes please use CMake.js 5)
- Node.js 14.15+ since CMake.js v7.0.0 (for older runtimes please use an earlier version of CMake.js). Newer versions can produce builds targetting older runtimes
- [NW.js](https://github.com/nwjs/nw.js): all CMake.js based native modules are compatible with NW.js out-of-the-box, there is no [nw-gyp like magic](https://github.com/nwjs/nw.js/wiki/Using-Node-modules#3rd-party-modules-with-cc-addons) required
- [Electron](https://github.com/atom/electron) (formerly known as atom-shell): out-of-the-box build support, [no post build steps required](https://github.com/atom/electron/blob/master/docs/tutorial/using-native-node-modules.md)
- [Electron](https://github.com/electron/electron) (formerly known as atom-shell): out-of-the-box build support, [no post build steps required](https://github.com/electron/electron/blob/main/docs/tutorial/using-native-node-modules.md)

@@ -13,3 +13,3 @@ ## Installation

```bash
npm install -g cmake-js
npm install cmake-js
```

@@ -27,3 +27,3 @@

Commands:
install Install Node.js/io.js distribution files if needed
install Install Node.js distribution files if needed
configure Configure CMake project

@@ -66,2 +66,3 @@ print-configure Print the configuration command

-a, --arch the architecture to build in [string]
-p, --parallel the number of threads cmake can use [number]
--CD Custom argument passed to CMake in format:

@@ -96,6 +97,11 @@ -D<your-arg-here> [string]

project (your-addon-name-here)
include_directories(${CMAKE_JS_INC})
file(GLOB SOURCE_FILES "your-source files-location-here")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})

@@ -173,3 +179,3 @@ ```

```
npm config set cmake_BuBu="kittyfck"
npm config set cmake_Foo="bar"
```

@@ -180,3 +186,3 @@

```cmake
message (STATUS ${BuBu})
message (STATUS ${Foo})
```

@@ -187,3 +193,3 @@

```
--- kittyfck
--- bar
```

@@ -199,3 +205,3 @@

```
cmake-js compile --CDBUBU="kittyfck"
cmake-js compile --CDFOO="bar"
```

@@ -206,3 +212,3 @@

```cmake
message (STATUS ${BUBU})
message (STATUS ${FOO})
```

@@ -213,3 +219,3 @@

```
--- kittyfck
--- bar
```

@@ -219,2 +225,8 @@

#### Important
It is important to understand that this setting is to be configured in the **application's root package.json file**. If you're creating a native module targeting nw.js for example, then **do not specify anything** in your module's package.json. It's the actual application's decision to specify its runtime, your module's just compatible anything that was mentioned in the [About chapter](#about). Actually defining `cmake-js` key in your module's package.json file may lead to an error. Why? If you set it up to use nw.js 0.12.1 for example, then when it gets compiled during development time (to run its unit tests for example) it's gonna be compiled against io.js 1.2 runtime. But if you're having io.js 34.0.1 at the command line then, which is binary incompatible with 1.2, then your unit tests will fail for sure. So it is advised to not use cmake-js target settings in your module's package.json, because that way CMake.js will use that you have, and your tests will pass.
#### Configuration
If any of the `runtime`, `runtimeVersion`, or `arch` configuration parameters is not explicitly configured, sensible defaults will be auto-detected based on the JavaScript environment where CMake.js runs within.

@@ -245,4 +257,11 @@

- **runtimeVersion**: version of the application's target runtime, for example: `0.12.1`
- **arch**: architecture of application's target runtime (eg: `x64`, `ia32`, `arm64`, `arm`). *Notice: on non-Windows systems the C++ toolset's architecture's gonna be used despite this setting. If you don't specify this on Windows, then architecture of the main node/io.js runtime is gonna be used, so you have to choose a matching nw.js runtime.*
- **arch**: architecture of application's target runtime (eg: `x64`, `ia32`, `arm64`, `arm`). *Notice: on non-Windows systems the C++ toolset's architecture's gonna be used despite this setting. If you don't specify this on Windows, then architecture of the main node runtime is gonna be used, so you have to choose a matching nw.js runtime.*
#### Electron
On Windows, the [`win_delay_load_hook`](https://www.electronjs.org/docs/tutorial/using-native-node-modules#a-note-about-win_delay_load_hook) is required to be embedded in the module or it will fail to load in the render process.
cmake-js will add the hook if the CMakeLists.txt contains the library `${CMAKE_JS_SRC}`.
Without the hook, the module can only be called from the render process using the Electron [remote](https://github.com/electron/electron/blob/master/docs/api/remote.md) module.
#### Runtime options in CMakeLists.txt

@@ -272,27 +291,3 @@

#### Electron
To make compatible your Electron application with any CMake.js based modules, write the following to your application's package.json file:
```json
{
"cmake-js": {
"runtime": "electron",
"runtimeVersion": "electron-runtime-version-here",
"arch": "whatever-setting-is-appropriate-for-your-application's-windows-build"
}
}
```
That's it. There is nothing else to do either on the application's or on the module's side, CMake.js modules are compatible with Electron out-of-the-box.
##### Note
Currently Electron (V1.4.x+) can only call modules built using CMake.js from the main process. To call such a module from a render process use the Electron [remote](https://github.com/electron/electron/blob/master/docs/api/remote.md) module in your require statement:
```var yourModule = require('electron').remote.require('pathToYourModule/cmakeModuleName.node')```
#### Important
It is important to understand that this setting is to be configured in the **application's root package.json file**. If you're creating a native module targeting nw.js for example, then **do not specify anything** in your module's package.json. It's the actual application's decision to specify its runtime, your module's just compatible anything that was mentioned in the [About chapter](#about). Actually defining `cmake-js` key in your module's package.json file may lead to an error. Why? If you set it up to use nw.js 0.12.1 for example, then when it gets compiled during development time (to run its unit tests for example) it's gonna be compiled against io.js 1.2 runtime. But if you're having io.js 34.0.1 at the command line then, which is binary incompatible with 1.2, then your unit tests will fail for sure. So it is advised to not use cmake-js target settings in your module's package.json, because that way CMake.js will use that you have, and your tests will pass.
#### Heroku

@@ -341,3 +336,3 @@ [Heroku](https://heroku.com) uses the concept of a [buildpack](https://devcenter.heroku.com/articles/buildpacks) to define

npm install --save-dev node-addon-api
npm install --save node-addon-api

@@ -366,6 +361,8 @@ and add it to the include directories of your *CMake* project file

## Use case in the works - ArrayFire.js
## Real examples
I'm working on the Node.js port of the awesome [ArrayFire](http://arrayfire.com/) CPU/GPU computing library, please follow its status in its repo: [ArrayFire.js](https://github.com/arrayfire/arrayfire_js).
* [@julusian/jpeg-turbo](https://github.com/julusian/node-jpeg-turbo) - A Node-API wrapping around libjpeg-turbo. cmake-js was a good fit here, as libjpeg-turbo provides cmake files that can be used, and would be hard to replicate correctly in node-gyp
Open a PR to add your own project here.
## Changelog

@@ -379,2 +376,2 @@

Ty all!
Ty all!

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc