Skip to content

Commit cff38a3

Browse files
committed
Added CI step to check semver compatibility
- right now our way to check semver compatibility is to run the tests on every version - this is really inefficient as it results in a lot of CI jobs that we don't need - this should run a CI job that ensures the minimum version we accept is Node 10.12.0
1 parent 93ed997 commit cff38a3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ jobs:
7070
- name: Install dependencies
7171
run: yarn install --ignore-scripts
7272

73+
- name: Check Node compatibility
74+
run: node tools/semver-check.js
75+
7376
- name: Add env vars
7477
shell: bash
7578
run: |

tools/semver-check.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const semver = require('semver');
4+
5+
const supportedVersions = '10.12.0';
6+
7+
function checkEngines(modulePath) {
8+
const packageJsonPath = path.join(modulePath, 'package.json');
9+
10+
if (!fs.existsSync(packageJsonPath)) return;
11+
12+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
13+
const engines = packageJson.engines;
14+
15+
if (engines && engines.node) {
16+
const minVersion = semver.minVersion(engines.node);
17+
18+
if (semver.gt(minVersion, supportedVersions)) {
19+
console.log(`${packageJson.name}@${packageJson.version} requires ${engines.node}`);
20+
process.exit(1);
21+
}
22+
}
23+
}
24+
25+
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json')));
26+
27+
const allDependencies = Object.keys(packageJson.dependencies || {}).concat(Object.keys(packageJson.optionalDependencies || {}));
28+
29+
for (const dependency of allDependencies) {
30+
const modulePath = path.join(__dirname, '..', 'node_modules', dependency);
31+
checkEngines(modulePath);
32+
}
33+

0 commit comments

Comments
 (0)