Skip to content
This repository has been archived by the owner on Dec 24, 2018. It is now read-only.

Commit

Permalink
Fix downloading npm for newer Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Oct 6, 2015
1 parent 80a504b commit 4234f62
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions get_npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,49 @@ var util = require('util'),
path = require('path'),
wget = require('./wget');

var NPM_PKG_JSON_URL = 'https://raw.githubusercontent.com/%s/%s/deps/npm/package.json';
// https://github.com/npm/npm/tags
var NPM_PKG_JSON_URL = 'https://raw.githubusercontent.com/%s/%s/deps/npm/package.json';
// https://github.com/npm/npm/tags
var NVMW_NPM_MIRROR = process.env.NVMW_NPM_MIRROR || 'https://github.com/npm/npm/archive';
var BASE_URL = NVMW_NPM_MIRROR + '/v%s.zip';


var targetDir = process.argv[2];
var versions = process.argv[3].split('/');
var binType = versions[0];
var binVersion = versions[1];

var pkgUri;
if (binType === 'iojs') {
// detect npm version from https://iojs.org/dist/index.json
var NVMW_IOJS_ORG_MIRROR = process.env.NVMW_IOJS_ORG_MIRROR || 'https://iojs.org/dist';
var pkgUri = NVMW_IOJS_ORG_MIRROR + '/index.json';
wget(pkgUri, function (filename, content) {
if (filename === null) {
return noNpmAndExit();
}
var npmVersion;
var items = JSON.parse(content);
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (!npmVersion) {
// make sure has a npm version
npmVersion = item.npm;
}
if (item.version === binVersion && item.npm) {
npmVersion = item.npm;
break;
}
}

pkgUri = NVMW_IOJS_ORG_MIRROR + '/index.json';
} else {
// detect npm version from https://nodejs.org/dist/index.json
var NVMW_NODEJS_ORG_MIRROR = process.env.NVMW_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist';
pkgUri = NVMW_NODEJS_ORG_MIRROR + '/index.json';
}
wget(pkgUri, function (filename, content) {
if (filename === null) {
return noNpmAndExit();
}
var npmVersion;
var items = JSON.parse(content);
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (!npmVersion) {
return noNpmAndExit();
// make sure has a npm version
npmVersion = item.npm;
}
downloadNpmZip(npmVersion);
});
} else {
var pkgUri = util.format(NPM_PKG_JSON_URL, 'joyent/node',
binVersion === 'latest' ? 'master' : binVersion);
wget(pkgUri, function (filename, pkg) {
if (filename === null) {
return noNpmAndExit();
if (item.version === binVersion && item.npm) {
npmVersion = item.npm;
break;
}
downloadNpmZip(JSON.parse(pkg).version);
});
}
}

if (!npmVersion) {
return noNpmAndExit();
}
downloadNpmZip(npmVersion);
});

function noNpmAndExit() {
console.error('%s %s does not include npm', binType, binVersion);
Expand Down

0 comments on commit 4234f62

Please sign in to comment.