feat: customize supportedArchitectures using CLI#9745
Conversation
config/config/src/index.ts
Outdated
| const supportedArchitecturesKeys = ['os', 'cpu', 'libc'] as const satisfies Array<keyof SupportedArchitectures> | ||
| for (const key of supportedArchitecturesKeys) { | ||
| const values = pnpmConfig[key] | ||
| if (values != null) { | ||
| pnpmConfig.supportedArchitectures ??= {} | ||
| pnpmConfig.supportedArchitectures[key] = [ | ||
| ...pnpmConfig.supportedArchitectures[key] ?? [], | ||
| ...typeof values === 'string' ? [values] : values, | ||
| ] | ||
| } | ||
| } |
There was a problem hiding this comment.
@zkochan This block of code would merge CLI's supportedArchitectures with rootManifest.pnpm.supportedArchitectures. But I'm not sure if this is a desired behavior. If you want one to completely override the other, let me know.
There was a problem hiding this comment.
Probably the CLI values should override the ones in the pnpmConfig.
|
|
@danielbayley this PR is not adding any new settings. |
| --- | ||
| "@pnpm/plugin-commands-installation": patch | ||
| "pnpm": patch | ||
| --- | ||
|
|
||
| Fix a bug in which `pnpm add` downloads packages whose `libc` differ from `pnpm.supportedArchitectures.libc`. |
There was a problem hiding this comment.
I didn't want to make this change in a separate PR because it would cause conflicts.
fetchFullMetadata from master did not include opts.supportedArchitectures?.libc in its calculation.
| opts.supportedArchitectures?.libc ?? | ||
| opts.rootProjectManifest?.pnpm?.supportedArchitectures?.libc |
There was a problem hiding this comment.
Both lines are necessary. Removing any of them would cause test to fail.
|
@danielbayley I don't think that the devEngines field can replace the supportedArchitectures field. The devEngines field just tells what os and cpu are supported by the project. But the supportedArchitecture tells pnpm which artifacts to download when installing optional dependencies. The purpose of these fields differs. |
config/config/src/index.ts
Outdated
| } | ||
| } | ||
|
|
||
| overrideSupportedArchitecturesWithCLI(pnpmConfig) |
There was a problem hiding this comment.
why are we adding these fields to config if they can only be passed as CLI args? Take the settings from cliOptions passed to getConfig.
Ok cool. I just like to reduce the amount of config as much as possible if we can… In that case a better name might have been |
|
I think supportedArchitecture is fine. Yarn uses the same field name. |
There was a problem hiding this comment.
Pull Request Overview
Adds command-line flags for customizing supportedArchitectures and propagates those flags through install, add, and dlx commands.
- Introduce
--cpu,--libc, and--osoptions topnpm install,pnpm add, andpnpm dlx - Refactor
createCacheKeyand tests to includesupportedArchitectures - Centralize
fetchFullMetadatalogic behind a helper and wire up CLI overrides in config
Reviewed Changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| store/plugin-commands-store/test/storePrune.ts | Updated createCacheKey call to new options signature |
| store/plugin-commands-store/src/cleanExpiredDlxCache.test.ts | Updated createCacheKey usage to new options structure |
| pnpm/test/install/supportedArchitectures.ts | Added tests for CLI- and manifest-driven supportedArchitectures |
| pnpm/test/dlx.ts | Updated createCacheKey calls and added supportedArchitectures tests |
| pnpm-workspace.yaml | Bumped @pnpm/registry-mock version |
| pkg-manager/plugin-commands-installation/test/install.ts | Renamed test suite and added --libc CLI behavior tests |
| pkg-manager/plugin-commands-installation/test/add.ts | Added supportedArchitectures.libc tests for pnpm add |
| pkg-manager/plugin-commands-installation/src/install.ts | Moved full-metadata logic into getFetchFullMetadata helper |
| pkg-manager/plugin-commands-installation/src/getFetchFullMetadata.ts | New helper for toggling full-metadata fetch based on libc |
| pkg-manager/plugin-commands-installation/src/add.ts | Integrated full-metadata helper into add handler |
| exec/plugin-commands-script-runners/test/dlx.e2e.ts | Updated createCacheKey usage to include supportedArchitectures |
| exec/plugin-commands-script-runners/test/dlx.createCacheKey.test.ts | Enhanced createCacheKey tests and added ordering checks |
| exec/plugin-commands-script-runners/src/dlx.ts | Extended dlx caching and handler logic to respect architectures |
| exec/plugin-commands-script-runners/package.json | Added @pnpm/util.lex-comparator dependency |
| config/config/test/overrideSupportedArchitecturesWithCLI.test.ts | Added tests for CLI overrides of supportedArchitectures |
| config/config/src/types.ts | Registered cpu, libc, and os in configuration types |
| config/config/src/overrideSupportedArchitecturesWithCLI.ts | Implemented override logic for CLI-supportedArchitectures |
| config/config/src/index.ts | Hooked CLI override into main getConfig flow |
| .changeset/slick-steaks-admire.md | New feature changeset |
| .changeset/pink-cars-guess.md | Bugfix changeset |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (4)
config/config/src/overrideSupportedArchitecturesWithCLI.ts:13
- The JSDoc for
cliOptionsis unclear–please clarify its purpose, e.g.:@param cliOptions - CLI flags for overriding supportedArchitectures.
* @param cliOptions - The object that contains object
exec/plugin-commands-script-runners/test/dlx.createCacheKey.test.ts:42
- This test covers
osandcpuordering but omitslibc. Adding a scenario to verify thatlibcarrays are sorted and deduped would ensure full coverage of the new logic.
test('is agnostic to supportedArchitectures values order', () => {
pnpm/test/dlx.ts:311
- [nitpick] The term
NotInstalleddiffers fromSkippedused elsewhere for skipped packages; consider unifying the name for consistency across tests.
type NotInstalled = string[]
pkg-manager/plugin-commands-installation/src/getFetchFullMetadata.ts:10
- [nitpick] Consider renaming
getFetchFullMetadatatoshouldFetchFullMetadatato better convey that it returns a boolean flag rather than fetching data directly.
export const getFetchFullMetadata = (opts: GetFetchFullMetadataOptions): true | undefined => (
| opts.supportedArchitectures?.libc ?? | ||
| opts.rootProjectManifest?.pnpm?.supportedArchitectures?.libc |
There was a problem hiding this comment.
Checking existence of libc alone can be truthy for empty arrays. You may want to guard on non-empty arrays (e.g. opts.supportedArchitectures?.libc?.length > 0) to avoid unnecessary full metadata fetches.
| opts.supportedArchitectures?.libc ?? | |
| opts.rootProjectManifest?.pnpm?.supportedArchitectures?.libc | |
| (opts.supportedArchitectures?.libc?.length > 0 ? opts.supportedArchitectures.libc : undefined) ?? | |
| (opts.rootProjectManifest?.pnpm?.supportedArchitectures?.libc?.length > 0 ? opts.rootProjectManifest.pnpm.supportedArchitectures.libc : undefined) |
Resolves #7510