Add globalOnlyBuiltDependencies support for PNPM 10.x #5523
+83
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PNPM 10.x disables lifecycle scripts by default for security. The
onlyBuiltDependenciessetting provides an allowlist of packages permitted to run build scripts.Changes
Configuration
globalOnlyBuiltDependenciesproperty toPnpmOptionsConfigurationRuntime
globalOnlyBuiltDependenciestocommon/temp/package.jsonaspnpm.onlyBuiltDependenciesInstallHelpers.tsmirrorsglobalNeverBuiltDependenciespatternTesting
pnpm-config-onlyBuiltDependencies.jsonUsage
Generates in
common/temp/package.json:{ "pnpm": { "onlyBuiltDependencies": ["esbuild", "@prisma/client"] } }Notes
common/temp/package.json, notpnpm-workspace.yamluseWorkspaces: falseconfigurationsglobalNeverBuiltDependencies(denylist vs allowlist)Original prompt
Background
Issue #5235 requests PNPM 10.x support. In PNPM 10, lifecycle scripts (e.g.,
postinstall) of dependencies are disabled by default for security. TheonlyBuiltDependenciessetting is an allowlist that specifies which dependencies are permitted to run build scripts.PNPM documentation: https://pnpm.io/package_json#pnpmonlybuiltdependencies
Requirements
Add support for
globalOnlyBuiltDependenciesinpnpm-config.jsonto allow Rush users to specify which dependencies are allowed to run build scripts when using PNPM 10.x.IMPORTANT: Implementation Location
The setting should be written to
common/temp/package.json'spnpmfield (NOT topnpm-workspace.yaml). This is consistent with howneverBuiltDependenciesis already handled inInstallHelpers.ts, and ensures it works for Rush repos that don't have pnpm workspaces enabled (useWorkspaces: false).Implementation Details
1. Update
libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.tsAdd to
IPnpmOptionsJsoninterface (around line 116, afterglobalNeverBuiltDependencies):Add public readonly property to
PnpmOptionsConfigurationclass (afterglobalNeverBuiltDependenciesproperty, around line 366):Initialize in constructor (after
globalNeverBuiltDependenciesinitialization, around line 470):2. Update
libraries/rush-lib/src/schemas/pnpm-config.schema.jsonAdd after
globalNeverBuiltDependencies(around line 151):3. Update
libraries/rush-lib/src/logic/installManager/InstallHelpers.tsUpdate the
ICommonPackageJsoninterface (around line 28) to add:In the
generateCommonPackageJsonmethod, after theglobalNeverBuiltDependenciesblock (around line 77), add:4. Update template file
libraries/rush-lib/assets/rush-init/common/config/rush/pnpm-config.jsonAdd documentation after the
globalNeverBuiltDependenciessection (around line 310):