Skip to content

Commit 21a7249

Browse files
authored
chore: add check engines script to CI (#2922)
1 parent 707927c commit 21a7249

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

.github/scripts/check-engines.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { join } = require('path')
2+
const semver = require('semver')
3+
const Arborist = require('@npmcli/arborist')
4+
5+
const run = async (path, useEngines) => {
6+
const pkgPath = join(path, 'package.json')
7+
const pkg = require(pkgPath)
8+
9+
const engines = useEngines || pkg.engines.node
10+
11+
const arb = new Arborist({ path })
12+
const tree = await arb.loadActual({ forceActual: true })
13+
const deps = await tree.querySelectorAll(`#${pkg.name} > .prod:attr(engines, [node])`)
14+
15+
const invalid = []
16+
for (const dep of deps) {
17+
const depEngines = dep.target.package.engines.node
18+
if (!semver.subset(engines, depEngines)) {
19+
invalid.push({
20+
name: `${dep.name}@${dep.version}`,
21+
location: dep.location,
22+
engines: depEngines
23+
})
24+
}
25+
}
26+
27+
if (invalid.length) {
28+
const msg = 'The following production dependencies are not compatible with ' +
29+
`\`engines.node: ${engines}\` found in \`${pkgPath}\`:\n` + invalid.map((dep) => [
30+
`${dep.name}:`,
31+
` engines.node: ${dep.engines}`,
32+
` location: ${dep.location}`
33+
].join('\n')).join('\n')
34+
throw new Error(msg)
35+
}
36+
}
37+
38+
run(process.cwd(), ...process.argv.slice(2)).then(() => console.log('Success')).catch((err) => {
39+
console.error(err)
40+
process.exitCode = 1
41+
})

.github/workflows/tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ jobs:
1818
- uses: actions/checkout@v4
1919
- run: pip install --user ruff
2020
- run: ruff --output-format=github --select="E,F,PLC,PLE,UP,W,YTT" --ignore="E721,PLC1901,S101,UP031" --target-version=py38 .
21+
Engines:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout Repository
25+
uses: actions/checkout@v3
26+
- name: Use Node.js 20.x
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 20.x
30+
- name: Install Dependencies
31+
run: |
32+
npm install --no-progress
33+
- name: Check Engines
34+
run: |
35+
# TODO: move this to its own action
36+
npm install @npmcli/arborist@7 semver@7 --no-save
37+
node .github/scripts/check-engines.js
2138
Tests:
2239
needs: Lint_Python # Lint_Python takes ~5 seconds, so wait for it to pass before running the full matrix of tests.
2340
strategy:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"standard": "^17.0.0"
4545
},
4646
"scripts": {
47-
"lint": "standard */*.js test/**/*.js",
47+
"lint": "standard \"*/*.js\" \"test/**/*.js\" \".github/**/*.js\"",
4848
"test": "npm run lint && mocha --timeout 15000 --reporter=test/reporter.js test/test-download.js test/test-*"
4949
}
5050
}

0 commit comments

Comments
 (0)