Skip to content

Commit b674c42

Browse files
committed
allow to override cpu and os on reify
1 parent 3f9aa45 commit b674c42

File tree

5 files changed

+95
-2
lines changed

5 files changed

+95
-2
lines changed

workspaces/arborist/lib/arborist/reify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ module.exports = cls => class Reifier extends cls {
628628
process.emit('time', timer)
629629
this.addTracker('reify', node.name, node.location)
630630

631-
const { npmVersion, nodeVersion } = this.options
631+
const { npmVersion, nodeVersion, cpu, os } = this.options
632632
const p = Promise.resolve().then(async () => {
633633
// when we reify an optional node, check the engine and platform
634634
// first. be sure to ignore the --force and --engine-strict flags,
@@ -638,7 +638,7 @@ module.exports = cls => class Reifier extends cls {
638638
// eslint-disable-next-line promise/always-return
639639
if (node.optional) {
640640
checkEngine(node.package, npmVersion, nodeVersion, false)
641-
checkPlatform(node.package, false)
641+
checkPlatform(node.package, false, { cpu, os })
642642
}
643643
await this[_checkBins](node)
644644
await this[_extractOrLink](node)

workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,44 @@ ArboristNode {
31613161
}
31623162
`
31633163

3164+
exports[`test/arborist/reify.js TAP fail to install optional deps with matched os and mismatched cpu with os and cpu options > expect resolving Promise 1`] = `
3165+
ArboristNode {
3166+
"edgesOut": Map {
3167+
"platform-specifying-test-package" => EdgeOut {
3168+
"name": "platform-specifying-test-package",
3169+
"spec": "1.0.0",
3170+
"to": null,
3171+
"type": "optional",
3172+
},
3173+
},
3174+
"isProjectRoot": true,
3175+
"location": "",
3176+
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-options",
3177+
"packageName": "platform-test",
3178+
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-options",
3179+
"version": "1.0.0",
3180+
}
3181+
`
3182+
3183+
exports[`test/arborist/reify.js TAP fail to install optional deps with mismatched os and matched cpu with os and cpu options > expect resolving Promise 1`] = `
3184+
ArboristNode {
3185+
"edgesOut": Map {
3186+
"platform-specifying-test-package" => EdgeOut {
3187+
"name": "platform-specifying-test-package",
3188+
"spec": "1.0.0",
3189+
"to": null,
3190+
"type": "optional",
3191+
},
3192+
},
3193+
"isProjectRoot": true,
3194+
"location": "",
3195+
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-options",
3196+
"packageName": "platform-test",
3197+
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-options",
3198+
"version": "1.0.0",
3199+
}
3200+
`
3201+
31643202
exports[`test/arborist/reify.js TAP failing script means install failure, unless ignoreScripts prod-dep-allinstall-fail --ignore-scripts > expect resolving Promise 1`] = `
31653203
ArboristNode {
31663204
"children": Map {
@@ -32993,6 +33031,43 @@ exports[`test/arborist/reify.js TAP store files with a custom indenting > must m
3299333031

3299433032
`
3299533033

33034+
exports[`test/arborist/reify.js TAP success to install optional deps with matched platform specifications with os and cpu options > expect resolving Promise 1`] = `
33035+
ArboristNode {
33036+
"children": Map {
33037+
"platform-specifying-test-package" => ArboristNode {
33038+
"edgesIn": Set {
33039+
EdgeIn {
33040+
"from": "",
33041+
"name": "platform-specifying-test-package",
33042+
"spec": "1.0.0",
33043+
"type": "optional",
33044+
},
33045+
},
33046+
"location": "node_modules/platform-specifying-test-package",
33047+
"name": "platform-specifying-test-package",
33048+
"optional": true,
33049+
"path": "{CWD}/test/arborist/tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-options/node_modules/platform-specifying-test-package",
33050+
"resolved": "https://registry.npmjs.org/platform-specifying-test-package/-/platform-specifying-test-package-1.0.0.tgz",
33051+
"version": "1.0.0",
33052+
},
33053+
},
33054+
"edgesOut": Map {
33055+
"platform-specifying-test-package" => EdgeOut {
33056+
"name": "platform-specifying-test-package",
33057+
"spec": "1.0.0",
33058+
"to": "node_modules/platform-specifying-test-package",
33059+
"type": "optional",
33060+
},
33061+
},
33062+
"isProjectRoot": true,
33063+
"location": "",
33064+
"name": "tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-options",
33065+
"packageName": "platform-test",
33066+
"path": "{CWD}/test/arborist/tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-options",
33067+
"version": "1.0.0",
33068+
}
33069+
`
33070+
3299633071
exports[`test/arborist/reify.js TAP tarball deps with transitive tarball deps > expect resolving Promise 1`] = `
3299733072
ArboristNode {
3299833073
"children": Map {

workspaces/arborist/test/arborist/reify.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,18 @@ t.test('still do not install optional deps with mismatched platform specificatio
465465
t.test('fail to install deps with mismatched platform specifications', t =>
466466
t.rejects(printReified(fixture(t, 'platform-specification')), { code: 'EBADPLATFORM' }))
467467

468+
t.test('success to install optional deps with matched platform specifications with os and cpu options', t =>
469+
t.resolveMatchSnapshot(printReified(
470+
fixture(t, 'optional-platform-specification'), { os: 'not-your-os', cpu: 'not-your-cpu' })))
471+
472+
t.test('fail to install optional deps with matched os and mismatched cpu with os and cpu options', t =>
473+
t.resolveMatchSnapshot(printReified(
474+
fixture(t, 'optional-platform-specification'), { os: 'not-your-os', cpu: 'another-cpu' })))
475+
476+
t.test('fail to install optional deps with mismatched os and matched cpu with os and cpu options', t =>
477+
t.resolveMatchSnapshot(printReified(
478+
fixture(t, 'optional-platform-specification'), { os: 'another-os', cpu: 'not-your-cpu' })))
479+
468480
t.test('dry run, do not get anything wet', async t => {
469481
const cases = [
470482
'shrinkwrapped-dep-with-lock-empty',

workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"os": [
2222
"not-your-os"
2323
],
24+
"cpu": [
25+
"not-your-cpu"
26+
],
2427
2528
"_nodeVersion": "12.18.4",
2629
"_npmVersion": "6.14.6",

workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.min.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
},
1616
"os": [
1717
"not-your-os"
18+
],
19+
"cpu": [
20+
"not-your-cpu"
1821
]
1922
}
2023
},

0 commit comments

Comments
 (0)