From 36dd809fdf481d1994ac11c21838e194b228e77d Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 26 Feb 2015 17:42:35 +0800 Subject: [PATCH 01/30] Add travis test Also fix typo on nodeDistUrl --- .travis.yml | 5 +++++ bin.js | 6 +++--- package.json | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e5919d..3784b85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,8 @@ language: node_js node_js: + - "iojs" + - "0.12" + - "0.11" - "0.10" +script: + - npm test diff --git a/bin.js b/bin.js index fe2cdf2..5c29c1c 100755 --- a/bin.js +++ b/bin.js @@ -7,12 +7,12 @@ var zlib = require('zlib') var fs = require('fs') var path = require('path') -var io = parseInt(process.version.slice(1), 10) >= 1 // yolo +var io = process.execPath.indexOf('iojs') !== -1 var iojsDistUrl = process.env.NVM_IOJS_ORG_MIRROR || 'https://iojs.org/dist/' if (iojsDistUrl[iojsDistUrl.length - 1] !== '/') { iojsDistUrl += '/' } -var nodeDistUrl = process.env.NVM_NODEJS_ORG_MIRROR || 'https://iojs.org/dist/' +var nodeDistUrl = process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist/' if (nodeDistUrl[nodeDistUrl.length - 1] !== '/') { nodeDistUrl += '/' } @@ -26,7 +26,7 @@ var target = path.join(process.env.HOME || process.env.USERPROFILE, '.node-gyp', if (fs.existsSync(path.join(target, 'installVersion'))) { console.log('Header files already fetched') console.log('node-gyp should now work for %s', process.version) - process.exit(1) + process.exit(0) } console.log('Fetching header files from %s', url) diff --git a/package.json b/package.json index e0390ea..8965b7d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "node-gyp-install": "./bin.js" }, "scripts": { - "test": "standard" + "test": "standard && node bin.js && node bin.js" }, "repository": { "type": "git", From 04dfdac1a5b322e6265d2c1429a2957ffc9a51b9 Mon Sep 17 00:00:00 2001 From: Jacob Burden Date: Sat, 28 Mar 2015 23:39:02 -0400 Subject: [PATCH 02/30] fetch header files for io.js-nightly versions --- bin.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin.js b/bin.js index fe2cdf2..cd26df3 100755 --- a/bin.js +++ b/bin.js @@ -7,12 +7,17 @@ var zlib = require('zlib') var fs = require('fs') var path = require('path') +var distBase = 'https://iojs.org/dist/' +if (process.version.indexOf('nightly') > -1) { + distBase = 'https://iojs.org/download/nightly/' +} + var io = parseInt(process.version.slice(1), 10) >= 1 // yolo -var iojsDistUrl = process.env.NVM_IOJS_ORG_MIRROR || 'https://iojs.org/dist/' +var iojsDistUrl = process.env.NVM_IOJS_ORG_MIRROR || distBase if (iojsDistUrl[iojsDistUrl.length - 1] !== '/') { iojsDistUrl += '/' } -var nodeDistUrl = process.env.NVM_NODEJS_ORG_MIRROR || 'https://iojs.org/dist/' +var nodeDistUrl = process.env.NVM_NODEJS_ORG_MIRROR || distBase if (nodeDistUrl[nodeDistUrl.length - 1] !== '/') { nodeDistUrl += '/' } From adcc6ef65504bb616086b05dd3ab93e767a10bab Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sun, 29 Mar 2015 22:07:08 +0200 Subject: [PATCH 03/30] 1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8965b7d..4ee369c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.2.0", + "version": "1.3.0", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From ec8a156df9f7212cabf13b2f0d8066d32258f87d Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 9 Apr 2015 17:39:19 -0700 Subject: [PATCH 04/30] should be globally installed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 43a3ba7..e7f04de 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Manually download node/iojs header files for usage with node-gyp. ``` sh -npm install node-gyp-install +npm install -g node-gyp-install ``` [![build status](http://img.shields.io/travis/mafintosh/node-gyp-install.svg?style=flat)](http://travis-ci.org/mafintosh/node-gyp-install) From 2087df1e815d30da52fb62ff73bce12c37a9c21a Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 9 Apr 2015 17:39:25 -0700 Subject: [PATCH 05/30] 1.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ee369c..e371d2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.3.0", + "version": "1.3.1", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 7e7afcc4fa9ef6bc0a2017e4bd266c5557ea5145 Mon Sep 17 00:00:00 2001 From: Chris Antaki Date: Sun, 19 Apr 2015 17:29:13 -0700 Subject: [PATCH 06/30] Fixed a typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7f04de..a08b469 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ npm install level # does not explode \o/ To use a mirror of the node/iojs header files, set `$NVM_NODEJS_ORG_MIRROR` and `$NVM_IOJS_ORG_MIRROR`. -Take an exapmle for users from China: +Take an example for users from China: ``` sh export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node From b288d2480cac482ebc5169c8e0dfb70dcd419875 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Fri, 24 Jul 2015 15:13:09 +0200 Subject: [PATCH 07/30] add js api and cli options --- README.md | 15 ++++++- bin.js | 112 +++++++++++---------------------------------------- index.js | 91 +++++++++++++++++++++++++++++++++++++++++ package.json | 5 ++- 4 files changed, 132 insertions(+), 91 deletions(-) create mode 100644 index.js diff --git a/README.md b/README.md index a08b469..69e759b 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,13 @@ node-gyp-install Afterwards installing native modules that uses node-gyp using iojs should *just work* ``` sh -# assuming you are using iojs node-gyp-install npm install level # does not explode \o/ ``` +Per default node-gyp-install will install header files for your current node version. +To see all available options see `node-gyp-install --help`. + ### Download From Mirrors To use a mirror of the node/iojs header files, set `$NVM_NODEJS_ORG_MIRROR` and `$NVM_IOJS_ORG_MIRROR`. @@ -36,6 +38,17 @@ export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node export NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs ``` +## Programmatic usage + +You can also use this as a module + +``` js +var install = require('node-gyp-install') +install(function (err) { + console.log('header files installed', err) +}) +``` + ## License MIT diff --git a/bin.js b/bin.js index 4e1105a..603423a 100755 --- a/bin.js +++ b/bin.js @@ -1,94 +1,28 @@ #!/usr/bin/env node -var request = require('request') -var map = require('tar-map-stream') -var tar = require('tar-fs') -var zlib = require('zlib') -var fs = require('fs') -var path = require('path') - -var io = process.execPath.indexOf('iojs') !== -1 -var nightly = process.version.indexOf('nightly') > -1 - -var iojsDistUrl = process.env.NVM_IOJS_ORG_MIRROR || (nightly ? 'https://iojs.org/download/nightly/' : 'https://iojs.org/dist/') -if (iojsDistUrl[iojsDistUrl.length - 1] !== '/') { - iojsDistUrl += '/' -} - -var nodeDistUrl = process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist/' -if (nodeDistUrl[nodeDistUrl.length - 1] !== '/') { - nodeDistUrl += '/' -} - -var url = io ? - iojsDistUrl + process.version + '/iojs-' + process.version + '.tar.gz' : - nodeDistUrl + process.version + '/node-' + process.version + '.tar.gz' - -var target = path.join(process.env.HOME || process.env.USERPROFILE, '.node-gyp', process.version.slice(1)) - -if (fs.existsSync(path.join(target, 'installVersion'))) { - console.log('Header files already fetched') - console.log('node-gyp should now work for %s', process.version) +var install = require('./') +var minimist = require('minimist') +var argv = minimist(process.argv, { + booleans: ['iojs', 'nightly', 'quiet', 'force'], + alias: {iojs: 'io', v: 'version', p: 'platform', d: 'dist', q: 'quiet', n: 'nightly', f: 'force'} +}) + +argv.log = !argv.quiet && console.log +if (argv.version && argv.version[0] !== 'v') argv.version = 'v' + argv.version + +if (argv.help) { + console.error( + 'node-gyp-install [options]\n' + + ' --version, -v (' + process.version + ')\n' + + ' --platform, -p (' + process.platform + ')\n' + + ' --force, -f\n' + + ' --nightly, -n\n' + + ' --quiet, -q\n' + + ' --iojs\n' + ) process.exit(0) } -console.log('Fetching header files from %s', url) - -request(url) - .pipe(zlib.createGunzip()) - .pipe(map(function (entry) { - return /(\.gypi$)|(\.h$)/.test(entry.name) ? entry : null - })) - .pipe(tar.extract(target, {strip: 1})) - .on('finish', function () { - downloadLibs(function () { - fs.writeFileSync(path.join(target, 'installVersion'), '9') // yolo - console.log('node-gyp should now work for %s', process.version) - }) - }) - -function downloadLibs (callback) { - if (process.platform !== 'win32') { - return callback() - } - - var urls - if (io) { - urls = [ - iojsDistUrl + process.version + '/win-x86/iojs.lib', - iojsDistUrl + process.version + '/win-x64/iojs.lib' - ] - } else { - urls = [ - nodeDistUrl + process.version + '/node.lib', - nodeDistUrl + process.version + '/x64/node.lib' - ] - } - - var count = 0 - var done = function () { - count++ - if (count === 2) { - callback() - } - } - urls.forEach(function (url, index) { - var arch = index === 0 ? 'ia32' : 'x64' - console.log('Fetching windows %s lib from %s', arch, url) - var nodeLib = path.join(process.env.HOME || process.env.USERPROFILE, '.node-gyp', - process.version.slice(1), arch, 'node.lib') - var parentDir = path.dirname(nodeLib) - if (!fs.existsSync(parentDir)) { - fs.mkdirSync(parentDir) - } - request(url).pipe(fs.createWriteStream(nodeLib)).on('finish', function () { - if (io) { - // copy node.lib to iojs.lib - var iojsLib = path.join(parentDir, 'iojs.lib') - fs.createReadStream(nodeLib).pipe(fs.createWriteStream(iojsLib)).on('finish', done) - } else { - done() - } - }) - }) -} +install(argv, function (err) { + if (err) console.error('Error: ' + err.message) +}) diff --git a/index.js b/index.js new file mode 100644 index 0000000..7f81278 --- /dev/null +++ b/index.js @@ -0,0 +1,91 @@ +#!/usr/bin/env node + +var request = require('request') +var map = require('tar-map-stream') +var tar = require('tar-fs') +var zlib = require('zlib') +var fs = require('fs') +var path = require('path') +var pump = require('pump') +var after = require('after-all') + +module.exports = install + +function install (opts, cb) { + if (typeof opts === 'function') return install(null, opts) + if (!opts) opts = {} + if (!cb) cb = noop + + var log = opts.log || noop + var version = opts.version || process.version + var nightly = opts.nightly !== undefined ? opts.nightly : process.version.indexOf('nightly') > -1 + var io = opts.iojs !== undefined ? opts.iojs : process.execPath.indexOf('iojs') !== -1 + var platform = opts.platform || process.platform + + var defaultIojsUrl = nightly ? 'https://iojs.org/download/nightly/' : 'https://iojs.org/dist/' + var iojsDistUrl = pad(process.env.NVM_IOJS_ORG_MIRROR || defaultIojsUrl) + var nodeDistUrl = pad(process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist/') + + var url = io ? + iojsDistUrl + version + '/iojs-' + version + '.tar.gz' : + nodeDistUrl + version + '/node-' + version + '.tar.gz' + + var target = path.join(process.env.HOME || process.env.USERPROFILE, '.node-gyp', version.slice(1)) + + fs.exists(path.join(target, 'installVersion'), function (exists) { + if (exists && !opts.force) { + log('Header files already fetched') + log('node-gyp should now work for ' + version) + return cb(null) + } + + log('Fetching header files from ' + url) + pump(request(url), zlib.createGunzip(), map(mapEntry), tar.extract(target, {strip: 1}), function (err) { + if (err) return cb(err) + fetchWindows(function (err) { + if (err) return cb(err) + fs.writeFile(path.join(target, 'installVersion'), '9', function (err) { + if (err) return cb(err) + log('node-gyp should now work for ' + version) + cb() + }) + }) + }) + }) + + function mapEntry (entry) { + return /(\.gypi$)|(\.h$)/.test(entry.name) ? entry : null + } + + function fetchWindows (cb) { + if (platform !== 'win32') return cb() + + var urls = io ? [ + iojsDistUrl + version + '/win-x86/iojs.lib', + iojsDistUrl + version + '/win-x64/iojs.lib' + ] : [ + nodeDistUrl + version + '/node.lib', + nodeDistUrl + version + '/x64/node.lib' + ] + + var next = after(cb) + + urls.forEach(function (url, index) { + var arch = index === 0 ? 'ia32' : 'x64' + var lib = path.join(target, arch, io ? 'iojs.lib' : 'node.lib') + var parentDir = path.dirname(lib) + var done = next() + + log('Fetching windows ' + arch + ' lib from ' + url) + fs.mkdir(parentDir, function () { + pump(request(url), fs.createWriteStream(lib), done) + }) + }) + } +} + +function pad (url) { + return url[url.length - 1] === '/' ? url : url + '/' +} + +function noop () {} diff --git a/package.json b/package.json index e371d2c..f722318 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,15 @@ "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { + "after-all": "^2.0.2", + "minimist": "^1.1.2", + "pump": "^1.0.0", "request": "^2.53.0", "tar-fs": "^1.4.2", "tar-map-stream": "^1.0.0" }, "devDependencies": { - "standard": "^2.5.0" + "standard": "^4.5.4" }, "bin": { "node-gyp-install": "./bin.js" From b13b6deff437610d2fe1c74b0b634f7f6d2fc6c8 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Fri, 24 Jul 2015 15:14:34 +0200 Subject: [PATCH 08/30] 1.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f722318..ec76e3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.3.1", + "version": "1.4.0", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 7369b2740016fcc636f60e265c95887330e75814 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 25 Jul 2015 19:00:30 +0200 Subject: [PATCH 09/30] always prefix version with v --- bin.js | 1 - index.js | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin.js b/bin.js index 603423a..ea756bc 100755 --- a/bin.js +++ b/bin.js @@ -8,7 +8,6 @@ var argv = minimist(process.argv, { }) argv.log = !argv.quiet && console.log -if (argv.version && argv.version[0] !== 'v') argv.version = 'v' + argv.version if (argv.help) { console.error( diff --git a/index.js b/index.js index 7f81278..396b38b 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,9 @@ function install (opts, cb) { var log = opts.log || noop var version = opts.version || process.version - var nightly = opts.nightly !== undefined ? opts.nightly : process.version.indexOf('nightly') > -1 + if (version[0] !== 'v') version = 'v' + version + + var nightly = opts.nightly !== undefined ? opts.nightly : version.indexOf('nightly') > -1 var io = opts.iojs !== undefined ? opts.iojs : process.execPath.indexOf('iojs') !== -1 var platform = opts.platform || process.platform From 378e23c502fb0fa2219488796d804c1f2ff1f788 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 25 Jul 2015 19:00:39 +0200 Subject: [PATCH 10/30] 1.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ec76e3f..f47c9f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.4.0", + "version": "1.4.1", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From e14ec0dd42716c479cd3b93bcd56cbcab71e1abb Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 25 Jul 2015 19:28:45 +0200 Subject: [PATCH 11/30] fix io issue on windows --- index.js | 8 +++++--- package.json | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 396b38b..f813129 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var fs = require('fs') var path = require('path') var pump = require('pump') var after = require('after-all') +var multi = require('multi-write-stream') module.exports = install @@ -74,13 +75,14 @@ function install (opts, cb) { urls.forEach(function (url, index) { var arch = index === 0 ? 'ia32' : 'x64' - var lib = path.join(target, arch, io ? 'iojs.lib' : 'node.lib') - var parentDir = path.dirname(lib) + var nodeLib = path.join(target, arch, 'node.lib') + var ioLib = path.join(target, arch, 'iojs.lib') + var parentDir = path.dirname(nodeLib) var done = next() log('Fetching windows ' + arch + ' lib from ' + url) fs.mkdir(parentDir, function () { - pump(request(url), fs.createWriteStream(lib), done) + pump(request(url), multi([fs.createWriteStream(nodeLib), fs.createWriteStream(ioLib)]), done) }) }) } diff --git a/package.json b/package.json index f47c9f0..01cb24c 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dependencies": { "after-all": "^2.0.2", "minimist": "^1.1.2", + "multi-write-stream": "^1.0.3", "pump": "^1.0.0", "request": "^2.53.0", "tar-fs": "^1.4.2", From 3bd73c949b31d01060117d326ac64f967b3da214 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 25 Jul 2015 19:28:48 +0200 Subject: [PATCH 12/30] 1.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 01cb24c..2762d63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.4.1", + "version": "1.4.2", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From e422ad6795c7ce2428c3a34e0d8b95b1c8bb2cfe Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 25 Jul 2015 21:29:19 +0200 Subject: [PATCH 13/30] no io releases before 1.0.0 --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index f813129..f2f7524 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,8 @@ function install (opts, cb) { var io = opts.iojs !== undefined ? opts.iojs : process.execPath.indexOf('iojs') !== -1 var platform = opts.platform || process.platform + if (io && version[1] === '0') io = false + var defaultIojsUrl = nightly ? 'https://iojs.org/download/nightly/' : 'https://iojs.org/dist/' var iojsDistUrl = pad(process.env.NVM_IOJS_ORG_MIRROR || defaultIojsUrl) var nodeDistUrl = pad(process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist/') From c7da4f315c875ae8ea29c2f55b77e3b1136b95b6 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 25 Jul 2015 21:31:59 +0200 Subject: [PATCH 14/30] if version is specified use that to infer iojs --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f2f7524..4e8ce2a 100644 --- a/index.js +++ b/index.js @@ -22,11 +22,9 @@ function install (opts, cb) { if (version[0] !== 'v') version = 'v' + version var nightly = opts.nightly !== undefined ? opts.nightly : version.indexOf('nightly') > -1 - var io = opts.iojs !== undefined ? opts.iojs : process.execPath.indexOf('iojs') !== -1 + var io = opts.iojs !== undefined ? opts.iojs : (opts.version ? iojsVersion(version) : process.execPath.indexOf('iojs') !== -1) var platform = opts.platform || process.platform - if (io && version[1] === '0') io = false - var defaultIojsUrl = nightly ? 'https://iojs.org/download/nightly/' : 'https://iojs.org/dist/' var iojsDistUrl = pad(process.env.NVM_IOJS_ORG_MIRROR || defaultIojsUrl) var nodeDistUrl = pad(process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist/') @@ -90,6 +88,10 @@ function install (opts, cb) { } } +function iojsVersion (v) { + return v[1] !== '0' +} + function pad (url) { return url[url.length - 1] === '/' ? url : url + '/' } From 459c3ebcacb6dd33d2ddcd784c8f9d0a91bc43c7 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 25 Jul 2015 21:32:08 +0200 Subject: [PATCH 15/30] 1.4.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2762d63..766fcf6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.4.2", + "version": "1.4.3", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From b2f9ed9e8bbbbb9eb1173ec47a0380af185a4ad5 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Wed, 29 Jul 2015 00:04:08 +0200 Subject: [PATCH 16/30] always rely on version sniffing --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4e8ce2a..750f1e3 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ function install (opts, cb) { if (version[0] !== 'v') version = 'v' + version var nightly = opts.nightly !== undefined ? opts.nightly : version.indexOf('nightly') > -1 - var io = opts.iojs !== undefined ? opts.iojs : (opts.version ? iojsVersion(version) : process.execPath.indexOf('iojs') !== -1) + var io = opts.iojs !== undefined ? opts.iojs : iojsVersion(version) var platform = opts.platform || process.platform var defaultIojsUrl = nightly ? 'https://iojs.org/download/nightly/' : 'https://iojs.org/dist/' From 9b4853085f7acb94ed68438f9ee74c0115495b01 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Wed, 29 Jul 2015 00:04:11 +0200 Subject: [PATCH 17/30] 1.4.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 766fcf6..288ad6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.4.3", + "version": "1.4.4", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 7d5f45da0384b53cbd06e408b212457d883027e4 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 1 Aug 2015 16:44:23 +0200 Subject: [PATCH 18/30] switch to simple-get and npmlog --- bin.js | 2 +- index.js | 32 ++++++++++++++++++++------------ package.json | 3 ++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/bin.js b/bin.js index ea756bc..b82dac6 100755 --- a/bin.js +++ b/bin.js @@ -7,7 +7,7 @@ var argv = minimist(process.argv, { alias: {iojs: 'io', v: 'version', p: 'platform', d: 'dist', q: 'quiet', n: 'nightly', f: 'force'} }) -argv.log = !argv.quiet && console.log +argv.log = !argv.quiet && require('npmlog') if (argv.help) { console.error( diff --git a/index.js b/index.js index 750f1e3..14d7deb 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -var request = require('request') +var get = require('simple-get') var map = require('tar-map-stream') var tar = require('tar-fs') var zlib = require('zlib') @@ -17,7 +17,7 @@ function install (opts, cb) { if (!opts) opts = {} if (!cb) cb = noop - var log = opts.log || noop + var log = opts.log var version = opts.version || process.version if (version[0] !== 'v') version = 'v' + version @@ -37,20 +37,24 @@ function install (opts, cb) { fs.exists(path.join(target, 'installVersion'), function (exists) { if (exists && !opts.force) { - log('Header files already fetched') - log('node-gyp should now work for ' + version) + if (log) log.info('node-gyp-install', 'Header files already fetched') + if (log) log.info('node-gyp-install', 'node-gyp should now work for ' + version) return cb(null) } - log('Fetching header files from ' + url) - pump(request(url), zlib.createGunzip(), map(mapEntry), tar.extract(target, {strip: 1}), function (err) { + if (log) log.http('request', url) + get(url, function (err, res) { if (err) return cb(err) - fetchWindows(function (err) { + if (log) log.http(res.statusCode, url) + pump(res, zlib.createGunzip(), map(mapEntry), tar.extract(target, {strip: 1}), function (err) { if (err) return cb(err) - fs.writeFile(path.join(target, 'installVersion'), '9', function (err) { + fetchWindows(function (err) { if (err) return cb(err) - log('node-gyp should now work for ' + version) - cb() + fs.writeFile(path.join(target, 'installVersion'), '9', function (err) { + if (err) return cb(err) + if (log) log.info('node-gyp-install', 'node-gyp should now work for ' + version) + cb() + }) }) }) }) @@ -80,9 +84,13 @@ function install (opts, cb) { var parentDir = path.dirname(nodeLib) var done = next() - log('Fetching windows ' + arch + ' lib from ' + url) + if (log) log.http('request', url) fs.mkdir(parentDir, function () { - pump(request(url), multi([fs.createWriteStream(nodeLib), fs.createWriteStream(ioLib)]), done) + get(url, function (err, res) { + if (err) return done(err) + log.http(res.statusCode, url) + pump(res, multi([fs.createWriteStream(nodeLib), fs.createWriteStream(ioLib)]), done) + }) }) }) } diff --git a/package.json b/package.json index 288ad6d..c5828c4 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,9 @@ "after-all": "^2.0.2", "minimist": "^1.1.2", "multi-write-stream": "^1.0.3", + "npmlog": "^1.2.1", "pump": "^1.0.0", - "request": "^2.53.0", + "simple-get": "^1.4.2", "tar-fs": "^1.4.2", "tar-map-stream": "^1.0.0" }, From 8eba0cc3005eff78ce42f8ccab978bce90baeb17 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 1 Aug 2015 16:44:25 +0200 Subject: [PATCH 19/30] 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c5828c4..8f0c931 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "1.4.4", + "version": "2.0.0", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 32693bfb4f1a7d674ba73d94de4f9480297937c8 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 1 Aug 2015 16:47:32 +0200 Subject: [PATCH 20/30] fix headers --- bin.js | 4 +++- index.js | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bin.js b/bin.js index b82dac6..b221e89 100755 --- a/bin.js +++ b/bin.js @@ -2,12 +2,14 @@ var install = require('./') var minimist = require('minimist') +var log = require('npmlog') var argv = minimist(process.argv, { booleans: ['iojs', 'nightly', 'quiet', 'force'], alias: {iojs: 'io', v: 'version', p: 'platform', d: 'dist', q: 'quiet', n: 'nightly', f: 'force'} }) -argv.log = !argv.quiet && require('npmlog') +log.heading = 'node-gyp-install' +argv.log = !argv.quiet && log if (argv.help) { console.error( diff --git a/index.js b/index.js index 14d7deb..be1a134 100644 --- a/index.js +++ b/index.js @@ -37,8 +37,8 @@ function install (opts, cb) { fs.exists(path.join(target, 'installVersion'), function (exists) { if (exists && !opts.force) { - if (log) log.info('node-gyp-install', 'Header files already fetched') - if (log) log.info('node-gyp-install', 'node-gyp should now work for ' + version) + if (log) log.info('install', 'Header files already fetched') + if (log) log.info('install', 'node-gyp should now work for ' + version) return cb(null) } @@ -52,7 +52,7 @@ function install (opts, cb) { if (err) return cb(err) fs.writeFile(path.join(target, 'installVersion'), '9', function (err) { if (err) return cb(err) - if (log) log.info('node-gyp-install', 'node-gyp should now work for ' + version) + if (log) log.info('install', 'node-gyp should now work for ' + version) cb() }) }) From 9c261a11ccdd80d9bb1bdcdeeb5525482734194c Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 1 Aug 2015 16:47:36 +0200 Subject: [PATCH 21/30] 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f0c931..f76df2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "2.0.0", + "version": "2.0.1", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 1b7ec8f51909103a6a566792062517f684306203 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 5 Sep 2015 12:41:21 +0200 Subject: [PATCH 22/30] check for installVersion and common.gypi --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index be1a134..50c3267 100644 --- a/index.js +++ b/index.js @@ -35,8 +35,8 @@ function install (opts, cb) { var target = path.join(process.env.HOME || process.env.USERPROFILE, '.node-gyp', version.slice(1)) - fs.exists(path.join(target, 'installVersion'), function (exists) { - if (exists && !opts.force) { + exists(function (err) { + if (!err && !opts.force) { if (log) log.info('install', 'Header files already fetched') if (log) log.info('install', 'node-gyp should now work for ' + version) return cb(null) @@ -60,6 +60,15 @@ function install (opts, cb) { }) }) + function exists (cb) { + fs.exists(path.join(target, 'installVersion'), function (exists) { + if (!exists) return cb(new Error('missing installVersion')) + fs.exists(path.join(target, 'common.gypi'), function (exists) { + cb(exists ? null : new Error('missing common.gypi')) + }) + }) + } + function mapEntry (entry) { return /(\.gypi$)|(\.h$)/.test(entry.name) ? entry : null } From 7ed863cea810ffa9e78340b922d6c28d7ee13b44 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 5 Sep 2015 12:20:01 +0100 Subject: [PATCH 23/30] 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f76df2f..153f768 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "2.0.1", + "version": "2.1.0", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From f954f056a44829f08fb27e6b95a7ef098c5d4066 Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Tue, 8 Sep 2015 22:47:20 +0200 Subject: [PATCH 24/30] Fix for Node.js v4.0.0 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 50c3267..86045be 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ function install (opts, cb) { } function iojsVersion (v) { - return v[1] !== '0' + return v[1] !== '0' && v[1] < 4 } function pad (url) { From 600ffabaa49dfb5a9d3f19dbd28ab3345e93ad07 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Tue, 8 Sep 2015 23:20:19 +0200 Subject: [PATCH 25/30] 2.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 153f768..63bf67e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "2.1.0", + "version": "2.1.1", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 6e19e082cb80cb975c96ddd96775d4711c7c0698 Mon Sep 17 00:00:00 2001 From: Brett Lawson Date: Mon, 21 Sep 2015 10:12:47 -0300 Subject: [PATCH 26/30] Fix incorrect download uri for Node v4.0.0 Correctly select lib download URI for Node.js v4.0.0 which uses an io.js style pathing. --- index.js | 27 +++++++++++++++++++-------- package.json | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 86045be..4f21d53 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ var path = require('path') var pump = require('pump') var after = require('after-all') var multi = require('multi-write-stream') +var semver = require('semver') module.exports = install @@ -76,13 +77,23 @@ function install (opts, cb) { function fetchWindows (cb) { if (platform !== 'win32') return cb() - var urls = io ? [ - iojsDistUrl + version + '/win-x86/iojs.lib', - iojsDistUrl + version + '/win-x64/iojs.lib' - ] : [ - nodeDistUrl + version + '/node.lib', - nodeDistUrl + version + '/x64/node.lib' - ] + var urls + if (io) { + urls = [ + iojsDistUrl + version + '/win-x86/iojs.lib', + iojsDistUrl + version + '/win-x64/iojs.lib' + ] + } else if (semver.satisfies(version, '>=4.0.0')) { + urls = [ + nodeDistUrl + version + '/win-x86/node.lib', + nodeDistUrl + version + '/win-x64/node.lib' + ] + } else { + urls = [ + nodeDistUrl + version + '/node.lib', + nodeDistUrl + version + '/x64/node.lib' + ] + } var next = after(cb) @@ -106,7 +117,7 @@ function install (opts, cb) { } function iojsVersion (v) { - return v[1] !== '0' && v[1] < 4 + return semver.satisfies(v, '>=1.0.0 <4.0.0') } function pad (url) { diff --git a/package.json b/package.json index 63bf67e..8c71c8e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "multi-write-stream": "^1.0.3", "npmlog": "^1.2.1", "pump": "^1.0.0", + "semver": "~5.0.3", "simple-get": "^1.4.2", "tar-fs": "^1.4.2", "tar-map-stream": "^1.0.0" From 9b375eda5d610b77ac7a9b63c431e5a2100cfbc4 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Mon, 21 Sep 2015 18:22:21 +0200 Subject: [PATCH 27/30] 2.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c71c8e..9f8d759 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "2.1.1", + "version": "2.1.2", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 990f7b40d6447fae12a66f36cf6a964ce0ddc171 Mon Sep 17 00:00:00 2001 From: otoense Date: Tue, 10 Nov 2015 14:49:11 +0100 Subject: [PATCH 28/30] pass some tls options in order to use secure mirrors commit 8f8c8e2d54bd6228125ffe76a4893ac85721db4c Author: otoense Date: Tue Nov 10 14:01:17 2015 +0100 Revert "add intellij files to gitignore" This reverts commit 34b98f45998af9bb20ed566afde7d2edcd6a870a. commit 0ce54037696c3951612e6a1c1910bf2bc1178d1c Author: otoense Date: Tue Nov 10 13:31:08 2015 +0100 meet 'standard' code style commit 8fbe40546e401c3562df13c0847f00af8d20a653 Author: otoense Date: Tue Nov 10 12:34:30 2015 +0100 fix readme commit e954663b1e5ac1bc98ef19c3beb7c96239cc1663 Author: otoense Date: Tue Nov 10 12:32:04 2015 +0100 extend readme by 'secure mirrors' section commit 39200eb3013282a7e37bf3601fbd281dde3dff33 Author: otoense Date: Tue Nov 10 09:48:10 2015 +0100 add https/tls configuration commit 34b98f45998af9bb20ed566afde7d2edcd6a870a Author: otoense Date: Tue Nov 10 09:47:41 2015 +0100 add intellij files to gitignore --- README.md | 19 +++++++++++++++++++ index.js | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 69e759b..8d9dbe9 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,25 @@ export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node export NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs ``` +### Download From Secure Mirrors + +To use private mirrors that need some https/tls configuration e.g. for client authentification you +can pass some more environment settings: + +``` sh +export NODE_GYP_INSTALL_PASSPHRASE=mysecret +export NODE_GYP_INSTALL_REJECTUNAUTHORIZED=false +export NODE_GYP_INSTALL_PFX=/path/to/my/key.p12 +export NODE_GYP_INSTALL_CERT=/path/to/my/cert.crt +export NODE_GYP_INSTALL_KEY=/path/to/my/key.key +export NODE_GYP_INSTALL_CA=/path/to/my/ca.crt +``` + +This variables refers to the according options of the https.request() function. +Please have a look to [nodejs tls api documentation](https://nodejs.org/api/tls.html) +for more details. + + ## Programmatic usage You can also use this as a module diff --git a/index.js b/index.js index 4f21d53..367ae59 100644 --- a/index.js +++ b/index.js @@ -30,9 +30,9 @@ function install (opts, cb) { var iojsDistUrl = pad(process.env.NVM_IOJS_ORG_MIRROR || defaultIojsUrl) var nodeDistUrl = pad(process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist/') - var url = io ? - iojsDistUrl + version + '/iojs-' + version + '.tar.gz' : - nodeDistUrl + version + '/node-' + version + '.tar.gz' + var url = io + ? iojsDistUrl + version + '/iojs-' + version + '.tar.gz' + : nodeDistUrl + version + '/node-' + version + '.tar.gz' var target = path.join(process.env.HOME || process.env.USERPROFILE, '.node-gyp', version.slice(1)) @@ -44,7 +44,7 @@ function install (opts, cb) { } if (log) log.http('request', url) - get(url, function (err, res) { + get(tlsopts(url), function (err, res) { if (err) return cb(err) if (log) log.http(res.statusCode, url) pump(res, zlib.createGunzip(), map(mapEntry), tar.extract(target, {strip: 1}), function (err) { @@ -106,7 +106,7 @@ function install (opts, cb) { if (log) log.http('request', url) fs.mkdir(parentDir, function () { - get(url, function (err, res) { + get(tlsopts(url), function (err, res) { if (err) return done(err) log.http(res.statusCode, url) pump(res, multi([fs.createWriteStream(nodeLib), fs.createWriteStream(ioLib)]), done) @@ -114,6 +114,32 @@ function install (opts, cb) { }) }) } + + function tlsopts (url) { + var getOpts = { + url: url, + passphrase: process.env.NODE_GYP_INSTALL_PASSPHRASE, + requestCert: true, + rejectUnauthorized: process.env.NODE_GYP_INSTALL_REJECTUNAUTHORIZED === 'true' + } + + if (process.env.NODE_GYP_INSTALL_PFX) { + getOpts.pfx = fs.readFileSync(process.env.NODE_GYP_INSTALL_PFX) + } + + if (process.env.NODE_GYP_INSTALL_CERT) { + getOpts.cert = fs.readFileSync(process.env.NODE_GYP_INSTALL_CERT) + } + + if (process.env.NODE_GYP_INSTALL_KEY) { + getOpts.cert = fs.readFileSync(process.env.NODE_GYP_INSTALL_KEY) + } + + if (process.env.NODE_GYP_INSTALL_CA) { + getOpts.ca = [fs.readFileSync(process.env.NODE_GYP_INSTALL_CA)] + } + return getOpts + } } function iojsVersion (v) { From 9311919f555fcacc4b997626a8eed427b6311487 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Tue, 10 Nov 2015 10:36:44 -0800 Subject: [PATCH 29/30] 2.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9f8d759..240d169 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-gyp-install", - "version": "2.1.2", + "version": "2.2.0", "description": "Manually download node/iojs header files for usage with node-gyp.", "main": "index.js", "dependencies": { From 4f3da5a1735e088c4d1ce3095908c80bd2ea33c9 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Wed, 8 Feb 2017 23:52:10 +0800 Subject: [PATCH 30/30] chore: upgrade license --- .travis.yml | 1 - LICENSE | 1 + README.md | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 159df4d..1238a99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ sudo: false language: node_js node_js: - - "lts" - "7" - "6" - "4" diff --git a/LICENSE b/LICENSE index 66a4d2a..3746f79 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2015 Mathias Buus +Copyright (c) 2016 - 2017 cnpm Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 3284292..dfe7fef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# node-gyp-install +# node-gyp-install-cn ___This is a fork `node-gyp-install` using [cnpm mirrors](https://npm.taobao.org/mirrors).___ @@ -8,7 +8,7 @@ Manually download node/iojs header files for usage with node-gyp. npm install -g node-gyp-install-cn ``` -[![build status](http://img.shields.io/travis/mafintosh/node-gyp-install.svg?style=flat)](http://travis-ci.org/mafintosh/node-gyp-install) +[![build status](http://img.shields.io/travis/cnpm/node-gyp-install.svg?style=flat)](http://travis-ci.org/cnpm/node-gyp-install) ## Usage