Skip to content

Commit 9c090d5

Browse files
committed
chore: script to bump supported node versions
No change to node support, this just adds a script. This adds a script to check that we correctly configure all supported node versions, since we need to update quite a few spots (README.md, package.json, travis, appveyor). Issue shelljs/shelljs#873 Test: manual
1 parent 062e50a commit 9c090d5

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ os:
1414
- osx
1515
script:
1616
- npm test
17+
- npm run check-node-support
1718
after_success:
1819
- npm run codecov -- -f coverage/lcov.info
1920

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
commands, providing an easy solution for simple Unix-like, cross-platform
1111
commands in npm package scripts.
1212

13+
`shx` is proudly tested on every node release since <!-- start minVersion -->`v4`<!-- stop minVersion -->!
14+
1315
## Difference Between ShellJS and shx
1416

1517
- **ShellJS:** Good for writing long scripts, all in JS, running via NodeJS (e.g. `node myScript.js`).

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lib"
1010
],
1111
"scripts": {
12+
"check-node-support": "node scripts/check-node-support",
1213
"prebuild": "rimraf lib",
1314
"build": "babel src -d lib",
1415
"build:watch": "npm run build -- -w",
@@ -59,6 +60,7 @@
5960
"eslint": "^2.10.1",
6061
"eslint-config-airbnb-base": "^3.0.1",
6162
"eslint-plugin-import": "^1.8.0",
63+
"js-yaml": "^3.12.0",
6264
"mocha": "^5.2.0",
6365
"nyc": "^11.0.0",
6466
"rimraf": "^2.5.2",

scripts/check-node-support.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env node
2+
3+
var assert = require('assert');
4+
var path = require('path');
5+
6+
var yaml = require('js-yaml');
7+
8+
var shell = require('shelljs');
9+
10+
// This is the authoritative list of supported node versions.
11+
var MIN_NODE_VERSION = 4;
12+
var MAX_NODE_VERSION = 10;
13+
14+
function checkReadme(minNodeVersion) {
15+
var start = '<!-- start minVersion -->';
16+
var stop = '<!-- stop minVersion -->';
17+
var formattedMinVersion = '`v' + minNodeVersion + '`';
18+
var expectedReadmeRegex = new RegExp(
19+
start + '\\s*' + formattedMinVersion + '\\s*' + stop, '');
20+
var readme = path.join(__dirname, '..', 'README.md');
21+
var match = shell.grep(expectedReadmeRegex, readme);
22+
if (!match.toString()) {
23+
var msg = 'Update README to specify the min supported version. Look for "'
24+
+ start + '"';
25+
throw new Error(msg);
26+
}
27+
}
28+
29+
function checkEngines(minNodeVersion, package) {
30+
var expectedEnginesNode = '>=' + minNodeVersion;
31+
if (package.engines.node !== expectedEnginesNode) {
32+
var msg = 'Update package.json to fix the "engines" attribute';
33+
throw new Error(msg);
34+
}
35+
}
36+
37+
function assertDeepEquals(arr1, arr2, msg) {
38+
try {
39+
assert.deepStrictEqual(arr1, arr2);
40+
} catch (e) {
41+
throw new Error(msg + '\n' + e);
42+
}
43+
}
44+
45+
function range(start, stop) {
46+
var ret = [];
47+
for (var i = start; i <= stop; i++) {
48+
ret.push(i);
49+
}
50+
return ret;
51+
}
52+
53+
function checkTravis(minNodeVersion, maxNodeVersion, travisYaml) {
54+
var expectedTravisVersions = range(minNodeVersion, maxNodeVersion);
55+
var msg = 'Check Travis node_js versions';
56+
assertDeepEquals(travisYaml.node_js, expectedTravisVersions, msg);
57+
}
58+
59+
function checkAppveyor(minNodeVersion, maxNodeVersion, appveyorYaml) {
60+
var expectedAppveyorVersions = range(minNodeVersion, maxNodeVersion)
61+
.map(function (num) {
62+
return { nodejs_version: num.toString() };
63+
})
64+
.reverse(); // Arbitrarily, we store appveyor in reverse order.
65+
var msg = 'Check Appveyor environment.matrix versions';
66+
assertDeepEquals(appveyorYaml.environment.matrix, expectedAppveyorVersions,
67+
msg);
68+
}
69+
70+
try {
71+
checkReadme(MIN_NODE_VERSION);
72+
73+
var package = require('../package.json');
74+
checkEngines(MIN_NODE_VERSION, package);
75+
76+
var travisFileName = path.join(__dirname, '..', '.travis.yml');
77+
var travisYaml = yaml.safeLoad(shell.cat(travisFileName));
78+
checkTravis(MIN_NODE_VERSION, MAX_NODE_VERSION, travisYaml);
79+
80+
var appveyorFileName = path.join(__dirname, '..', 'appveyor.yml');
81+
var appveyorYaml = yaml.safeLoad(shell.cat(appveyorFileName));
82+
checkAppveyor(MIN_NODE_VERSION, MAX_NODE_VERSION, appveyorYaml);
83+
} catch (e) {
84+
console.error('Please check the files which declare our Node version');
85+
console.error('support, as something is out-of-sync. This script failed');
86+
console.error('specificaly because:');
87+
throw e;
88+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy