Skip to content

fix(arborist): don't checkEngine/checkPlatform for extraneous deps #8310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
async #checkEngineAndPlatform () {
const { engineStrict, npmVersion, nodeVersion } = this.options
for (const node of this.idealTree.inventory.values()) {
if (!node.optional) {
if (!node.optional && !node.extraneous) {
try {
// if devEngines is present in the root node we ignore the engines check
if (!(node.isRoot && node.package.devEngines)) {
Expand Down
64 changes: 64 additions & 0 deletions workspaces/arborist/test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -4091,3 +4091,67 @@ t.test('should take devEngines in account', async t => {
const tree = await buildIdeal(path)
t.matchSnapshot(String(tree.meta))
})

t.test(
'extraneous dependency not buildable on current platform does not throw',
async (t) => {
const isLinux = process.platform === 'linux'
const incompatibleOS = isLinux ? 'darwin' : 'linux'

const path = t.testdir({
'package.json': JSON.stringify({
name: 'extraneous-test',
version: '1.0.0',
dependencies: {
'dependency-with-shrinkwrap': '1.0.0',
},
}),
'package-lock.json': JSON.stringify({
name: 'extraneous-test',
version: '1.0.0',
lockfileVersion: 3,
requires: true,
packages: {
'': {
name: 'extraneous-test',
version: '1.0.0',
dependencies: {
'dependency-with-shrinkwrap': '^1.0.0',
},
},
'node_modules/dependency-with-shrinkwrap': {
version: '1.0.0',
hasShrinkwrap: true,
dependencies: {},
},
'node_modules/dependency-with-shrinkwrap/node_modules/dev-dependency':
{
version: '1.0.0',
extraneous: true,
optionalDependencies: {
'optional-dependancy': '1.0.0',
},
},
'node_modules/dependency-with-shrinkwrap/node_modules/optional-dependancy':
{
version: '1.0.0',
cpu: ['x64'],
extraneous: true,
os: [incompatibleOS],
},
},
}),
})

createRegistry(t, false)
const arb = newArb(path)

try {
await arb.buildIdealTree({ prune: false })
} catch (e) {
t.fail(
'should not throw for extraneous dependency not buildable on this platform'
)
}
}
)