From 0a53c48504a9c922dde6ba29297685702269d507 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sat, 16 Sep 2023 23:48:23 -0700 Subject: [PATCH] feat: add `--libc` option to override platform specific install --- lib/commands/install.js | 1 + .../test/lib/commands/config.js.test.cjs | 2 + tap-snapshots/test/lib/docs.js.test.cjs | 19 ++++++++- workspaces/arborist/lib/arborist/reify.js | 4 +- .../test/arborist/reify.js.test.cjs | 39 ++++++++++++++----- workspaces/arborist/test/arborist/reify.js | 16 +++++--- .../platform-specifying-test-package.json | 3 ++ .../platform-specifying-test-package.min.json | 9 ++--- .../config/lib/definitions/definitions.js | 10 +++++ .../test/type-description.js.test.cjs | 4 ++ 10 files changed, 81 insertions(+), 26 deletions(-) diff --git a/lib/commands/install.js b/lib/commands/install.js index 6687ec4371dd8..d04a35fbec2a7 100644 --- a/lib/commands/install.js +++ b/lib/commands/install.js @@ -37,6 +37,7 @@ class Install extends ArboristWorkspaceCmd { 'dry-run', 'cpu', 'os', + 'libc', ...super.params, ] diff --git a/tap-snapshots/test/lib/commands/config.js.test.cjs b/tap-snapshots/test/lib/commands/config.js.test.cjs index cff766edb8e51..6c4a27ca5916b 100644 --- a/tap-snapshots/test/lib/commands/config.js.test.cjs +++ b/tap-snapshots/test/lib/commands/config.js.test.cjs @@ -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, @@ -245,6 +246,7 @@ json = false key = null legacy-bundling = false legacy-peer-deps = false +libc = null link = false local-address = null location = "user" diff --git a/tap-snapshots/test/lib/docs.js.test.cjs b/tap-snapshots/test/lib/docs.js.test.cjs index 86bf394e8bb25..5ea1c9e4383b2 100644 --- a/tap-snapshots/test/lib/docs.js.test.cjs +++ b/tap-snapshots/test/lib/docs.js.test.cjs @@ -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 @@ -2049,6 +2059,7 @@ Array [ "commit-hooks", "cpu", "os", + "libc", "depth", "description", "dev", @@ -2206,6 +2217,7 @@ Array [ "commit-hooks", "cpu", "os", + "libc", "depth", "description", "dev", @@ -2395,6 +2407,7 @@ Object { "json": false, "key": null, "legacyPeerDeps": false, + "libc": null, "localAddress": null, "location": "user", "lockfileVersion": null, @@ -3240,7 +3253,7 @@ Options: [--include [--include ...]] [--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 ] [--os ] +[--no-fund] [--dry-run] [--cpu ] [--os ] [--libc ] [-w|--workspace [-w|--workspace ...]] [-ws|--workspaces] [--include-workspace-root] [--install-links] @@ -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\` @@ -3337,7 +3351,7 @@ Options: [--include [--include ...]] [--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 ] [--os ] +[--no-fund] [--dry-run] [--cpu ] [--os ] [--libc ] [-w|--workspace [-w|--workspace ...]] [-ws|--workspaces] [--include-workspace-root] [--install-links] @@ -3371,6 +3385,7 @@ alias: it #### \`dry-run\` #### \`cpu\` #### \`os\` +#### \`libc\` #### \`workspace\` #### \`workspaces\` #### \`include-workspace-root\` diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index 0981afdae6ece..7ce3bc2a9db1d 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -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, @@ -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) diff --git a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs index 94a60bf9c9ca7..57c71f72e0a04 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs @@ -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 { @@ -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 { @@ -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", } ` @@ -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 { @@ -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", }, @@ -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", } ` diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js index 28e711bb31ab5..3d1c34b354ced 100644 --- a/workspaces/arborist/test/arborist/reify.js +++ b/workspaces/arborist/test/arborist/reify.js @@ -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 = [ diff --git a/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.json b/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.json index 5d4d8ccc7bd58..02272157e4f31 100644 --- a/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.json +++ b/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.json @@ -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", diff --git a/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.min.json b/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.min.json index a13d09372b177..2da93f4f492c3 100644 --- a/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.min.json +++ b/workspaces/arborist/test/fixtures/registry-mocks/content/platform-specifying-test-package.min.json @@ -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" diff --git a/workspaces/config/lib/definitions/definitions.js b/workspaces/config/lib/definitions/definitions.js index 9146505d2c2b0..6f8760fce1d3e 100644 --- a/workspaces/config/lib/definitions/definitions.js +++ b/workspaces/config/lib/definitions/definitions.js @@ -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: ` diff --git a/workspaces/config/tap-snapshots/test/type-description.js.test.cjs b/workspaces/config/tap-snapshots/test/type-description.js.test.cjs index a293672deaa0a..78fca4ef3eb94 100644 --- a/workspaces/config/tap-snapshots/test/type-description.js.test.cjs +++ b/workspaces/config/tap-snapshots/test/type-description.js.test.cjs @@ -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)", ],