-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add check engines script to CI (#2922)
- Loading branch information
1 parent
a4da8d9
commit 61ce4e0
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { join } = require('path') | ||
const semver = require('semver') | ||
const Arborist = require('@npmcli/arborist') | ||
|
||
const run = async (path, useEngines) => { | ||
const pkgPath = join(path, 'package.json') | ||
const pkg = require(pkgPath) | ||
|
||
const engines = useEngines || pkg.engines.node | ||
|
||
const arb = new Arborist({ path }) | ||
const tree = await arb.loadActual({ forceActual: true }) | ||
const deps = await tree.querySelectorAll(`#${pkg.name} > .prod:attr(engines, [node])`) | ||
|
||
const invalid = [] | ||
for (const dep of deps) { | ||
const depEngines = dep.target.package.engines.node | ||
if (!semver.subset(engines, depEngines)) { | ||
invalid.push({ | ||
name: `${dep.name}@${dep.version}`, | ||
location: dep.location, | ||
engines: depEngines | ||
}) | ||
} | ||
} | ||
|
||
if (invalid.length) { | ||
const msg = 'The following production dependencies are not compatible with ' + | ||
`\`engines.node: ${engines}\` found in \`${pkgPath}\`:\n` + invalid.map((dep) => [ | ||
`${dep.name}:`, | ||
` engines.node: ${dep.engines}`, | ||
` location: ${dep.location}` | ||
].join('\n')).join('\n') | ||
throw new Error(msg) | ||
} | ||
} | ||
|
||
run(process.cwd(), ...process.argv.slice(2)).then(() => console.log('Success')).catch((err) => { | ||
console.error(err) | ||
process.exitCode = 1 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters