Skip to content

Commit 6673c77

Browse files
wraithgarBrooooooklyn
andauthoredJan 10, 2024
feat: add --libc option to override platform specific install (#6914)
Co-authored-by: LongYinan <lynweklm@gmail.com>
1 parent 3fd5213 commit 6673c77

File tree

10 files changed

+81
-26
lines changed

10 files changed

+81
-26
lines changed
 

‎lib/commands/install.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Install extends ArboristWorkspaceCmd {
3737
'dry-run',
3838
'cpu',
3939
'os',
40+
'libc',
4041
...super.params,
4142
]
4243

‎tap-snapshots/test/lib/commands/config.js.test.cjs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
3535
"commit-hooks": true,
3636
"cpu": null,
3737
"os": null,
38+
"libc": null,
3839
"depth": null,
3940
"description": true,
4041
"dev": false,
@@ -245,6 +246,7 @@ json = false
245246
key = null
246247
legacy-bundling = false
247248
legacy-peer-deps = false
249+
libc = null
248250
link = false
249251
local-address = null
250252
location = "user"

‎tap-snapshots/test/lib/docs.js.test.cjs

+17-2
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,16 @@ Use of \`legacy-peer-deps\` is not recommended, as it will not enforce the
903903
904904
905905
906+
#### \`libc\`
907+
908+
* Default: null
909+
* Type: null or String
910+
911+
Override libc of native modules to install. Acceptable values are same as
912+
\`libc\` field of package.json
913+
914+
915+
906916
#### \`link\`
907917
908918
* Default: false
@@ -2049,6 +2059,7 @@ Array [
20492059
"commit-hooks",
20502060
"cpu",
20512061
"os",
2062+
"libc",
20522063
"depth",
20532064
"description",
20542065
"dev",
@@ -2206,6 +2217,7 @@ Array [
22062217
"commit-hooks",
22072218
"cpu",
22082219
"os",
2220+
"libc",
22092221
"depth",
22102222
"description",
22112223
"dev",
@@ -2395,6 +2407,7 @@ Object {
23952407
"json": false,
23962408
"key": null,
23972409
"legacyPeerDeps": false,
2410+
"libc": null,
23982411
"localAddress": null,
23992412
"location": "user",
24002413
"lockfileVersion": null,
@@ -3240,7 +3253,7 @@ Options:
32403253
[--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
32413254
[--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
32423255
[--foreground-scripts] [--ignore-scripts] [--no-audit] [--no-bin-links]
3243-
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>]
3256+
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>] [--libc <libc>]
32443257
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
32453258
[-ws|--workspaces] [--include-workspace-root] [--install-links]
32463259
@@ -3274,6 +3287,7 @@ aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
32743287
#### \`dry-run\`
32753288
#### \`cpu\`
32763289
#### \`os\`
3290+
#### \`libc\`
32773291
#### \`workspace\`
32783292
#### \`workspaces\`
32793293
#### \`include-workspace-root\`
@@ -3337,7 +3351,7 @@ Options:
33373351
[--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
33383352
[--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
33393353
[--foreground-scripts] [--ignore-scripts] [--no-audit] [--no-bin-links]
3340-
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>]
3354+
[--no-fund] [--dry-run] [--cpu <cpu>] [--os <os>] [--libc <libc>]
33413355
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
33423356
[-ws|--workspaces] [--include-workspace-root] [--install-links]
33433357
@@ -3371,6 +3385,7 @@ alias: it
33713385
#### \`dry-run\`
33723386
#### \`cpu\`
33733387
#### \`os\`
3388+
#### \`libc\`
33743389
#### \`workspace\`
33753390
#### \`workspaces\`
33763391
#### \`include-workspace-root\`

‎workspaces/arborist/lib/arborist/reify.js

+2-2
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, cpu, os } = this.options
631+
const { npmVersion, nodeVersion, cpu, os, libc } = 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, { cpu, os })
641+
checkPlatform(node.package, false, { cpu, os, libc })
642642
}
643643
await this[_checkBins](node)
644644
await this[_extractOrLink](node)

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

+29-10
Original file line numberDiff line numberDiff line change
@@ -3295,7 +3295,7 @@ ArboristNode {
32953295
}
32963296
`
32973297

3298-
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`] = `
3298+
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`] = `
32993299
ArboristNode {
33003300
"edgesOut": Map {
33013301
"platform-specifying-test-package" => EdgeOut {
@@ -3307,14 +3307,14 @@ ArboristNode {
33073307
},
33083308
"isProjectRoot": true,
33093309
"location": "",
3310-
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-options",
3310+
"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",
33113311
"packageName": "platform-test",
3312-
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-options",
3312+
"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",
33133313
"version": "1.0.0",
33143314
}
33153315
`
33163316

3317-
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`] = `
3317+
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`] = `
33183318
ArboristNode {
33193319
"edgesOut": Map {
33203320
"platform-specifying-test-package" => EdgeOut {
@@ -3326,9 +3326,28 @@ ArboristNode {
33263326
},
33273327
"isProjectRoot": true,
33283328
"location": "",
3329-
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-options",
3329+
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-matched-os-and-mismatched-cpu-with-os-and-cpu-and-libc-options",
33303330
"packageName": "platform-test",
3331-
"path": "{CWD}/test/arborist/tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-options",
3331+
"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",
3332+
"version": "1.0.0",
3333+
}
3334+
`
3335+
3336+
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`] = `
3337+
ArboristNode {
3338+
"edgesOut": Map {
3339+
"platform-specifying-test-package" => EdgeOut {
3340+
"name": "platform-specifying-test-package",
3341+
"spec": "1.0.0",
3342+
"to": null,
3343+
"type": "optional",
3344+
},
3345+
},
3346+
"isProjectRoot": true,
3347+
"location": "",
3348+
"name": "tap-testdir-reify-fail-to-install-optional-deps-with-mismatched-os-and-matched-cpu-with-os-and-cpu-and-libc-options",
3349+
"packageName": "platform-test",
3350+
"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",
33323351
"version": "1.0.0",
33333352
}
33343353
`
@@ -33165,7 +33184,7 @@ exports[`test/arborist/reify.js TAP store files with a custom indenting > must m
3316533184

3316633185
`
3316733186

33168-
exports[`test/arborist/reify.js TAP success to install optional deps with matched platform specifications with os and cpu options > expect resolving Promise 1`] = `
33187+
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`] = `
3316933188
ArboristNode {
3317033189
"children": Map {
3317133190
"platform-specifying-test-package" => ArboristNode {
@@ -33180,7 +33199,7 @@ ArboristNode {
3318033199
"location": "node_modules/platform-specifying-test-package",
3318133200
"name": "platform-specifying-test-package",
3318233201
"optional": true,
33183-
"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",
33202+
"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",
3318433203
"resolved": "https://registry.npmjs.org/platform-specifying-test-package/-/platform-specifying-test-package-1.0.0.tgz",
3318533204
"version": "1.0.0",
3318633205
},
@@ -33195,9 +33214,9 @@ ArboristNode {
3319533214
},
3319633215
"isProjectRoot": true,
3319733216
"location": "",
33198-
"name": "tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-options",
33217+
"name": "tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-and-libc-options",
3319933218
"packageName": "platform-test",
33200-
"path": "{CWD}/test/arborist/tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-options",
33219+
"path": "{CWD}/test/arborist/tap-testdir-reify-success-to-install-optional-deps-with-matched-platform-specifications-with-os-and-cpu-and-libc-options",
3320133220
"version": "1.0.0",
3320233221
}
3320333222
`

‎workspaces/arborist/test/arborist/reify.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -470,17 +470,21 @@ t.test('still do not install optional deps with mismatched platform specificatio
470470
t.test('fail to install deps with mismatched platform specifications', t =>
471471
t.rejects(printReified(fixture(t, 'platform-specification')), { code: 'EBADPLATFORM' }))
472472

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

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

481-
t.test('fail to install optional deps with mismatched os and matched cpu with os and cpu options', t =>
481+
t.test('fail to install optional deps with mismatched os and matched cpu with os and cpu and libc options', t =>
482482
t.resolveMatchSnapshot(printReified(
483-
fixture(t, 'optional-platform-specification'), { os: 'another-os', cpu: 'not-your-cpu' })))
483+
fixture(t, 'optional-platform-specification'), { os: 'another-os', cpu: 'not-your-cpu', libc: 'not-your-libc' })))
484+
485+
t.test('fail to install optional deps with matched os and matched cpu and mismatched libc with os and cpu and libc options', t =>
486+
t.resolveMatchSnapshot(printReified(
487+
fixture(t, 'optional-platform-specification'), { os: 'another-os', cpu: 'not-your-cpu', libc: 'not-your-libc' })))
484488

485489
t.test('dry run, do not get anything wet', async t => {
486490
const cases = [

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

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"cpu": [
2525
"not-your-cpu"
2626
],
27+
"libc": [
28+
"not-your-libc"
29+
],
2730
"_id": "platform-specifying-test-package@1.0.0",
2831
"_nodeVersion": "12.18.4",
2932
"_npmVersion": "6.14.6",

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
"unpackedSize": 3481,
1414
"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"
1515
},
16-
"os": [
17-
"not-your-os"
18-
],
19-
"cpu": [
20-
"not-your-cpu"
21-
]
16+
"os": ["not-your-os"],
17+
"cpu": ["not-your-cpu"],
18+
"libc": ["not-your-libc"]
2219
}
2320
},
2421
"modified": "2020-09-24T22:21:27.433Z"

‎workspaces/config/lib/definitions/definitions.js

+10
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,16 @@ define('os', {
494494
flatten,
495495
})
496496

497+
define('libc', {
498+
default: null,
499+
type: [null, String],
500+
description: `
501+
Override libc of native modules to install.
502+
Acceptable values are same as \`libc\` field of package.json
503+
`,
504+
flatten,
505+
})
506+
497507
define('depth', {
498508
default: null,
499509
defaultDescription: `

‎workspaces/config/tap-snapshots/test/type-description.js.test.cjs

+4
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ Object {
267267
"legacy-peer-deps": Array [
268268
"boolean value (true or false)",
269269
],
270+
"libc": Array [
271+
null,
272+
Function String(),
273+
],
270274
"link": Array [
271275
"boolean value (true or false)",
272276
],

0 commit comments

Comments
 (0)
Please sign in to comment.