From c8680d7e02977ea99c1426eb80130ca04e5b5d88 Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Thu, 7 Oct 2021 10:55:19 -0500 Subject: [PATCH 1/8] add options for offline mode --- lib/buildSystem.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/buildSystem.js b/lib/buildSystem.js index 432c0cfb..e93104e9 100644 --- a/lib/buildSystem.js +++ b/lib/buildSystem.js @@ -20,6 +20,9 @@ function BuildSystem(options) { this.options.runtime = this.options.runtime || appConfig.runtime; this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion; this.options.arch = this.options.arch || appConfig.arch; + this.options.ensureInstalled = appConfig.ensureInstalled === undefined ? true : appConfig.ensureInstalled; + this.options.ensureDownloaded = appConfig.ensureDownloaded === undefined ? true : appConfig.ensureDownloaded; + this.options.customDownloadDir = this.options.customDownloadDir || appConfig.customDownloadDir; } } this.log.verbose("CFG", "Build system options:"); @@ -32,7 +35,6 @@ function BuildSystem(options) { BuildSystem.prototype._ensureInstalled = async function () { try { await this.toolset.initialize(true); - await this.dist.ensureDownloaded(); } catch (e) { this._showError(e); @@ -54,13 +56,19 @@ BuildSystem.prototype._showError = function (e) { } }; -BuildSystem.prototype.install = function () { - return this._ensureInstalled(); +BuildSystem.prototype.install = async function () { + await this._ensureInstalled(); + await this.dist.ensureDownloaded(); }; BuildSystem.prototype._invokeCMake = async function (method) { try { - await this._ensureInstalled(); + if (this.options.ensureInstalled === true) { + await this._ensureInstalled(); + } + if (this.options.ensureDownloaded === true) { + await this.dist.ensureDownloaded(); + } return await this.cmake[method](); } catch (e) { From 136d031110af462e9f0a2df272381e17c3c6df69 Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Thu, 7 Oct 2021 10:55:55 -0500 Subject: [PATCH 2/8] add option for a custom download directory --- lib/dist.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/dist.js b/lib/dist.js index fa77e71c..ff69dc06 100644 --- a/lib/dist.js +++ b/lib/dist.js @@ -30,11 +30,12 @@ function Dist(options) { Object.defineProperties(Dist.prototype, { internalPath: { get: function () { - return path.join( - environment.home, - ".cmake-js", - (this.targetOptions.runtime) + "-" + this.targetOptions.arch, - "v" + this.targetOptions.runtimeVersion); + let mainDir = ".cmake-js" + let runtimeArchDir = (this.targetOptions.runtime) + "-" + this.targetOptions.arch + let runtimeVersionDir = "v" + this.targetOptions.runtimeVersion + let downloadPath = this.options.customDownloadDir || path.join(mainDir, runtimeArchDir, runtimeVersionDir) + + return path.join(environment.home, downloadPath); } }, externalPath: { From 133be3d27920ab08b8d0e8cc5049e83de59c921e Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Thu, 7 Oct 2021 11:24:24 -0500 Subject: [PATCH 3/8] add missing semicolon --- lib/dist.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/dist.js b/lib/dist.js index ff69dc06..c1d618b2 100644 --- a/lib/dist.js +++ b/lib/dist.js @@ -30,10 +30,10 @@ function Dist(options) { Object.defineProperties(Dist.prototype, { internalPath: { get: function () { - let mainDir = ".cmake-js" - let runtimeArchDir = (this.targetOptions.runtime) + "-" + this.targetOptions.arch - let runtimeVersionDir = "v" + this.targetOptions.runtimeVersion - let downloadPath = this.options.customDownloadDir || path.join(mainDir, runtimeArchDir, runtimeVersionDir) + let mainDir = ".cmake-js"; + let runtimeArchDir = (this.targetOptions.runtime) + "-" + this.targetOptions.arch; + let runtimeVersionDir = "v" + this.targetOptions.runtimeVersion; + let downloadPath = this.options.customDownloadDir || path.join(mainDir, runtimeArchDir, runtimeVersionDir); return path.join(environment.home, downloadPath); } From deef52d54e8654f8a44fb903611d32bd287fa228 Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Mon, 11 Oct 2021 17:17:38 -0500 Subject: [PATCH 4/8] add npm config dictionary --- lib/buildSystem.js | 8 +++++++- lib/npmConfig.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/npmConfig.js diff --git a/lib/buildSystem.js b/lib/buildSystem.js index e93104e9..9c1173d6 100644 --- a/lib/buildSystem.js +++ b/lib/buildSystem.js @@ -3,6 +3,7 @@ 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"); @@ -12,6 +13,11 @@ function BuildSystem(options) { this.options.directory = path.resolve(this.options.directory || process.cwd()); this.log = new CMLog(this.options); let appConfig = appCMakeJSConfig(this.options.directory, this.log); + let npmOptions = npmConfig(this.log); + + if (_.isPlainObject(npmOptions) && _.keys(npmOptions).length) { + this.options.runtimeDir = npmOptions["nodedir"]; + } if (_.isPlainObject(appConfig)) { if (_.keys(appConfig).length) { this.log.verbose("CFG", "Applying CMake.js config from root package.json:"); @@ -22,7 +28,7 @@ function BuildSystem(options) { this.options.arch = this.options.arch || appConfig.arch; this.options.ensureInstalled = appConfig.ensureInstalled === undefined ? true : appConfig.ensureInstalled; this.options.ensureDownloaded = appConfig.ensureDownloaded === undefined ? true : appConfig.ensureDownloaded; - this.options.customDownloadDir = this.options.customDownloadDir || appConfig.customDownloadDir; + this.options.runtimeDir = this.options.runtimeDir || appConfig.runtimeDir; } } this.log.verbose("CFG", "Build system options:"); diff --git a/lib/npmConfig.js b/lib/npmConfig.js new file mode 100644 index 00000000..570197cd --- /dev/null +++ b/lib/npmConfig.js @@ -0,0 +1,31 @@ +"use strict"; + +function getNpmConfig() { + let npmOptions = {}; + let npmConfigPrefix = 'npm_config_' + Object.keys(process.env).forEach(function (name) { + if (name.indexOf(npmConfigPrefix) !== 0) { + return + } + let value = process.env[name] + name = name.substring(npmConfigPrefix.length) + if (name) { + npmOptions[name] = value + } + }, this) + + return npmOptions; +} + +module.exports = function (log) { + log.verbose("CFG", "Looking for NPM config."); + let options = getNpmConfig(); + + if (options) { + log.silly("CFG", "NPM options:", options); + }else { + log.verbose("CFG", "There are no NPM options available."); + } + + return options; +}; From 72ee32b0d1ec45105a4ee9c7f17441811d417d30 Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Mon, 11 Oct 2021 17:18:20 -0500 Subject: [PATCH 5/8] rename to runtime Dir/Path --- lib/dist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dist.js b/lib/dist.js index c1d618b2..2788f11a 100644 --- a/lib/dist.js +++ b/lib/dist.js @@ -33,9 +33,9 @@ Object.defineProperties(Dist.prototype, { let mainDir = ".cmake-js"; let runtimeArchDir = (this.targetOptions.runtime) + "-" + this.targetOptions.arch; let runtimeVersionDir = "v" + this.targetOptions.runtimeVersion; - let downloadPath = this.options.customDownloadDir || path.join(mainDir, runtimeArchDir, runtimeVersionDir); + let runtimePath = this.options.runtimeDir || path.join(mainDir, runtimeArchDir, runtimeVersionDir); - return path.join(environment.home, downloadPath); + return path.join(environment.home, runtimePath); } }, externalPath: { From 60801fdb1fba8db69a3718ee4c9ddb98102506dc Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Thu, 14 Oct 2021 15:58:10 -0500 Subject: [PATCH 6/8] add only the npm config, and restore the other changes - Use the runtimeDirectory as the full path if defined, otherwise, keep it as it was --- lib/buildSystem.js | 19 ++++++------------- lib/dist.js | 12 ++++++------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/buildSystem.js b/lib/buildSystem.js index 9c1173d6..dc48c8ca 100644 --- a/lib/buildSystem.js +++ b/lib/buildSystem.js @@ -16,7 +16,7 @@ function BuildSystem(options) { let npmOptions = npmConfig(this.log); if (_.isPlainObject(npmOptions) && _.keys(npmOptions).length) { - this.options.runtimeDir = npmOptions["nodedir"]; + this.options.runtimeDirectory = npmOptions["nodedir"]; } if (_.isPlainObject(appConfig)) { if (_.keys(appConfig).length) { @@ -26,9 +26,6 @@ function BuildSystem(options) { this.options.runtime = this.options.runtime || appConfig.runtime; this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion; this.options.arch = this.options.arch || appConfig.arch; - this.options.ensureInstalled = appConfig.ensureInstalled === undefined ? true : appConfig.ensureInstalled; - this.options.ensureDownloaded = appConfig.ensureDownloaded === undefined ? true : appConfig.ensureDownloaded; - this.options.runtimeDir = this.options.runtimeDir || appConfig.runtimeDir; } } this.log.verbose("CFG", "Build system options:"); @@ -41,6 +38,7 @@ function BuildSystem(options) { BuildSystem.prototype._ensureInstalled = async function () { try { await this.toolset.initialize(true); + await this.dist.ensureDownloaded(); } catch (e) { this._showError(e); @@ -62,19 +60,14 @@ BuildSystem.prototype._showError = function (e) { } }; -BuildSystem.prototype.install = async function () { - await this._ensureInstalled(); - await this.dist.ensureDownloaded(); +BuildSystem.prototype.install = function () { + return this._ensureInstalled(); }; BuildSystem.prototype._invokeCMake = async function (method) { try { - if (this.options.ensureInstalled === true) { - await this._ensureInstalled(); - } - if (this.options.ensureDownloaded === true) { - await this.dist.ensureDownloaded(); - } + await this._ensureInstalled(); + await this.dist.ensureDownloaded(); return await this.cmake[method](); } catch (e) { diff --git a/lib/dist.js b/lib/dist.js index 2788f11a..3de1ed5f 100644 --- a/lib/dist.js +++ b/lib/dist.js @@ -30,12 +30,12 @@ function Dist(options) { Object.defineProperties(Dist.prototype, { internalPath: { get: function () { - let mainDir = ".cmake-js"; - let runtimeArchDir = (this.targetOptions.runtime) + "-" + this.targetOptions.arch; - let runtimeVersionDir = "v" + this.targetOptions.runtimeVersion; - let runtimePath = this.options.runtimeDir || path.join(mainDir, runtimeArchDir, runtimeVersionDir); + let cacheDirectory = ".cmake-js"; + let runtimeArchDirectory = (this.targetOptions.runtime) + "-" + this.targetOptions.arch; + let runtimeVersionDirectory = "v" + this.targetOptions.runtimeVersion; + let runtimePath = this.options.runtimeDirectory || path.join(environment.home, cacheDirectory, runtimeArchDirectory, runtimeVersionDirectory); - return path.join(environment.home, runtimePath); + return path.join(runtimePath); } }, externalPath: { @@ -108,7 +108,7 @@ Dist.prototype.ensureDownloaded = async function () { Dist.prototype.download = async function () { let log = this.log; - log.info("DIST", "Downloading distribution files."); + log.info("DIST", "Downloading distribution files to: " + this.internalPath); await fs.ensureDir(this.internalPath); let sums = await this._downloadShaSums(); await Promise.all([this._downloadLibs(sums), this._downloadTar(sums)]); From 38085f12f485a08dbbcbfb261bf36b252cdf18ff Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Thu, 14 Oct 2021 16:03:57 -0500 Subject: [PATCH 7/8] remove unneeded call --- lib/buildSystem.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/buildSystem.js b/lib/buildSystem.js index dc48c8ca..0845a84c 100644 --- a/lib/buildSystem.js +++ b/lib/buildSystem.js @@ -67,7 +67,6 @@ BuildSystem.prototype.install = function () { BuildSystem.prototype._invokeCMake = async function (method) { try { await this._ensureInstalled(); - await this.dist.ensureDownloaded(); return await this.cmake[method](); } catch (e) { From cbb548d497c599188a0805e08f20ae90798ba0c8 Mon Sep 17 00:00:00 2001 From: Juan Jose Castellanos Date: Thu, 14 Oct 2021 16:07:56 -0500 Subject: [PATCH 8/8] inline the return variable --- lib/dist.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/dist.js b/lib/dist.js index 3de1ed5f..a2c0821e 100644 --- a/lib/dist.js +++ b/lib/dist.js @@ -33,9 +33,12 @@ Object.defineProperties(Dist.prototype, { let cacheDirectory = ".cmake-js"; let runtimeArchDirectory = (this.targetOptions.runtime) + "-" + this.targetOptions.arch; let runtimeVersionDirectory = "v" + this.targetOptions.runtimeVersion; - let runtimePath = this.options.runtimeDirectory || path.join(environment.home, cacheDirectory, runtimeArchDirectory, runtimeVersionDirectory); - return path.join(runtimePath); + return this.options.runtimeDirectory || + path.join(environment.home, + cacheDirectory, + runtimeArchDirectory, + runtimeVersionDirectory); } }, externalPath: {