Skip to content

feat: customize supportedArchitectures using CLI#9745

Merged
zkochan merged 22 commits intomainfrom
cli-supported-architectures-7510
Jul 15, 2025
Merged

feat: customize supportedArchitectures using CLI#9745
zkochan merged 22 commits intomainfrom
cli-supported-architectures-7510

Conversation

@KSXGitHub
Copy link
Copy Markdown
Contributor

Resolves #7510

Comment on lines +384 to +394
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,
]
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the CLI values should override the ones in the pnpmConfig.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbayley
Copy link
Copy Markdown

#7510 (comment)

If we are supporting the devEngines standard (which includes os and cpu—see #9742 and #9707), is it a good idea to duplicate even more config here? @KSXGitHub

@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jul 11, 2025

@danielbayley this PR is not adding any new settings.

Comment on lines +1 to +6
---
"@pnpm/plugin-commands-installation": patch
"pnpm": patch
---

Fix a bug in which `pnpm add` downloads packages whose `libc` differ from `pnpm.supportedArchitectures.libc`.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +11 to +12
opts.supportedArchitectures?.libc ??
opts.rootProjectManifest?.pnpm?.supportedArchitectures?.libc
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both lines are necessary. Removing any of them would cause test to fail.

@KSXGitHub KSXGitHub marked this pull request as ready for review July 15, 2025 12:34
@KSXGitHub KSXGitHub requested a review from zkochan July 15, 2025 12:35
@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jul 15, 2025

@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.

}
}

overrideSupportedArchitecturesWithCLI(pnpmConfig)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbayley
Copy link
Copy Markdown

@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.

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 preferredArchitecture or something, no?

@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jul 15, 2025

I think supportedArchitecture is fine. Yarn uses the same field name.

@KSXGitHub KSXGitHub requested a review from zkochan July 15, 2025 15:54
@zkochan zkochan requested a review from Copilot July 15, 2025 22:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds command-line flags for customizing supportedArchitectures and propagates those flags through install, add, and dlx commands.

  • Introduce --cpu, --libc, and --os options to pnpm install, pnpm add, and pnpm dlx
  • Refactor createCacheKey and tests to include supportedArchitectures
  • Centralize fetchFullMetadata logic 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 cliOptions is 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 os and cpu ordering but omits libc. Adding a scenario to verify that libc arrays 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 NotInstalled differs from Skipped used 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 getFetchFullMetadata to shouldFetchFullMetadata to better convey that it returns a boolean flag rather than fetching data directly.
export const getFetchFullMetadata = (opts: GetFetchFullMetadataOptions): true | undefined => (

Comment on lines +11 to +12
opts.supportedArchitectures?.libc ??
opts.rootProjectManifest?.pnpm?.supportedArchitectures?.libc
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
@zkochan zkochan merged commit 6f7ac0f into main Jul 15, 2025
19 of 21 checks passed
@zkochan zkochan deleted the cli-supported-architectures-7510 branch July 15, 2025 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

supportedArchitectures using the CLI

4 participants