Skip to content

Commit

Permalink
Add check for engines
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Aug 3, 2021
1 parent ccdbfe5 commit 2e2128f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Expand Up @@ -82,5 +82,8 @@ jobs:
paths:
- node_modules
- run:
name: Test
name: Lint
command: npm run lint
- run:
name: Check
command: npm run valid
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -19,7 +19,8 @@
"update": "node ./tools/update.js",
"docs:watch": "vuepress dev docs",
"predocs:build": "npm run update",
"docs:build": "vuepress build docs"
"docs:build": "vuepress build docs",
"valid": "node tools/valid-dependencies-engines"
},
"files": [
"lib"
Expand Down
28 changes: 28 additions & 0 deletions tools/valid-dependencies-engines.js
@@ -0,0 +1,28 @@
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
'use strict'

const cp = require('child_process')
const semver = require('semver')
const pkg = require('../package.json')
const nodeVer = pkg.engines.node
const deps = { ...pkg.dependencies, ...pkg.peerDependencies }

for (const [name, ver] of Object.entries(deps)) {
// eslint-disable-next-line no-console
// console.log(`call npm view "${name}@${ver}" --json`)
const json = cp.execSync(`npm view "${name}@${ver}" --json`, {
maxBuffer: 1024 * 1024 * 100
})
const meta = JSON.parse(json)
const v = meta.engines && meta.engines.node
if (v && !semver.subset(nodeVer, v)) {
// eslint-disable-next-line no-console
console.error(
`"${name}@${ver}" is not compatible with "node@${nodeVer}".\nAllowed is:${v}`
)
process.exit(1)
}
}

0 comments on commit 2e2128f

Please sign in to comment.