From 497a6bd2b94ec70e8b5a5a7cba0558536d157510 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 1 Aug 2017 00:27:07 +0800 Subject: [PATCH 1/7] feat: add `egg-bin autod --check` command --- README.md | 15 +++++++++++++-- lib/cmd/autod.js | 28 ++++++++++++++++++++++++++++ package.json | 18 +++++++++--------- 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 lib/cmd/autod.js diff --git a/README.md b/README.md index ef79d3db..5182ffab 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,9 @@ Add `egg-bin` to `package.json` scripts: "test": "npm run lint -- --fix && npm run test-local", "cov": "egg-bin cov", "lint": "eslint .", - "ci": "npm run lint && npm run cov" + "pkgfiles": "egg-bin pkgfiles --check", + "autod": "egg-bin autod --check", + "ci": "npm run lint && npm run autod && npm run pkgfiles && npm run cov" } } ``` @@ -167,7 +169,15 @@ $ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov Generate `pkg.files` automatically before npm publish, see [ypkgfiles] for detail ```bash -$ egg-bin pkgfiles +$ egg-bin pkgfiles --check +``` + +### autod + +Generate `pkg.dependencies` and `pkg.devDependencies` automatically, see [autod] for detail + +```bash +$ egg-bin autod --check ``` ## Custom egg-bin for your team @@ -256,3 +266,4 @@ run nsp check at /foo/bar with {} [power-assert]: https://github.com/power-assert-js/power-assert [ypkgfiles]: https://github.com/popomore/ypkgfiles [common-bin]: https://github.com/node-modules/common-bin +[autod]: https://github.com/node-modules/autod diff --git a/lib/cmd/autod.js b/lib/cmd/autod.js new file mode 100644 index 00000000..e675121e --- /dev/null +++ b/lib/cmd/autod.js @@ -0,0 +1,28 @@ +'use strict'; + +const Command = require('../command'); + +class AutodCommand extends Command { + constructor(rawArgv) { + super(rawArgv); + this.usage = 'Usage: egg-bin autod'; + this.options = { + check: { + description: 'dependencies checker', + }, + }; + } + + get description() { + return 'Generate pkg.dependencies and pkg.devDependencies automatically'; + } + + * run({ cwd, argv }) { + const args = []; + if (argv.check) args.push('--check'); + const autodBin = require.resolve('autod/bin/autod.js'); + yield this.helper.forkNode(autodBin, args, { cwd }); + } +} + +module.exports = AutodCommand; diff --git a/package.json b/package.json index 8869cfd1..f1045a66 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "mocha": "bin/mocha.js" }, "dependencies": { + "autod": "^2.9.0", "change-case": "^3.0.1", "co-mocha": "^1.2.0", "common-bin": "^2.4.0", @@ -19,29 +20,28 @@ "mocha": "^3.4.2", "mz": "^2.6.0", "mz-modules": "^1.0.0", - "nyc": "^11.0.2", + "nyc": "^11.1.0", "power-assert": "^1.4.4", + "spawn-wrap": "^1.3.8", "test-exclude": "^4.1.1", "ypkgfiles": "^1.4.0" }, "devDependencies": { - "autod": "^2.8.0", "babel": "^6.3.26", "babel-preset-airbnb": "^1.0.1", "babel-register": "^6.4.3", - "coffee": "^4.0.1", + "coffee": "^4.1.0", "cross-env": "^3.1.3", "egg-ci": "^1.8.0", "enzyme": "^2.0.0", - "eslint": "^3.0.0", - "eslint-config-egg": "^4.2.1", + "eslint": "^4.3.0", + "eslint-config-egg": "^5.0.0", "jsdom": "^8.0.1", "mm": "^2.1.0", - "mz": "^2.6.0", "react": "^0.14.7", "react-addons-test-utils": "^0.14.7", "react-dom": "^0.14.7", - "semver": "^5.3.0" + "semver": "^5.4.1" }, "repository": { "type": "git", @@ -59,8 +59,8 @@ "test-local": "node bin/egg-bin.js test -t 3600000", "cov": "nyc -r lcov -r text-summary npm run test-local", "ci-test-only": "TESTS=test/lib/cmd/cov.test.js npm run test-local", - "ci": "npm run lint && npm run pkgfiles && npm run ci-test-only && npm run cov", - "autod": "autod" + "ci": "npm run lint && npm run pkgfiles && npm run autod && npm run ci-test-only && npm run cov", + "autod": "node bin/egg-bin.js autod --check" }, "engines": { "node": ">= 6.0.0" From e0b9359fa26a050ceb6a829dd704bda17e79dc7a Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 1 Aug 2017 00:34:21 +0800 Subject: [PATCH 2/7] f --- test/fixtures/autod-exists/index.js | 1 + test/fixtures/autod-exists/package.json | 6 ++++++ test/fixtures/autod-missing/index.js | 1 + test/fixtures/autod-missing/package.json | 3 +++ test/lib/cmd/autod.test.js | 25 ++++++++++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 test/fixtures/autod-exists/index.js create mode 100644 test/fixtures/autod-exists/package.json create mode 100644 test/fixtures/autod-missing/index.js create mode 100644 test/fixtures/autod-missing/package.json create mode 100644 test/lib/cmd/autod.test.js diff --git a/test/fixtures/autod-exists/index.js b/test/fixtures/autod-exists/index.js new file mode 100644 index 00000000..5ac1bae3 --- /dev/null +++ b/test/fixtures/autod-exists/index.js @@ -0,0 +1 @@ +require('urllib'); diff --git a/test/fixtures/autod-exists/package.json b/test/fixtures/autod-exists/package.json new file mode 100644 index 00000000..dd48a3bd --- /dev/null +++ b/test/fixtures/autod-exists/package.json @@ -0,0 +1,6 @@ +{ + "name": "autod-exists", + "dependencies": { + "urllib": "*" + } +} diff --git a/test/fixtures/autod-missing/index.js b/test/fixtures/autod-missing/index.js new file mode 100644 index 00000000..5ac1bae3 --- /dev/null +++ b/test/fixtures/autod-missing/index.js @@ -0,0 +1 @@ +require('urllib'); diff --git a/test/fixtures/autod-missing/package.json b/test/fixtures/autod-missing/package.json new file mode 100644 index 00000000..e274ee25 --- /dev/null +++ b/test/fixtures/autod-missing/package.json @@ -0,0 +1,3 @@ +{ + "name": "autod-missing" +} diff --git a/test/lib/cmd/autod.test.js b/test/lib/cmd/autod.test.js new file mode 100644 index 00000000..89b508bc --- /dev/null +++ b/test/lib/cmd/autod.test.js @@ -0,0 +1,25 @@ +'use strict'; + +const path = require('path'); +const coffee = require('coffee'); + +const eggBin = require.resolve('../../../bin/egg-bin.js'); + +describe('test/lib/cmd/autod.test.js', () => { + it('should autod check fail', function* () { + const cwd = path.join(__dirname, '../../fixtures/autod-missing'); + yield coffee.fork(eggBin, [ 'autod', '--check' ], { cwd }) + .debug() + .expect('code', 1) + .expect('stderr', /\[ERROR\] Missing dependencies: \["urllib"\]/) + .end(); + }); + + it('should autod check pass', function* () { + const cwd = path.join(__dirname, '../../fixtures/autod-exists'); + yield coffee.fork(eggBin, [ 'autod', '--check' ], { cwd }) + .debug() + .expect('code', 0) + .end(); + }); +}); From c60e9f0d2852fb77846d6a04576afc6363b85ad4 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 1 Aug 2017 00:41:51 +0800 Subject: [PATCH 3/7] f --- test/fixtures/autod-exists/index.js | 2 ++ test/fixtures/autod-missing/index.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/fixtures/autod-exists/index.js b/test/fixtures/autod-exists/index.js index 5ac1bae3..da20d9d0 100644 --- a/test/fixtures/autod-exists/index.js +++ b/test/fixtures/autod-exists/index.js @@ -1 +1,3 @@ +'use strict'; + require('urllib'); diff --git a/test/fixtures/autod-missing/index.js b/test/fixtures/autod-missing/index.js index 5ac1bae3..da20d9d0 100644 --- a/test/fixtures/autod-missing/index.js +++ b/test/fixtures/autod-missing/index.js @@ -1 +1,3 @@ +'use strict'; + require('urllib'); From a9c532662ebfd7ea6b6aa50a6107e7a2b106ae59 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 1 Aug 2017 00:59:01 +0800 Subject: [PATCH 4/7] chore: remove hotfix spawn-wrap codest --- lib/cmd/cov.js | 38 -------------------------------------- package.json | 3 +-- test/lib/cmd/cov.test.js | 2 +- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index 7efb80e2..06d79207 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -77,15 +77,10 @@ class CovCommand extends Command { env: Object.assign({ NODE_ENV: 'test' }, env), }; - // FIXME: remove hotfix after https://github.com/tapjs/spawn-wrap/pull/57 merged - yield hotfixSpawnWrap(); - // save coverage-xxxx.json to $PWD/coverage const covArgs = this.getCovArgs(context); debug('covArgs: %j', covArgs); yield this.helper.forkNode(nycCli, covArgs, opt); - - yield rollbackSpawnWrap(); } /** @@ -123,36 +118,3 @@ class CovCommand extends Command { } module.exports = CovCommand; - -const src = 'var command = path.basename(options.file, \'.exe\')'; -const target = 'var command = path.basename(options.file).replace(/\.exe$/i, \'\')'; - -function* hotfixSpawnWrap() { - if (process.platform === 'win32') { - yield replaceSpawnWrap(src, target); - } -} - -function* rollbackSpawnWrap() { - if (process.platform === 'win32') { - yield replaceSpawnWrap(target, src); - } -} - -function* replaceSpawnWrap(src, target) { - let spawnWrapPath; - try { - spawnWrapPath = require.resolve('spawn-wrap/index.js'); - } catch (_) { - spawnWrapPath = path.join(__dirname, '../../node_modules/nyc/node_modules/spawn-wrap/index.js'); - } - if (!(yield fs.exists(spawnWrapPath))) return; - - let content = yield fs.readFile(spawnWrapPath, 'utf8'); - // https://github.com/tapjs/spawn-wrap/pull/57 - if (content.includes(src)) { - content = content.replace(src, target); - console.warn('[egg-bin] hotfix spawn-wrap'); - yield fs.writeFile(spawnWrapPath, content); - } -} diff --git a/package.json b/package.json index f1045a66..c266e14d 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "mz-modules": "^1.0.0", "nyc": "^11.1.0", "power-assert": "^1.4.4", - "spawn-wrap": "^1.3.8", "test-exclude": "^4.1.1", "ypkgfiles": "^1.4.0" }, @@ -59,7 +58,7 @@ "test-local": "node bin/egg-bin.js test -t 3600000", "cov": "nyc -r lcov -r text-summary npm run test-local", "ci-test-only": "TESTS=test/lib/cmd/cov.test.js npm run test-local", - "ci": "npm run lint && npm run pkgfiles && npm run autod && npm run ci-test-only && npm run cov", + "ci": "npm run lint && npm run pkgfiles && npm run ci-test-only && npm run cov", "autod": "node bin/egg-bin.js autod --check" }, "engines": { diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 9c727dcb..46173e3d 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -57,7 +57,7 @@ describe('test/lib/cmd/cov.test.js', () => { if (!process.env.NYC_ROOT_ID) { child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); } - child.expect('stderr', /\[egg-bin] hotfix spawn-wrap/); + // child.expect('stderr', /\[egg-bin] hotfix spawn-wrap/); child.expect('code', 0) .end(err => { assert.ifError(err); From d20aa54a4701607fd28ac9489221b01e02cc49a6 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 1 Aug 2017 08:44:17 +0800 Subject: [PATCH 5/7] f --- lib/cmd/cov.js | 1 - package.json | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index 06d79207..c689cdca 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -5,7 +5,6 @@ const debug = require('debug')('egg-bin:cov'); const path = require('path'); const rimraf = require('mz-modules/rimraf'); const testExclude = require('test-exclude'); -const fs = require('mz/fs'); const Command = require('./test'); const EXCLUDES = Symbol('cov#excludes'); diff --git a/package.json b/package.json index c266e14d..b3de95ca 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "egg-utils": "^2.2.0", "globby": "^6.1.0", "intelli-espower-loader": "^1.0.1", - "mocha": "^3.4.2", - "mz": "^2.6.0", + "mocha": "^3.5.0", "mz-modules": "^1.0.0", "nyc": "^11.1.0", "power-assert": "^1.4.4", @@ -37,6 +36,7 @@ "eslint-config-egg": "^5.0.0", "jsdom": "^8.0.1", "mm": "^2.1.0", + "mz": "^2.6.0", "react": "^0.14.7", "react-addons-test-utils": "^0.14.7", "react-dom": "^0.14.7", From d65cc9a4297580a2a52c405fb855cb5f8a01c629 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 1 Aug 2017 09:01:21 +0800 Subject: [PATCH 6/7] f --- test/lib/cmd/cov.test.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 46173e3d..9d83a4c6 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -27,10 +27,6 @@ describe('test/lib/cmd/cov.test.js', () => { child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); } - if (process.platform === 'win32') { - child.expect('stderr', /\[egg-bin] hotfix spawn-wrap/); - } - child.expect('code', 0) .end(err => { assert.ifError(err); @@ -57,7 +53,6 @@ describe('test/lib/cmd/cov.test.js', () => { if (!process.env.NYC_ROOT_ID) { child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); } - // child.expect('stderr', /\[egg-bin] hotfix spawn-wrap/); child.expect('code', 0) .end(err => { assert.ifError(err); From ab28cfa4b92ac7a3d961141dbae3a19f21417d88 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 1 Aug 2017 09:06:52 +0800 Subject: [PATCH 7/7] f --- README.md | 10 +++++----- package.json | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5182ffab..ee9a6bdc 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ Add `egg-bin` to `package.json` scripts: "test": "npm run lint -- --fix && npm run test-local", "cov": "egg-bin cov", "lint": "eslint .", - "pkgfiles": "egg-bin pkgfiles --check", - "autod": "egg-bin autod --check", - "ci": "npm run lint && npm run autod && npm run pkgfiles && npm run cov" + "pkgfiles": "egg-bin pkgfiles", + "autod": "egg-bin autod", + "ci": "npm run lint && npm run autod -- --check && npm run pkgfiles -- --check && npm run cov" } } ``` @@ -169,7 +169,7 @@ $ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov Generate `pkg.files` automatically before npm publish, see [ypkgfiles] for detail ```bash -$ egg-bin pkgfiles --check +$ egg-bin pkgfiles ``` ### autod @@ -177,7 +177,7 @@ $ egg-bin pkgfiles --check Generate `pkg.dependencies` and `pkg.devDependencies` automatically, see [autod] for detail ```bash -$ egg-bin autod --check +$ egg-bin autod ``` ## Custom egg-bin for your team diff --git a/package.json b/package.json index b3de95ca..a1ff634d 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,13 @@ "author": "fengmk2 (https://fengmk2.com)", "scripts": { "lint": "eslint .", - "pkgfiles": "node bin/egg-bin.js pkgfiles --check", + "pkgfiles": "node bin/egg-bin.js pkgfiles", "test": "npm run lint -- --fix && npm run test-local", "test-local": "node bin/egg-bin.js test -t 3600000", "cov": "nyc -r lcov -r text-summary npm run test-local", "ci-test-only": "TESTS=test/lib/cmd/cov.test.js npm run test-local", - "ci": "npm run lint && npm run pkgfiles && npm run ci-test-only && npm run cov", - "autod": "node bin/egg-bin.js autod --check" + "ci": "npm run lint && npm run pkgfiles -- --check && npm run autod -- --check && npm run ci-test-only && npm run cov", + "autod": "node bin/egg-bin.js autod" }, "engines": { "node": ">= 6.0.0"