Skip to content

Commit

Permalink
Merge pull request #36 from cnpm/strict-ssl
Browse files Browse the repository at this point in the history
feat: support read strict-ssl from npm config
  • Loading branch information
fengmk2 committed Mar 3, 2016
2 parents 7d20708 + 4a8e3d4 commit 724b398
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ co(function*() {

## Support Features

- [x] all types of npm package
- [x] a) a folder containing a program described by a package.json file (`npm install file:eslint-rule`)
- [x] b) a gzipped tarball containing (a) (`npm install ./rule.tgz`)
- [x] c) a url that resolves to (b) (`npm install https://github.com/indexzero/forever/tarball/v0.5.6`)
- [x] d) a <name>@<version> that is published on the registry with (c)
- [x] e) a <name>@<tag> (see npm-dist-tag) that points to (d)
- [x] f) a <name> that has a "latest" tag satisfying (e)
- [x] g) a <git remote url> that resolves to (a) (`npm install git://github.com/timaschew/cogent#fix-redirects`)
- [x] All platform support
- [x] global install (`-g, --global`)
- [x] postinstall script
- [x] support Windows
- [x] `preinstall`, `install`, `postinstall` scripts
- [x] node-gyp
- [x] node-pre-gyp
- [x] bin ([email protected], [email protected])
Expand All @@ -108,16 +116,6 @@ co(function*() {
- [x] peerDependencies ([email protected], [email protected], [email protected])
- [x] deprecate message
- [x] `--production` mode
- [x] cleanup when install failed
- all types of npm package
- [x] a) a folder containing a program described by a package.json file (`npm install file:eslint-rule`)
- [x] b) a gzipped tarball containing (a) (`npm install ./rule.tgz`)
- [x] c) a url that resolves to (b) (`npm install https://github.com/indexzero/forever/tarball/v0.5.6`)
- [x] d) a <name>@<version> that is published on the registry with (c)
- [x] e) a <name>@<tag> (see npm-dist-tag) that points to (d)
- [x] f) a <name> that has a "latest" tag satisfying (e)
- [x] g) a <git remote url> that resolves to (a) (`npm install git://github.com/timaschew/cogent#fix-redirects`)
- [x] `preinstall`, `install`, `postinstall` scripts
- [x] `save`, `save-dev`, `save-optional`

## Different with NPM
Expand All @@ -141,10 +139,8 @@ Two rules:

e.g.:

- app: `{ "dependencies": { "a": "1.0.0" } }` (root)
- [email protected]: `{ "dependencies": { "c": "2.0.0", "b": "1.0.0" } }`
- [email protected]: `{ "dependencies": { "c": "1.0.0" } }`
- [email protected] & [email protected]: `{ "dependencies": { } }`
- app: `{ "dependencies": { "debug": "2.2.0", "ms": "0.5.1" } }` (root)
- [email protected]: `{ "dependencies": { "ms": "0.7.1" } }`

```bash
app/
Expand Down
11 changes: 11 additions & 0 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ co(function*() {
config.targetDir = path.join(npmPrefix, 'lib');
config.binDir = path.join(npmPrefix, 'bin');
}
config.strictSSL = getStrictSSL();
yield npminstall(config);

if (!argv.global && pkgs.length > 0) {
Expand Down Expand Up @@ -183,6 +184,16 @@ function getVersionSavePrefix() {
}
}

function getStrictSSL() {
try {
const strictSSL = execSync('npm config get strict-ssl').toString().trim();
return strictSSL !== 'false';
} catch (err) {
console.error(`exec npm config get strict-ssl ERROR: ${err.message}`);
return true;
}
}

function* updateDependencies(root, pkgs, propName) {
const savePrefix = getVersionSavePrefix();
const pkgFile = path.join(root, 'package.json');
Expand Down
6 changes: 3 additions & 3 deletions lib/download/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function* (pkg, options) {
timeout: options.timeout,
followRedirect: true,
gzip: true,
});
}, options);
const realPkg = result.data;
options.totalJSONSize += result.res.size;
options.totalJSONCount += 1;
Expand Down Expand Up @@ -111,7 +111,7 @@ function* getTarballStream(pkg, options) {
timeout: options.timeout,
followRedirect: true,
streaming: true,
});
}, options);

if (result.status !== 200) {
destroy(result.res);
Expand Down Expand Up @@ -142,7 +142,7 @@ function* getTarballStream(pkg, options) {
timeout: options.timeout,
followRedirect: true,
writeStream: fs.createWriteStream(tmpFile),
});
}, options);

if (result.status !== 200) {
throw new Error(`Download ${pkg.dist.tarball} status: ${result.status} error, should be 200`);
Expand Down
2 changes: 1 addition & 1 deletion lib/download/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function* getTarballStream(url, options) {
timeout: options.timeout,
followRedirect: true,
streaming: true,
});
}, options);

if (result.status !== 200) {
destroy(result.res);
Expand Down
3 changes: 2 additions & 1 deletion lib/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ const httpsKeepaliveAgent = new HttpsAgent({

const USER_AGENT = 'npminstall/' + require('../package.json').version + ' ' + urllib.USER_AGENT;

function* get(url, options) {
function* get(url, options, globalOptions) {
options.httpsAgent = httpsKeepaliveAgent;
options.agent = httpKeepaliveAgent;
options.headers = options.headers || {};
options.headers['User-Agent'] = USER_AGENT;
options.rejectUnauthorized = globalOptions.strictSSL;
const result = yield _get(url, options, 5);
debug('GET %s, headers: %j from %j', result.status, result.headers, url);
if (result.status < 100 || result.status >= 300) {
Expand Down

0 comments on commit 724b398

Please sign in to comment.