Skip to content

Commit 2e2128f

Browse files
committed
Add check for engines
1 parent ccdbfe5 commit 2e2128f

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,8 @@ jobs:
8282
paths:
8383
- node_modules
8484
- run:
85-
name: Test
85+
name: Lint
8686
command: npm run lint
87+
- run:
88+
name: Check
89+
command: npm run valid

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"update": "node ./tools/update.js",
2020
"docs:watch": "vuepress dev docs",
2121
"predocs:build": "npm run update",
22-
"docs:build": "vuepress build docs"
22+
"docs:build": "vuepress build docs",
23+
"valid": "node tools/valid-dependencies-engines"
2324
},
2425
"files": [
2526
"lib"

tools/valid-dependencies-engines.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @author Yosuke Ota
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
const cp = require('child_process')
8+
const semver = require('semver')
9+
const pkg = require('../package.json')
10+
const nodeVer = pkg.engines.node
11+
const deps = { ...pkg.dependencies, ...pkg.peerDependencies }
12+
13+
for (const [name, ver] of Object.entries(deps)) {
14+
// eslint-disable-next-line no-console
15+
// console.log(`call npm view "${name}@${ver}" --json`)
16+
const json = cp.execSync(`npm view "${name}@${ver}" --json`, {
17+
maxBuffer: 1024 * 1024 * 100
18+
})
19+
const meta = JSON.parse(json)
20+
const v = meta.engines && meta.engines.node
21+
if (v && !semver.subset(nodeVer, v)) {
22+
// eslint-disable-next-line no-console
23+
console.error(
24+
`"${name}@${ver}" is not compatible with "node@${nodeVer}".\nAllowed is:${v}`
25+
)
26+
process.exit(1)
27+
}
28+
}

0 commit comments

Comments
 (0)