From 494ca39f7e9eccf77e4e0330e23aa35e1b4880b2 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Thu, 19 Jul 2018 15:40:05 -0400 Subject: [PATCH 1/2] bin,lib: remove extra comments/lines/spaces - Removes "module dependencies" comments and things that, IMHO, don't add too much value. Happy to add back if helps some people when reading through `node-gyp`. - DRY up `lib/process-release.js`. - Removes a bunch of extra blank lines, as well as random spaces. --- bin/node-gyp.js | 9 -------- lib/build.js | 14 +------------ lib/clean.js | 7 ------- lib/configure.js | 15 ++----------- lib/find-node-directory.js | 4 +--- lib/find-vs2017.js | 4 +--- lib/install.js | 7 ------- lib/list.js | 6 ------ lib/node-gyp.js | 13 ------------ lib/process-release.js | 43 +++++++++++++------------------------- lib/rebuild.js | 1 - lib/remove.js | 6 ------ 12 files changed, 20 insertions(+), 109 deletions(-) diff --git a/bin/node-gyp.js b/bin/node-gyp.js index 70d7d50262..7d63f6b0ec 100755 --- a/bin/node-gyp.js +++ b/bin/node-gyp.js @@ -1,15 +1,7 @@ #!/usr/bin/env node -/** - * Set the title. - */ - process.title = 'node-gyp' -/** - * Module dependencies. - */ - var gyp = require('../') var log = require('npmlog') var osenv = require('osenv') @@ -126,7 +118,6 @@ process.on('uncaughtException', function (err) { }) function errorMessage () { - // copied from npm's lib/util/error-handler.js var os = require('os') log.error('System', os.type() + ' ' + os.release()) log.error('command', process.argv diff --git a/lib/build.js b/lib/build.js index 2f8e14c374..81494d65aa 100644 --- a/lib/build.js +++ b/lib/build.js @@ -1,10 +1,6 @@ module.exports = exports = build -/** - * Module dependencies. - */ - var fs = require('graceful-fs') , rm = require('rimraf') , path = require('path') @@ -32,8 +28,6 @@ function build (gyp, argv, callback) { var release = processRelease(argv, gyp, process.version, process.release) , makeCommand = gyp.opts.make || process.env.MAKE || platformMake , command = win ? 'msbuild' : makeCommand - , buildDir = path.resolve('build') - , configPath = path.resolve(buildDir, 'config.gypi') , jobs = gyp.opts.jobs || process.env.JOBS , buildType , config @@ -47,6 +41,7 @@ function build (gyp, argv, callback) { */ function loadConfigGypi () { + var configPath = path.resolve('build', 'config.gypi') fs.readFile(configPath, 'utf8', function (err, data) { if (err) { if (err.code == 'ENOENT') { @@ -187,13 +182,11 @@ function build (gyp, argv, callback) { }) } - /** * Actually spawn the process and compile the module. */ function doBuild () { - // Enable Verbose build var verbose = log.levels[log.level] <= log.levels.verbose if (!win && verbose) { @@ -253,10 +246,6 @@ function build (gyp, argv, callback) { proc.on('exit', onExit) } - /** - * Invoked after the make/msbuild command exits. - */ - function onExit (code, signal) { if (code !== 0) { return callback(new Error('`' + command + '` failed with exit code: ' + code)) @@ -266,5 +255,4 @@ function build (gyp, argv, callback) { } callback() } - } diff --git a/lib/clean.js b/lib/clean.js index e69164d45a..8172e1c3d3 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -3,20 +3,13 @@ module.exports = exports = clean exports.usage = 'Removes any generated build files and the "out" dir' -/** - * Module dependencies. - */ - var rm = require('rimraf') var log = require('npmlog') - function clean (gyp, argv, callback) { - // Remove the 'build' dir var buildDir = 'build' log.verbose('clean', 'removing "%s" directory', buildDir) rm(buildDir, callback) - } diff --git a/lib/configure.js b/lib/configure.js index f4820b514b..2cf4c443ce 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -5,10 +5,6 @@ module.exports.test = { findPython: findPython, } -/** - * Module dependencies. - */ - var fs = require('graceful-fs') , path = require('path') , log = require('npmlog') @@ -28,7 +24,6 @@ if (win) exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module' function configure (gyp, argv, callback) { - var python = gyp.opts.python || process.env.PYTHON || 'python2' , buildDir = path.resolve('build') , configNames = [ 'config.gypi', 'common.gypi' ] @@ -46,7 +41,6 @@ function configure (gyp, argv, callback) { }) function getNodeDir () { - // 'python' should be set by now process.env.PYTHON = python @@ -56,7 +50,6 @@ function configure (gyp, argv, callback) { log.verbose('get node dir', 'compiling against specified --nodedir dev files: %s', nodeDir) createBuildDir() - } else { // if no --nodedir specified, ensure node dependencies are installed if ('v' + release.version !== process.version) { @@ -245,12 +238,12 @@ function configure (gyp, argv, callback) { }) // For AIX and z/OS we need to set up the path to the exports file - // which contains the symbols needed for linking. + // which contains the symbols needed for linking. var node_exp_file = undefined if (process.platform === 'aix' || process.platform === 'os390') { var ext = process.platform === 'aix' ? 'exp' : 'x' var node_root_dir = findNodeDirectory() - var candidates = undefined + var candidates = undefined if (process.platform === 'aix') { candidates = ['include/node/node', 'out/Release/node', @@ -336,10 +329,6 @@ function configure (gyp, argv, callback) { }) } - /** - * Called when the `gyp` child process exits. - */ - function onCpExit (code, signal) { if (code !== 0) { callback(new Error('`gyp` failed with exit code: ' + code)) diff --git a/lib/find-node-directory.js b/lib/find-node-directory.js index 3aee8a109a..524909581f 100644 --- a/lib/find-node-directory.js +++ b/lib/find-node-directory.js @@ -1,7 +1,7 @@ var path = require('path') , log = require('npmlog') -function findNodeDirectory(scriptLocation, processObj) { +module.exports = function findNodeDirectory(scriptLocation, processObj) { // set dirname and process if not passed in // this facilitates regression tests if (scriptLocation === undefined) { @@ -57,5 +57,3 @@ function findNodeDirectory(scriptLocation, processObj) { } return node_root_dir } - -module.exports = findNodeDirectory diff --git a/lib/find-vs2017.js b/lib/find-vs2017.js index ad46ceaf88..8655d7c931 100644 --- a/lib/find-vs2017.js +++ b/lib/find-vs2017.js @@ -2,7 +2,7 @@ var log = require('npmlog') , execFile = require('child_process').execFile , path = require('path') -function findVS2017(callback) { +module.exports = function findVS2017(callback) { var ps = path.join(process.env.SystemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe') var csFile = path.join(__dirname, 'Find-VS2017.cs') @@ -42,5 +42,3 @@ function findVS2017(callback) { child.stdin.end() } - -module.exports = findVS2017 diff --git a/lib/install.js b/lib/install.js index 8a615dfb38..fa0fef6fe0 100644 --- a/lib/install.js +++ b/lib/install.js @@ -10,10 +10,6 @@ module.exports.test = { exports.usage = 'Install node development files for the specified node version.' -/** - * Module dependencies. - */ - var fs = require('graceful-fs') , osenv = require('osenv') , tar = require('tar') @@ -28,7 +24,6 @@ var fs = require('graceful-fs') , win = process.platform == 'win32' function install (fs, gyp, argv, callback) { - var release = processRelease(argv, gyp, process.version, process.release) // ensure no double-callbacks happen @@ -124,7 +119,6 @@ function install (fs, gyp, argv, callback) { } function go () { - log.verbose('ensuring nodedir is created', devDir) // first create the dir for the node dev files @@ -165,7 +159,6 @@ function install (fs, gyp, argv, callback) { } // download the tarball and extract! - if (tarPath) { return tar.extract({ file: tarPath, diff --git a/lib/list.js b/lib/list.js index 9d680a56a4..cda4fd2f2f 100644 --- a/lib/list.js +++ b/lib/list.js @@ -3,20 +3,14 @@ module.exports = exports = list exports.usage = 'Prints a listing of the currently installed node development files' -/** - * Module dependencies. - */ - var fs = require('graceful-fs') , path = require('path') , log = require('npmlog') function list (gyp, args, callback) { - var devDir = gyp.devDir log.verbose('list', 'using node-gyp dir:', devDir) - // readdir() the node-gyp dir fs.readdir(devDir, onreaddir) function onreaddir (err, versions) { diff --git a/lib/node-gyp.js b/lib/node-gyp.js index a841161e32..b35a5ebe44 100644 --- a/lib/node-gyp.js +++ b/lib/node-gyp.js @@ -1,14 +1,6 @@ -/** - * Module exports. - */ - module.exports = exports = gyp -/** - * Module dependencies. - */ - var fs = require('graceful-fs') , path = require('path') , nopt = require('nopt') @@ -35,10 +27,6 @@ var fs = require('graceful-fs') // differentiate node-gyp's logs from npm's log.heading = 'gyp' -/** - * The `gyp` function. - */ - function gyp () { return new Gyp() } @@ -213,4 +201,3 @@ Object.defineProperty(proto, 'version', { } , enumerable: true }) - diff --git a/lib/process-release.js b/lib/process-release.js index 0d177f1c93..4805fcc7d1 100644 --- a/lib/process-release.js +++ b/lib/process-release.js @@ -9,7 +9,7 @@ var semver = require('semver') , bitsreV3 = /\/win-(x86|ia32|x64)\// // io.js v3.x.x shipped with "ia32" but should // have been "x86" -// Captures all the logic required to determine download URLs, local directory and +// Captures all the logic required to determine download URLs, local directory and // file names. Inputs come from command-line switches (--target, --dist-url), // `process.version` and `process.release` where it exists. function processRelease (argv, gyp, defaultVersion, defaultRelease) { @@ -88,35 +88,22 @@ function processRelease (argv, gyp, defaultVersion, defaultRelease) { baseUrl = url.resolve(defaultRelease.headersUrl, './') libUrl32 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || distBaseUrl, 'x86', versionSemver.major) libUrl64 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || distBaseUrl, 'x64', versionSemver.major) - - return { - version: version, - semver: versionSemver, - name: name, - baseUrl: baseUrl, - tarballUrl: defaultRelease.headersUrl, - shasumsUrl: url.resolve(baseUrl, 'SHASUMS256.txt'), - versionDir: (name !== 'node' ? name + '-' : '') + version, - libUrl32: libUrl32, - libUrl64: libUrl64, - libPath32: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl32).path)), - libPath64: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl64).path)) - } + tarballUrl = defaultRelease.headersUrl + } else { + // older versions without process.release are captured here and we have to make + // a lot of assumptions, additionally if you --target=x.y.z then we can't use the + // current process.release + baseUrl = distBaseUrl + libUrl32 = resolveLibUrl(name, baseUrl, 'x86', versionSemver.major) + libUrl64 = resolveLibUrl(name, baseUrl, 'x64', versionSemver.major) + + // making the bold assumption that anything with a version number >3.0.0 will + // have a *-headers.tar.gz file in its dist location, even some frankenstein + // custom version + canGetHeaders = semver.satisfies(versionSemver, headersTarballRange) + tarballUrl = url.resolve(baseUrl, name + '-v' + version + (canGetHeaders ? '-headers' : '') + '.tar.gz') } - // older versions without process.release are captured here and we have to make - // a lot of assumptions, additionally if you --target=x.y.z then we can't use the - // current process.release - - baseUrl = distBaseUrl - libUrl32 = resolveLibUrl(name, baseUrl, 'x86', versionSemver.major) - libUrl64 = resolveLibUrl(name, baseUrl, 'x64', versionSemver.major) - // making the bold assumption that anything with a version number >3.0.0 will - // have a *-headers.tar.gz file in its dist location, even some frankenstein - // custom version - canGetHeaders = semver.satisfies(versionSemver, headersTarballRange) - tarballUrl = url.resolve(baseUrl, name + '-v' + version + (canGetHeaders ? '-headers' : '') + '.tar.gz') - return { version: version, semver: versionSemver, diff --git a/lib/rebuild.js b/lib/rebuild.js index 4c6f472aa7..dc8025a7b0 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -4,7 +4,6 @@ module.exports = exports = rebuild exports.usage = 'Runs "clean", "configure" and "build" all at once' function rebuild (gyp, argv, callback) { - gyp.todo.push( { name: 'clean', args: [] } , { name: 'configure', args: argv } diff --git a/lib/remove.js b/lib/remove.js index eb80981b88..213af2b9d3 100644 --- a/lib/remove.js +++ b/lib/remove.js @@ -3,10 +3,6 @@ module.exports = exports = remove exports.usage = 'Removes the node development files for the specified version' -/** - * Module dependencies. - */ - var fs = require('fs') , rm = require('rimraf') , path = require('path') @@ -14,7 +10,6 @@ var fs = require('fs') , semver = require('semver') function remove (gyp, argv, callback) { - var devDir = gyp.devDir log.verbose('remove', 'using node-gyp dir:', devDir) @@ -48,5 +43,4 @@ function remove (gyp, argv, callback) { // Go ahead and delete the dir rm(versionPath, callback) }) - } From b428ba312d91ce08a2876fa13f862e88e5b9263c Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Wed, 25 Jul 2018 21:22:26 -0400 Subject: [PATCH 2/2] [squash] add back npm attribution --- bin/node-gyp.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/node-gyp.js b/bin/node-gyp.js index 7d63f6b0ec..0cc3517748 100755 --- a/bin/node-gyp.js +++ b/bin/node-gyp.js @@ -118,6 +118,7 @@ process.on('uncaughtException', function (err) { }) function errorMessage () { + // copied from npm's lib/utils/error-handler.js var os = require('os') log.error('System', os.type() + ' ' + os.release()) log.error('command', process.argv