Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 37fbbdd

Browse filesBrowse files
committed
build: install nyc on demand
1 parent 0420029 commit 37fbbdd
Copy full SHA for 37fbbdd

File tree

Expand file treeCollapse file tree

4 files changed

+103
-10
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+103
-10
lines changed

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ before_install:
5656
- "npm config set shrinkwrap false"
5757

5858
# Setup Node.js version-specific dependencies
59-
- "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev nyc"
60-
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev nyc"
59+
- "node tool/install-nyc.js --nyc-optional"
6160
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev eslint"
6261

6362
# Update Node.js modules
@@ -78,10 +77,9 @@ before_script:
7877
- "docker exec mysql mysql -e 'select version()'"
7978

8079
script:
81-
# Run test script, depending on nyc install
82-
- "test ! -z $(npm -ps ls nyc) || npm test"
83-
- "test -z $(npm -ps ls nyc) || npm run-script test-ci"
84-
- "test -z $(npm -ps ls eslint) || npm run-script lint"
80+
# Run test script
81+
- "npm run-script test-ci"
82+
- "test -z $(npm -ps ls eslint) || npm run-script lint"
8583

8684
after_script:
8785
- "test -d .nyc_output && npm install coveralls@2 && nyc report --reporter=text-lcov | coveralls"

‎appveyor.yml

Copy file name to clipboardExpand all lines: appveyor.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ install:
3232
catch { Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) }
3333
- npm config set shrinkwrap false
3434
- if "%nodejs_version%" equ "0.8" npm config set strict-ssl false
35-
- npm rm --silent --save-dev eslint nyc
35+
- npm rm --silent --save-dev eslint
3636
- if exist node_modules npm prune
3737
- if exist node_modules npm rebuild
3838
- npm install

‎package.json

Copy file name to clipboardExpand all lines: package.json
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"devDependencies": {
2222
"after": "0.8.2",
2323
"eslint": "4.19.1",
24-
"nyc": "10.3.2",
2524
"seedrandom": "2.4.4",
2625
"timezone-mock": "0.0.7",
2726
"urun": "0.0.8",
@@ -40,8 +39,8 @@
4039
"scripts": {
4140
"lint": "eslint .",
4241
"test": "node test/run.js",
43-
"test-ci": "nyc --reporter=text npm test",
44-
"test-cov": "nyc --reporter=html --reporter=text npm test",
42+
"test-ci": "node tool/install-nyc.js --nyc-optional --reporter=text -- npm test",
43+
"test-cov": "node tool/install-nyc.js --reporter=html --reporter=text -- npm test",
4544
"version": "node tool/version-changes.js && git add Changes.md"
4645
}
4746
}

‎tool/install-nyc.js

Copy file name to clipboard
+96Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
var path = require('path');
2+
var spawn = require('child_process').spawn;
3+
4+
process.nextTick(run);
5+
6+
function installNpmModule(name, version, callback) {
7+
if (getPackageVersion(name) === version) {
8+
callback();
9+
return;
10+
}
11+
12+
var spec = name + '@' + version;
13+
var args = ['install', '--silent', '--no-save', spec];
14+
var child = spawn('npm', args, {
15+
cwd : path.join(__dirname, '..'),
16+
shell : true
17+
});
18+
19+
child.stderr.resume();
20+
child.stdout.resume();
21+
22+
child.on('exit', function (code) {
23+
var err = null;
24+
25+
if (code !== 0) {
26+
err = new Error('npm install ' + spec + ' failed with exit code ' + code);
27+
}
28+
29+
callback(err);
30+
});
31+
}
32+
33+
function getNycVersion() {
34+
var nodeVersion = process.version.replace(/^v/, '').split('.')
35+
.map(function (s) { return Number(s); });
36+
37+
if (nodeVersion[0] === 0 && nodeVersion[1] < 10) {
38+
return undefined;
39+
} else if (nodeVersion[0] < 4) {
40+
return '10.3.2';
41+
} else if (nodeVersion[0] < 6) {
42+
return '11.9.0';
43+
} else {
44+
return '13.1.0';
45+
}
46+
}
47+
48+
function getPackageVersion(name) {
49+
try {
50+
return require(name + '/package').version;
51+
} catch (e) {
52+
return undefined;
53+
}
54+
}
55+
56+
function run() {
57+
var args = process.argv.slice(2);
58+
var cmd = null;
59+
var divider = args.indexOf('--');
60+
var version = getNycVersion();
61+
62+
if (divider !== -1) {
63+
cmd = args.slice(divider + 1);
64+
args = args.slice(0, divider);
65+
}
66+
67+
if (!version && args.indexOf('--nyc-optional') === -1) {
68+
console.error('nyc does not support current Node.js version');
69+
process.exit(1);
70+
} else if (version) {
71+
installNpmModule('nyc', version, function (err) {
72+
if (err) {
73+
console.error(err.message);
74+
process.exit(1);
75+
} else if (cmd) {
76+
runCmd('nyc', args.concat(cmd));
77+
}
78+
});
79+
} else if (cmd) {
80+
runCmd(cmd[0], cmd.slice(1));
81+
}
82+
}
83+
84+
function runCmd(cmd, args) {
85+
var child = spawn(cmd, args, {
86+
cwd : path.join(__dirname, '..'),
87+
shell : true
88+
});
89+
90+
child.stderr.pipe(process.stderr, {end: false});
91+
child.stdout.pipe(process.stdout, {end: false});
92+
93+
child.on('exit', function (code) {
94+
process.exit(code);
95+
});
96+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.