Skip to content

Commit

Permalink
feat: add --libc option to override platform specific install (#6914)
Browse files Browse the repository at this point in the history
Co-authored-by: LongYinan <lynweklm@gmail.com>
  • Loading branch information
wraithgar and Brooooooklyn authored Jan 10, 2024
1 parent 3fd5213 commit 6673c77
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Install extends ArboristWorkspaceCmd {
'dry-run',
'cpu',
'os',
'libc',
...super.params,
]

Expand Down
2 changes: 2 additions & 0 deletions tap-snapshots/test/lib/commands/config.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"commit-hooks": true,
"cpu": null,
"os": null,
"libc": null,
"depth": null,
"description": true,
"dev": false,
Expand Down Expand Up @@ -245,6 +246,7 @@ json = false
key = null
legacy-bundling = false
legacy-peer-deps = false
libc = null
link = false
local-address = null
location = "user"
Expand Down
19 changes: 17 additions & 2 deletions tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,16 @@ Use of \`legacy-peer-deps\` is not recommended, as it will not enforce the
#### \`libc\`
* Default: null
* Type: null or String
Override libc of native modules to install. Acceptable values are same as
\`libc\` field of package.json
#### \`link\`
* Default: false
Expand Down Expand Up @@ -2049,6 +2059,7 @@ Array [
"commit-hooks",
"cpu",
"os",
"libc",
"depth",
"description",
"dev",
Expand Down Expand Up @@ -2206,6 +2217,7 @@ Array [
"commit-hooks",
"cpu",
"os",
"libc",
"depth",
"description",
"dev",
Expand Down Expand Up @@ -2395,6 +2407,7 @@ Object {
"json": false,
"key": null,
"legacyPeerDeps": false,
"libc": null,
"localAddress": null,
"location": "user",
"lockfileVersion": null,
Expand Down Expand Up @@ -3240,7 +3253,7 @@ Options:
[--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
[--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
[--foreground-scripts] [--ignore-scripts] [--no-audit] [--no-bin-links]
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>]
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>] [--libc <libc>]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root] [--install-links]
Expand Down Expand Up @@ -3274,6 +3287,7 @@ aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
#### \`dry-run\`
#### \`cpu\`
#### \`os\`
#### \`libc\`
#### \`workspace\`
#### \`workspaces\`
#### \`include-workspace-root\`
Expand Down Expand Up @@ -3337,7 +3351,7 @@ Options:
[--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
[--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
[--foreground-scripts] [--ignore-scripts] [--no-audit] [--no-bin-links]
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>]
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>] [--libc <libc>]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root] [--install-links]
Expand Down Expand Up @@ -3371,6 +3385,7 @@ alias: it
#### \`dry-run\`
#### \`cpu\`
#### \`os\`
#### \`libc\`
#### \`workspace\`
#### \`workspaces\`
#### \`include-workspace-root\`
Expand Down
4 changes: 2 additions & 2 deletions workspaces/arborist/lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ module.exports = cls => class Reifier extends cls {
process.emit('time', timer)
this.addTracker('reify', node.name, node.location)

const { npmVersion, nodeVersion, cpu, os } = this.options
const { npmVersion, nodeVersion, cpu, os, libc } = this.options
const p = Promise.resolve().then(async () => {
// when we reify an optional node, check the engine and platform
// first. be sure to ignore the --force and --engine-strict flags,
Expand All @@ -638,7 +638,7 @@ module.exports = cls => class Reifier extends cls {
// eslint-disable-next-line promise/always-return
if (node.optional) {
checkEngine(node.package, npmVersion, nodeVersion, false)
checkPlatform(node.package, false, { cpu, os })
checkPlatform(node.package, false, { cpu, os, libc })
}
await this[_checkBins](node)
await this[_extractOrLink](node)
Expand Down
39 changes: 29 additions & 10 deletions workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3295,7 +3295,7 @@ ArboristNode {
}
`

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`] = `
exports[`test/arborist/reify.js TAP fail to install optional deps with matched os and matched cpu and mismatched libc with os and cpu and libc options > expect resolving Promise 1`] = `
ArboristNode {
"edgesOut": Map {
"platform-specifying-test-package" => EdgeOut {
Expand All @@ -3307,14 +3307,14 @@ ArboristNode {
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-options",
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-matched-cpu-and-mismatched-libc-with-os-and-cpu-and-libc-options",
"packageName": "platform-test",
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-options",
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-matched-cpu-and-mismatched-libc-with-os-and-cpu-and-libc-options",
"version": "1.0.0",
}
`

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`] = `
exports[`test/arborist/reify.js TAP fail to install optional deps with matched os and mismatched cpu with os and cpu and libc options > expect resolving Promise 1`] = `
ArboristNode {
"edgesOut": Map {
"platform-specifying-test-package" => EdgeOut {
Expand All @@ -3326,9 +3326,28 @@ ArboristNode {
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-options",
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-and-libc-options",
"packageName": "platform-test",
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-options",
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-and-libc-options",
"version": "1.0.0",
}
`

exports[`test/arborist/reify.js TAP fail to install optional deps with mismatched os and matched cpu with os and cpu and libc options > expect resolving Promise 1`] = `
ArboristNode {
"edgesOut": Map {
"platform-specifying-test-package" => EdgeOut {
"name": "platform-specifying-test-package",
"spec": "1.0.0",
"to": null,
"type": "optional",
},
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-and-libc-options",
"packageName": "platform-test",
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-and-libc-options",
"version": "1.0.0",
}
`
Expand Down Expand Up @@ -33165,7 +33184,7 @@ exports[`test/arborist/reify.js TAP store files with a custom indenting > must m

`

exports[`test/arborist/reify.js TAP success to install optional deps with matched platform specifications with os and cpu options > expect resolving Promise 1`] = `
exports[`test/arborist/reify.js TAP success to install optional deps with matched platform specifications with os and cpu and libc options > expect resolving Promise 1`] = `
ArboristNode {
"children": Map {
"platform-specifying-test-package" => ArboristNode {
Expand All @@ -33180,7 +33199,7 @@ ArboristNode {
"location": "node_modules/platform-specifying-test-package",
"name": "platform-specifying-test-package",
"optional": true,
"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",
"path": "{CWD}/test/arborist/tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-and-libc-options/node_modules/platform-specifying-test-package",
"resolved": "https://registry.npmjs.org/platform-specifying-test-package/-/platform-specifying-test-package-1.0.0.tgz",
"version": "1.0.0",
},
Expand All @@ -33195,9 +33214,9 @@ ArboristNode {
},
"isProjectRoot": true,
"location": "",
"name": "tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-options",
"name": "tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-and-libc-options",
"packageName": "platform-test",
"path": "{CWD}/test/arborist/tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-options",
"path": "{CWD}/test/arborist/tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-and-libc-options",
"version": "1.0.0",
}
`
Expand Down
16 changes: 10 additions & 6 deletions workspaces/arborist/test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,21 @@ t.test('still do not install optional deps with mismatched platform specificatio
t.test('fail to install deps with mismatched platform specifications', t =>
t.rejects(printReified(fixture(t, 'platform-specification')), { code: 'EBADPLATFORM' }))

t.test('success to install optional deps with matched platform specifications with os and cpu options', t =>
t.test('success to install optional deps with matched platform specifications with os and cpu and libc options', t =>
t.resolveMatchSnapshot(printReified(
fixture(t, 'optional-platform-specification'), { os: 'not-your-os', cpu: 'not-your-cpu' })))
fixture(t, 'optional-platform-specification'), { os: 'not-your-os', cpu: 'not-your-cpu', libc: 'not-your-libc' })))

t.test('fail to install optional deps with matched os and mismatched cpu with os and cpu options', t =>
t.test('fail to install optional deps with matched os and mismatched cpu with os and cpu and libc options', t =>
t.resolveMatchSnapshot(printReified(
fixture(t, 'optional-platform-specification'), { os: 'not-your-os', cpu: 'another-cpu' })))
fixture(t, 'optional-platform-specification'), { os: 'not-your-os', cpu: 'another-cpu', libc: 'not-your-libc' })))

t.test('fail to install optional deps with mismatched os and matched cpu with os and cpu options', t =>
t.test('fail to install optional deps with mismatched os and matched cpu with os and cpu and libc options', t =>
t.resolveMatchSnapshot(printReified(
fixture(t, 'optional-platform-specification'), { os: 'another-os', cpu: 'not-your-cpu' })))
fixture(t, 'optional-platform-specification'), { os: 'another-os', cpu: 'not-your-cpu', libc: 'not-your-libc' })))

t.test('fail to install optional deps with matched os and matched cpu and mismatched libc with os and cpu and libc options', t =>
t.resolveMatchSnapshot(printReified(
fixture(t, 'optional-platform-specification'), { os: 'another-os', cpu: 'not-your-cpu', libc: 'not-your-libc' })))

t.test('dry run, do not get anything wet', async t => {
const cases = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"cpu": [
"not-your-cpu"
],
"libc": [
"not-your-libc"
],
"_id": "platform-specifying-test-package@1.0.0",
"_nodeVersion": "12.18.4",
"_npmVersion": "6.14.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
"unpackedSize": 3481,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfbRvlCRA9TVsSAnZWagAAIQMP/jgNB73uGp5pHvkumGq7\nyA6DC6pqL3vU7Pwctr7QzYi+1jHcWwHtNHHTYwrZZru04xLpiQk8BohAfmOt\nEXstFVfMR/C/Y1pAxi3ITPj79zTmgixUVaor9knGWov8gHyFgQsg+2Jf/90E\nv0fOnAKe4+tb1xZNtKiG+Jc2KBIBhVG3g+YjYc8xYz8FaS4Gj9GPwozhE/kl\nHOu+cAXI/CM2nu1U0Q9Jgxna3i/uzXs8exZVzErgHs6sQPKxBpRwItcl4bOi\nkvUJA+QKmiUNHJauJc/1/vK4O8TD35+kiFSrg82MHnrYuDSzfpRhnjWFKlSb\nfcdLICfV0PhR/6KX4ct+uepUAHHJXBpOe48X5zXjMtFcl1MkImzNzXLbuOZ+\nXo+8LCCc7K5AuBx4HDkAHU0hjdG7k6FLf+fjIdeDbFy/bjPHzb6ecyKf73hX\n+Fh1szs37uwsT2M500qgYgfsLl2GuguBEz2IrFaA7ZGmzXZSF34lsH1dXDgY\nl/CFekaEvA4QaIvGL8BM8CdWkFA2VN8xTuZ9+gC9vsLOSnmaM8Qp1iS+mfr9\nVC5FhANvIi8Ckx0iNJQZ0pC8hMdrT5ox8/oSA42l8XZn4PWQWUco3RA6ksig\n2tcUTuRUDeb40SZV3i1l2xS76YBT4ROeYGyXoiPHBECIo4ps0mGmSd1v3Jdk\nk1n3\r\n=gZQk\r\n-----END PGP SIGNATURE-----\r\n"
},
"os": [
"not-your-os"
],
"cpu": [
"not-your-cpu"
]
"os": ["not-your-os"],
"cpu": ["not-your-cpu"],
"libc": ["not-your-libc"]
}
},
"modified": "2020-09-24T22:21:27.433Z"
Expand Down
10 changes: 10 additions & 0 deletions workspaces/config/lib/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,16 @@ define('os', {
flatten,
})

define('libc', {
default: null,
type: [null, String],
description: `
Override libc of native modules to install.
Acceptable values are same as \`libc\` field of package.json
`,
flatten,
})

define('depth', {
default: null,
defaultDescription: `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ Object {
"legacy-peer-deps": Array [
"boolean value (true or false)",
],
"libc": Array [
null,
Function String(),
],
"link": Array [
"boolean value (true or false)",
],
Expand Down

0 comments on commit 6673c77

Please sign in to comment.