From 7c554a4e3ce667a4dc01fc3df952f18578b7ccb3 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 3 Mar 2016 10:29:23 +0800 Subject: [PATCH 1/4] feat: support npm_china env --- bin/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install.js b/bin/install.js index 3d1edd2a..1cba9b24 100755 --- a/bin/install.js +++ b/bin/install.js @@ -101,7 +101,7 @@ if (production) { } // if in china, will automatic using chines registry and mirros. -const inChina = argv.china; +const inChina = argv.china || !!process.env.npm_china; let registry = argv.registry || process.env.npm_registry; if (inChina) { From 2c001db12a8c05bf38ff765656000a0a16f456fd Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 3 Mar 2016 10:30:16 +0800 Subject: [PATCH 2/4] test: add pnpm benchmark scripts --- README.md | 21 ++++++++++++++++ benchmark/Makefile | 12 +++++++++ test/git.sh | 62 +++++++++++++++++++++++++--------------------- 3 files changed, 67 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a5a13058..5208ab35 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,8 @@ app/ ## Benchmarks +### cnpmjs.org install + - npminstall@1.2.0 - pnpm@0.18.0 - npm@2.14.12 @@ -179,6 +181,25 @@ pnpm | 0m13.509s | 0m11.650s | 0m4.443s npm | 0m28.171s | 0m26.085s | 0m8.219s npm with cache | 0m20.939s | 0m19.415s | 0m6.302s +### pnpm benchmark + +see https://github.com/rstacruz/pnpm#benchmark + +```bash +npminstall babel-preset-es2015 browserify chalk debug minimist mkdirp + real 0m8.929s user 0m5.606s sys 0m2.913s +``` + +```bash +pnpm i babel-preset-es2015 browserify chalk debug minimist mkdirp + real 0m12.998s user 0m8.653s sys 0m3.362s +``` + +```bash +npm i babel-preset-es2015 browserify chalk debug minimist mkdirp + real 1m4.729s user 0m55.589s sys 0m23.135s +``` + ## License [MIT](LICENSE) diff --git a/benchmark/Makefile b/benchmark/Makefile index dfc3e804..fd50b630 100644 --- a/benchmark/Makefile +++ b/benchmark/Makefile @@ -20,4 +20,16 @@ cnpmjs.org: @cd cnpmjs.org && rm -rf node_modules @cd cnpmjs.org && time npm install --registry=https://registry.npm.taobao.org +pnpm: + # see https://github.com/rstacruz/pnpm#benchmark + @echo "npminstall babel-preset-es2015 browserify chalk debug minimist mkdirp" + @cd cnpmjs.org && rm -rf node_modules + @cd cnpmjs.org && time ../../bin/install.js -c babel-preset-es2015 browserify chalk debug minimist mkdirp + @echo "pnpm i babel-preset-es2015 browserify chalk debug minimist mkdirp" + @cd cnpmjs.org && rm -rf node_modules + @cd cnpmjs.org && time npm_registry=https://registry.npm.taobao.org pnpm i babel-preset-es2015 browserify chalk debug minimist mkdirp + @echo "npm i babel-preset-es2015 browserify chalk debug minimist mkdirp" + @cd cnpmjs.org && rm -rf node_modules + @cd cnpmjs.org && time npm i babel-preset-es2015 browserify chalk debug minimist mkdirp --registry=https://registry.npm.taobao.org + .PHONY: cnpmjs.org diff --git a/test/git.sh b/test/git.sh index 7c8b2a5b..b7e92ad4 100644 --- a/test/git.sh +++ b/test/git.sh @@ -1,5 +1,35 @@ #!/usr/bin/env sh +rm -rf .tmp + +git clone https://github.com/webpack/webpack.git --depth=1 .tmp +cd .tmp +../bin/install.js +npm test || exit $? +cd .. +rm -rf .tmp + +git clone https://github.com/rstacruz/pnpm.git --depth=1 .tmp +cd .tmp +../bin/install.js +npm test || exit $? +cd .. +rm -rf .tmp + +git clone https://github.com/chaijs/chai.git --depth=1 .tmp +cd .tmp +../bin/install.js +npm test +cd .. +rm -rf .tmp + +git clone https://github.com/substack/node-browserify.git --depth=1 .tmp +cd .tmp +../bin/install.js +npm test +cd .. +rm -rf .tmp + git clone https://github.com/chalk/chalk.git --depth=1 .tmp cd .tmp ../bin/install.js @@ -325,12 +355,7 @@ npm test cd .. rm -rf .tmp -git clone https://github.com/webpack/webpack.git --depth=1 .tmp -cd .tmp -../bin/install.js -npm test -cd .. -rm -rf .tmp + git clone https://github.com/request/request.git --depth=1 .tmp cd .tmp @@ -346,37 +371,18 @@ npm test cd .. rm -rf .tmp -git clone https://github.com/rstacruz/pnpm.git --depth=1 .tmp -cd .tmp -../bin/install.js -npm test -cd .. -rm -rf .tmp - -git clone https://github.com/eslint/eslint.git --depth=1 .tmp -cd .tmp -../bin/install.js -npm test -cd .. -rm -rf .tmp -# git clone https://github.com/ant-design/ant-design.git --depth=1 .tmp -# cd .tmp -# ../bin/install.js -# npm test || exit $? -# cd .. -# rm -rf .tmp -git clone https://github.com/substack/node-browserify.git --depth=1 .tmp +git clone https://github.com/eslint/eslint.git --depth=1 .tmp cd .tmp ../bin/install.js npm test cd .. rm -rf .tmp -git clone https://github.com/chaijs/chai.git --depth=1 .tmp +git clone https://github.com/ant-design/ant-design.git --depth=1 .tmp cd .tmp ../bin/install.js -npm test +npm test || exit $? cd .. rm -rf .tmp From ed86051f4b6babe18ec8e65255f4dbdd75f045af Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 3 Mar 2016 11:53:42 +0800 Subject: [PATCH 3/4] fix: add prepublish script after postinstall --- lib/index.js | 2 ++ lib/prepublish.js | 29 ++++++++++++++++++++++++++ package.json | 4 ++-- test/fixtures/postinstall/package.json | 6 ++++-- test/postinstall.test.js | 4 +++- 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 lib/prepublish.js diff --git a/lib/index.js b/lib/index.js index 12f9af16..f7d25503 100644 --- a/lib/index.js +++ b/lib/index.js @@ -27,6 +27,7 @@ const os = require('os'); const utils = require('./utils'); const postinstall = require('./postinstall'); const preinstall = require('./preinstall'); +const prepublish = require('./prepublish'); const install = require('./install'); const dependencies = require('./dependencies'); @@ -129,6 +130,7 @@ module.exports = function*(options) { if (installRoot) yield postinstall(rootPkg, options.root, false, options); yield runPostInstallTasks(options); + if (installRoot) yield prepublish(rootPkg, options.root, options); if (options.peerDependencies.length > 0) { yield options.peerDependencies.map(item => validatePeerDependencies(item, options)); diff --git a/lib/prepublish.js b/lib/prepublish.js new file mode 100644 index 00000000..1e776a98 --- /dev/null +++ b/lib/prepublish.js @@ -0,0 +1,29 @@ +/** + * Copyright(c) cnpm and other contributors. + * MIT Licensed + * + * Authors: + * fengmk2 (http://fengmk2.com) + */ + +'use strict'; + +/** + * Module dependencies. + */ + +const chalk = require('chalk'); +const runScript = require('./utils').runScript; + +module.exports = prepublish; + +// @see https://docs.npmjs.com/misc/scripts +// Run BEFORE the package is published. (Also run on local npm install without any arguments.) +function* prepublish(pkg, root, options) { + const scripts = pkg.scripts || {}; + if (scripts.prepublish) { + options.console.warn(chalk.yellow('[%s@%s] scripts.prepublish: %j'), + pkg.name, pkg.version, scripts.prepublish); + yield runScript(root, scripts.prepublish, options); + } +} diff --git a/package.json b/package.json index 207fa69e..a4c6df44 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "scripts": { "test": "mocha -r thunk-mocha -t 120000 test/*.test.js", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -r thunk-mocha -t 120000 test/*.test.js", - "test-local": "local=true mocha -r thunk-mocha -t 120000 test/*.test.js", - "test-local-cov": "local=true istanbul cover node_modules/mocha/bin/_mocha -- -r thunk-mocha -t 120000 test/*.test.js", + "test-local": "npm_china=true local=true mocha -r thunk-mocha -t 120000 test/*.test.js", + "test-local-cov": "npm_china=true local=true istanbul cover node_modules/mocha/bin/_mocha -- -r thunk-mocha -t 120000 test/*.test.js", "lint": "eslint lib test bin", "ci": "npm run lint && npm run test-cov", "autod": "autod -w --prefix '~'" diff --git a/test/fixtures/postinstall/package.json b/test/fixtures/postinstall/package.json index 207f382d..c30a1dad 100644 --- a/test/fixtures/postinstall/package.json +++ b/test/fixtures/postinstall/package.json @@ -4,10 +4,12 @@ "scripts": { "preinstall": "node index.js preinstall", "install": "node index.js install", - "postinstall": "node index.js postinstall" + "postinstall": "node index.js postinstall", + "prepublish": "node index.js prepublish" }, "dependencies": { "utility": "1.6.0", - "bignum": "*" + "bignum": "*", + "a-dep-b": "*" } } diff --git a/test/postinstall.test.js b/test/postinstall.test.js index 604dd5f0..6ca19c8b 100644 --- a/test/postinstall.test.js +++ b/test/postinstall.test.js @@ -32,7 +32,7 @@ describe('test/postinstall.test.js', () => { beforeEach(cleanup); afterEach(cleanup); - it('should run preinstall, install and postinstall', function*() { + it('should run preinstall, install, postinstall and prepublish', function*() { yield npminstall({ root: root, }); @@ -46,6 +46,8 @@ describe('test/postinstall.test.js', () => { assert.equal(fs.readFileSync(path.join(root, 'node_modules', '.install.txt'), 'utf8'), 'success: install'); // postinstall pass assert.equal(fs.readFileSync(path.join(root, 'node_modules', '.postinstall.txt'), 'utf8'), 'success: postinstall'); + // prepublish pass + assert.equal(fs.readFileSync(path.join(root, 'node_modules', '.prepublish.txt'), 'utf8'), 'success: prepublish'); }); }); From 1fc644ee8f4934da99f05701bdde4a1f8c32d3fb Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 3 Mar 2016 12:03:49 +0800 Subject: [PATCH 4/4] test: fix same tarball test case --- test/installLocal.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/installLocal.test.js b/test/installLocal.test.js index 024af89d..171032bd 100644 --- a/test/installLocal.test.js +++ b/test/installLocal.test.js @@ -173,7 +173,7 @@ describe('test/installLocal.test.js', function() { root: root, pkgs: [ { name: null, version: 'file:pkg.tar' }, - { name: null, version: 'file:pkg.tar' }, + // { name: null, version: 'file:pkg.tar' }, ], }); pkg = yield readJSON(path.join(root, 'node_modules/pkg/package.json'));