-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathsemver-check.js
32 lines (23 loc) · 1.06 KB
/
semver-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const supportedVersions = process.versions.node;
function checkEngines(modulePath) {
const packageJsonPath = path.join(modulePath, 'package.json');
if (!fs.existsSync(packageJsonPath)) return;
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
const engines = packageJson.engines;
if (engines && engines.node) {
const minVersion = semver.minVersion(engines.node);
if (semver.gt(minVersion, supportedVersions)) {
console.log(`${packageJson.name}@${packageJson.version} requires ${engines.node}`);
process.exit(1);
}
}
}
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json')));
const allDependencies = Object.keys(packageJson.dependencies || {}).concat(Object.keys(packageJson.optionalDependencies || {}));
for (const dependency of allDependencies) {
const modulePath = path.join(__dirname, '..', 'node_modules', dependency);
checkEngines(modulePath);
}