Skip to content

Commit acba478

Browse files
committed
Add gulp pack
1 parent 48ef25f commit acba478

File tree

20 files changed

+283
-128
lines changed

20 files changed

+283
-128
lines changed

.nycrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"include": ["build"],
3-
"all": true,
2+
"include": ["dist", "{index,register}.js"],
43
"reporter": ["lcov", "text"]
54
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ os:
66
- osx
77
- linux
88
dist: xenial
9-
script: npm run ci-test
9+
script: npm test
1010
# When pushing a tagged commit, Travis adds two builds: one with the tag, one
1111
# without. We only want to build the one with the tag, because it's the one
1212
# that runs the deployment stage

gulp/exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const addStdio = function({ opts }) {
3131
return { ...opts, stdio: 'inherit' }
3232
}
3333

34-
const STDIO_OPTIONS = ['stdio', 'stdin', 'stdout', 'stderr']
34+
const STDIO_OPTIONS = ['stdio', 'stdin', 'stdout', 'stderr', 'input']
3535

3636
// Retrieve error message to print
3737
const getErrorMessage = function({

gulp/tasks/build.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ const { getWatchTask } = require('../utils')
66
const { BUILD_SRC, BUILD_DIST } = require('../files')
77
const gulpExeca = require('../exec')
88

9-
const { pack } = require('./pack')
10-
119
const babel = () =>
1210
gulpExeca(
1311
`babel ${BUILD_SRC} --out-dir ${BUILD_DIST} --copy-files --delete-dir-on-start --source-maps --no-comments --minified --retain-lines`,
1412
)
1513

16-
const build = series(babel, pack)
14+
const build = series(babel)
1715

1816
// eslint-disable-next-line fp/no-mutation
1917
build.description = 'Build source files'

gulp/tasks/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ module.exports = {
66
...require('./check'),
77
...require('./unit'),
88
...require('./build'),
9-
...require('./pack'),
109
...require('./emit'),
1110
}

gulp/tasks/pack.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

gulp/tasks/unit.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,50 @@ const { readFile } = require('fs')
44
const { promisify } = require('util')
55

66
const { load: loadYaml } = require('js-yaml')
7+
const isCi = require('is-ci')
78

8-
const { getWatchTask } = require('../utils')
9+
const { name } = require('../../package.json')
10+
const { getWatchTask, pack } = require('../utils')
911
const gulpExeca = require('../exec')
1012

1113
const TRAVIS_CONFIG = `${__dirname}/../../.travis.yml`
1214

13-
const unit = () => gulpExeca('ava')
15+
const unit = async function() {
16+
// In CI, we use `pack`, but not locally since it is slow.
17+
// Also, in CI we do test coverage and send it to Coveralls.
18+
if (!isCi) {
19+
return gulpExeca('ava')
20+
}
21+
22+
// When using `pack`, tested files will be inside `node_modules`
23+
// By default `nyc` ignore those, so we need to add them to `--include``
24+
// Even after this, `node_modules` are still ignored by `nyc` unless using
25+
// a negated `--exclude`
26+
await pack(`nyc --include ${NESTED_DIR} --exclude !${NESTED_DIR} ava`)
27+
28+
await sendToCoveralls()
29+
}
1430

1531
// eslint-disable-next-line fp/no-mutation
1632
unit.description = 'Run unit tests'
1733

34+
const sendToCoveralls = async function() {
35+
// We strip `node_modules/PACKAGE/` from test coverage reports so it looks
36+
// like source files were in the same directory (not inside `node_modules`).
37+
const covMap = await promisify(readFile)(COVMAP_PATH, { encoding: 'utf-8' })
38+
const covMapA = covMap.replace(NESTED_DIR_REGEXP, '')
39+
40+
await gulpExeca('coveralls', { input: covMapA })
41+
}
42+
43+
const NESTED_DIR = `node_modules/${name}`
44+
// The RegExp needs to account for Windows having different separators.
45+
const NESTED_DIR_REGEXP = new RegExp(
46+
`node_modules(\\/|\\\\)${name}(\\/|\\\\)`,
47+
'gu',
48+
)
49+
const COVMAP_PATH = './coverage/lcov.info'
50+
1851
// We have to use this to debug Ava test files with Chrome devtools
1952
const unitwatch = getWatchTask({ UNIT: unit }, unit)
2053

gulp/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
module.exports = {
44
...require('./watch'),
5+
...require('./pack'),
56
}

gulp/utils/pack/constants.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ENV_VAR": {
3+
"NAME": "GULP_PACK",
4+
"VALUE": "1"
5+
}
6+
}

gulp/utils/pack/get.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict'
2+
3+
const { env } = require('process')
4+
5+
const { getPackageRootSync, getManifest } = require('./root')
6+
const { ENV_VAR } = require('./constants')
7+
8+
// Retrieve the package root directory.
9+
// When run with `pack`, the package will first be packed with `npm pack` so
10+
// that it is required the same way as on the npm repository.
11+
// This help detecting problems in the package due to:
12+
// - missing files in the package (`.npmignore`, `files` field)
13+
// - wrong entry point (`main` or `browser` field)
14+
// - requiring `devDependencies` in production code
15+
const getPackage = function() {
16+
const packageRoot = getPackageRootSync()
17+
18+
if (env[ENV_VAR.NAME] !== ENV_VAR.VALUE) {
19+
return packageRoot
20+
}
21+
22+
const { name } = getManifest({ packageRoot })
23+
return name
24+
}
25+
26+
module.exports = {
27+
getPackage,
28+
}

0 commit comments

Comments
 (0)