Skip to content

Commit 7fa64b8

Browse files
committed
feat(watch): use concurrently for the watch task
Fixes #11
1 parent 7f9492b commit 7fa64b8

File tree

4 files changed

+186
-40
lines changed

4 files changed

+186
-40
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ yarn watch
4949

5050
which will build and watch the entire project for changes (to both the library source files and test source files). As you develop, you can add tests for new functionality – which will initially fail – before developing the new functionality. Each time you save, any changes will be rebuilt and retested.
5151

52-
Typescript builds on the left, tests run on the right:
53-
5452
<p align="center">
55-
<img alt="Typescript and AVA watch task" src="https://cloud.githubusercontent.com/assets/904007/22908704/f4a83b20-f21d-11e6-8006-da6a851fb057.png">
53+
<img alt="Typescript and AVA watch task" src="https://cloud.githubusercontent.com/assets/904007/23443884/c625d562-fdff-11e6-8f26-77bf75add240.png">
5654
</p>
5755

5856
Since only changed files are rebuilt and retested, this workflow remains fast even for large projects.
@@ -154,6 +152,10 @@ While both the browser and the Node.js versions of the library are tested, this
154152

155153
Note: test coverage is only checked against the Node.js implementation. This is much simpler, and works well for libraries where the node and browser implementations have different dependencies and only minor adapter code. With only a few lines of differences (e.g. `src/adapters/crypto.browser.ts`), including those few lines in test coverage analysis usually isn't necessary.
156154

