-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace --engines-strict check with arborist query
Closes #149
- Loading branch information
1 parent
26495f3
commit 49a0581
Showing
10 changed files
with
139 additions
and
421 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const semver = require('semver') | ||
const { relative, join } = require('path') | ||
const Arborist = require('@npmcli/arborist') | ||
|
||
const run = async ({ root, path, pkg, config: { omitEngines = [] } }) => { | ||
const pkgPath = join(relative(root, path), 'package.json') | ||
const arb = new Arborist({ path }) | ||
const tree = await arb.loadActual({ forceActual: true }) | ||
|
||
const engines = pkg.engines.node | ||
const deps = await tree.querySelectorAll(`#${pkg.name} > .prod:attr(engines, [node])`) | ||
|
||
const invalid = [] | ||
for (const dep of deps) { | ||
if (omitEngines.includes(dep.name)) { | ||
continue | ||
} | ||
|
||
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 title = `The following production dependencies are not compatible with ` + | ||
`\`engines.node: ${engines}\` found in \`${pkgPath}\`:` | ||
return { | ||
title, | ||
body: invalid.map((dep) => [ | ||
`${dep.name}:`, | ||
` engines.node: ${dep.engines}`, | ||
` location: ${dep.location}`, | ||
].join('\n')).join('\n'), | ||
solution: 'Remove them or move them to devDependencies.', | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
run, | ||
when: ({ pkg, config: c }) => c.applyModule && pkg.engines?.node, | ||
name: 'check-engines', | ||
} |
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
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
Oops, something went wrong.