155+
### Building browser dependencies
156+
157+
This starter demonstrates importing and using a CommonJS module ([`hash.js`](https://github.com/indutny/hash.js)) for it's `hash256` method. See the `build:browser-deps` [package script](./package.json) and [rollup.config.js](./config/exports/rollup.config.js) for more details. Of course, your project likely does not need this dependency, so it can be removed. If your library doesn't need to bundle external dependencies for the browser, several other devDependencies can also be removed (`browserify`, `rollup-plugin-alias`, `rollup-plugin-commonjs`, `rollup-plugin-node-resolve`, etc).
158+
157159
### Dependency on `tslib`
158160

159161
By default, this project requires [tslib](https://github.com/Microsoft/tslib) as a dependency. This is the recommended way to use Typescript's es6 &amp; es7 transpiling for sizable projects, but you can remove this dependency by removing the `importHelpers` compiler option in `tsconfig.json`. Depending on your usage, this may increase the size of your library significantly, as the Typescript compiler will inject it's helper functions directly into every file which uses them. (See also: [`noEmitHelpers` &rarr;](https://www.typescriptlang.org/docs/handbook/compiler-options.html))

config/exports/build-tests.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ const makeTransform = (filePath, buildPath) => {
2727

2828
// copy, then watch for changes to the tests
2929
const testsFromRoot = 'build/main/**/*.spec.js';
30-
const task = process.argv[2] === '-w' ? cpx.watch : cpx.copy;
30+
const watchMode = process.argv.indexOf('-w') !== -1 ? true : false;
31+
const browserTests = process.argv.indexOf('--no-browser') !== -1 ? true : false;
32+
const task = watchMode ? cpx.watch : cpx.copy;
3133

3234
task(testsFromRoot, 'test/main', {
3335
transform: (filePath) => makeTransform(filePath, pkg.main)
34-
})
35-
task(testsFromRoot, 'test/browser', {
36-
transform: (filePath) => makeTransform(filePath, pkg.browser.replace('.js', '.cjs.js'))
37-
})
36+
});
37+
if (!browserTests) {
38+
task(testsFromRoot, 'test/browser', {
39+
transform: (filePath) => makeTransform(filePath, pkg.browser.replace('.js', '.cjs.js'))
40+
});
41+
}

package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
"license": "MIT",
1212
"scripts": {
1313
"info": "npm-scripts-info",
14-
"build": "trash build && yarn build:main && yarn build:module && yarn build:browser-deps && yarn build:browser && yarn build:browser-cjs",
14+
"build": "trash build && yarn build:main && yarn build:module && yarn build:browser-deps && yarn build:browser && yarn build:browser-cjs && yarn build:resolve-sourcemaps",
1515
"build:main": "tsc -p tsconfig.json",
1616
"build:module": "tsc -p config/exports/tsconfig.module.json",
1717
"build:browser-deps": "mkdirp build/temp && browserify node_modules/hash.js/lib/hash.js --standalone hash -o build/temp/hash.js",
18-
"build:browser": "rollup -c config/exports/rollup.config.js -f es -o build/browser/index.js && sorcery -i build/browser/index.js",
19-
"build:browser-cjs": "rollup -c config/exports/rollup.config.js -f cjs -o build/browser/index.cjs.js && sorcery -i build/browser/index.cjs.js",
20-
"build:tests": "node config/exports/build-tests.js",
18+
"build:browser": "rollup -c config/exports/rollup.config.js -f es -o build/browser/index.js",
19+
"build:browser-cjs": "rollup -c config/exports/rollup.config.js -f cjs -o build/browser/index.cjs.js",
20+
"build:resolve-sourcemaps": "sorcery -i build/browser/index.js && sorcery -i build/browser/index.cjs.js",
21+
"build:tests": "trash test && node config/exports/build-tests.js",
2122
"lint": "tslint src/**/*.ts",
2223
"unit": "yarn build && yarn build:tests && nyc ava",
2324
"check-coverage": "nyc check-coverage --lines 100 --functions 100 --branches 100",
24-
"test": "yarn lint && yarn unit && yarn check-coverage && ava",
25-
"watch": "yarn build && concurrently -r 'yarn build:main -- -w' 'yarn build:module -- -w' 'yarn build:browser -- -w' 'yarn build:browser-cjs -- -w' 'yarn build:tests -- -w' 'ava --watch --verbose'",
25+
"test": "yarn lint && yarn unit && yarn check-coverage",
26+
"watch": "yarn build && yarn build:tests -- --no-browser && concurrently -r --kill-others 'npm run --silent build:main -- -w' 'npm run --silent build:tests -- -w --no-browser' 'sleepms 2000 && ava --watch'",
2627
"cov": "yarn unit && yarn html-coverage && opn coverage/index.html",
2728
"html-coverage": "nyc report --reporter=html",
2829
"send-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
29-
"docs": "typedoc src/index.ts --excludePrivate --mode file --theme minimal --out build/docs && opn build/docs/index.html",
30+
"docs": "typedoc src/index.ts --excludePrivate --exclude src/adapters/*.ts --mode file --theme minimal --out build/docs && opn build/docs/index.html",
3031
"docs:json": "typedoc --mode file --json build/docs/typedoc.json src/index.ts",
3132
"release": "standard-version"
3233
},
@@ -66,13 +67,14 @@
6667
"rollup-plugin-commonjs": "^7.0.0",
6768
"rollup-plugin-node-resolve": "^2.0.0",
6869
"rollup-watch": "^3.2.2",
70+
"sleep-ms": "^2.0.1",
6971
"sorcery": "^0.10.0",
7072
"standard-version": "^4.0.0",
7173
"trash-cli": "^1.4.0",
72-
"tslint": "^4.0.2",
74+
"tslint": "^4.5.1",
7375
"tslint-config-standard": "^4.0.0",
74-
"typedoc": "^0.5.5",
75-
"typescript": "^2.2.0"
76+
"typedoc": "^0.5.7",
77+
"typescript": "^2.2.1"
7678
},
7779
"keywords": [
7880
"async",
@@ -102,6 +104,6 @@
102104
]
103105
},
104106
"dependencies": {
105-
"tslib": "^1.5.0"
107+
"tslib": "^1.6.0"
106108
}
107109
}

0 commit comments

Comments
 (0)