From 8ef00ef3c300cbb9b4b1bd806ef0285f341d837c Mon Sep 17 00:00:00 2001 From: Kyle Lastimosa Date: Sat, 12 Oct 2024 23:10:13 -0400 Subject: [PATCH 1/2] add support for pnpm ignoredOptionalDependencies, resolve #4859 --- ...-optional-dependencies_2024-10-13-01-04.json | 10 ++++++++++ common/reviews/api/rush-lib.api.md | 2 ++ .../src/logic/installManager/InstallHelpers.ts | 5 +++++ .../src/logic/pnpm/PnpmOptionsConfiguration.ts | 17 +++++++++++++++++ .../src/schemas/pnpm-config.schema.json | 9 +++++++++ 5 files changed, 43 insertions(+) create mode 100644 common/changes/@microsoft/rush/support-pnpm-ignore-optional-dependencies_2024-10-13-01-04.json diff --git a/common/changes/@microsoft/rush/support-pnpm-ignore-optional-dependencies_2024-10-13-01-04.json b/common/changes/@microsoft/rush/support-pnpm-ignore-optional-dependencies_2024-10-13-01-04.json new file mode 100644 index 00000000000..cd7225971db --- /dev/null +++ b/common/changes/@microsoft/rush/support-pnpm-ignore-optional-dependencies_2024-10-13-01-04.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "add support for pnpm ignoredOptionalDependencies", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 9e659294629..921878e3417 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -695,6 +695,7 @@ export interface _IPnpmOptionsJson extends IPackageManagerOptionsJsonBase { alwaysInjectDependenciesFromOtherSubspaces?: boolean; autoInstallPeers?: boolean; globalAllowedDeprecatedVersions?: Record; + globalIgnoredOptionalDependencies?: string[]; globalNeverBuiltDependencies?: string[]; globalOverrides?: Record; globalPackageExtensions?: Record; @@ -1061,6 +1062,7 @@ export class PnpmOptionsConfiguration extends PackageManagerOptionsConfiguration readonly alwaysInjectDependenciesFromOtherSubspaces: boolean | undefined; readonly autoInstallPeers: boolean | undefined; readonly globalAllowedDeprecatedVersions: Record | undefined; + readonly globalIgnoredOptionalDependencies: string[] | undefined; readonly globalNeverBuiltDependencies: string[] | undefined; readonly globalOverrides: Record | undefined; readonly globalPackageExtensions: Record | undefined; diff --git a/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts b/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts index cb8a4df9410..a9d0415d330 100644 --- a/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts +++ b/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts @@ -28,6 +28,7 @@ interface ICommonPackageJson extends IPackageJson { packageExtensions?: typeof PnpmOptionsConfiguration.prototype.globalPackageExtensions; peerDependencyRules?: typeof PnpmOptionsConfiguration.prototype.globalPeerDependencyRules; neverBuiltDependencies?: typeof PnpmOptionsConfiguration.prototype.globalNeverBuiltDependencies; + ignoredOptionalDependencies?: typeof PnpmOptionsConfiguration.prototype.globalIgnoredOptionalDependencies; allowedDeprecatedVersions?: typeof PnpmOptionsConfiguration.prototype.globalAllowedDeprecatedVersions; patchedDependencies?: typeof PnpmOptionsConfiguration.prototype.globalPatchedDependencies; }; @@ -69,6 +70,10 @@ export class InstallHelpers { commonPackageJson.pnpm.neverBuiltDependencies = pnpmOptions.globalNeverBuiltDependencies; } + if (pnpmOptions.globalIgnoredOptionalDependencies) { + commonPackageJson.pnpm.ignoredOptionalDependencies = pnpmOptions.globalIgnoredOptionalDependencies; + } + if (pnpmOptions.globalAllowedDeprecatedVersions) { commonPackageJson.pnpm.allowedDeprecatedVersions = pnpmOptions.globalAllowedDeprecatedVersions; } diff --git a/libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.ts b/libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.ts index 8060a65fba7..bc8ba24a594 100644 --- a/libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.ts +++ b/libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.ts @@ -111,6 +111,10 @@ export interface IPnpmOptionsJson extends IPackageManagerOptionsJsonBase { * {@inheritDoc PnpmOptionsConfiguration.globalNeverBuiltDependencies} */ globalNeverBuiltDependencies?: string[]; + /** + * {@inheritDoc PnpmOptionsConfiguration.globalIgnoredOptionalDependencies} + */ + globalIgnoredOptionalDependencies?: string[]; /** * {@inheritDoc PnpmOptionsConfiguration.globalAllowedDeprecatedVersions} */ @@ -321,6 +325,18 @@ export class PnpmOptionsConfiguration extends PackageManagerOptionsConfiguration */ public readonly globalNeverBuiltDependencies: string[] | undefined; + /** + * The ignoredOptionalDependencies setting allows you to exclude certain optional dependencies from being installed + * during the Rush installation process. This can be useful when optional dependencies are not required or are + * problematic in specific environments (e.g., dependencies with incompatible binaries or platform-specific requirements). + * The listed dependencies will be treated as though they are missing, even if other packages specify them as optional + * dependencies. The settings are copied into the pnpm.ignoredOptionalDependencies field of the common/temp/package.json + * file that is generated by Rush during installation. + * + * PNPM documentation: https://pnpm.io/package_json#pnpmignoredoptionaldependencies + */ + public readonly globalIgnoredOptionalDependencies: string[] | undefined; + /** * The `globalAllowedDeprecatedVersions` setting suppresses installation warnings for package * versions that the NPM registry reports as being deprecated. This is useful if the @@ -400,6 +416,7 @@ export class PnpmOptionsConfiguration extends PackageManagerOptionsConfiguration this.globalPeerDependencyRules = json.globalPeerDependencyRules; this.globalPackageExtensions = json.globalPackageExtensions; this.globalNeverBuiltDependencies = json.globalNeverBuiltDependencies; + this.globalIgnoredOptionalDependencies = json.globalIgnoredOptionalDependencies; this.globalAllowedDeprecatedVersions = json.globalAllowedDeprecatedVersions; this.unsupportedPackageJsonSettings = json.unsupportedPackageJsonSettings; this._globalPatchedDependencies = json.globalPatchedDependencies; diff --git a/libraries/rush-lib/src/schemas/pnpm-config.schema.json b/libraries/rush-lib/src/schemas/pnpm-config.schema.json index d120ca72266..3193f069b88 100644 --- a/libraries/rush-lib/src/schemas/pnpm-config.schema.json +++ b/libraries/rush-lib/src/schemas/pnpm-config.schema.json @@ -145,6 +145,15 @@ } }, + "globalIgnoredOptionalDependencies": { + "description": "This field allows you to skip the installation of specific optional dependencies. The listed packages will be treated as if they are not present in the dependency tree during installation, meaning they will not be installed even if required by other packages.", + "type": "array", + "items": { + "description": "Specify the package name of the optional dependency to be ignored.", + "type": "string" + } + }, + "globalAllowedDeprecatedVersions": { "description": "The `globalAllowedDeprecatedVersions` setting suppresses installation warnings for package versions that the NPM registry reports as being deprecated. This is useful if the deprecated package is an indirect dependency of an external package that has not released a fix. The settings are copied into the `pnpm.allowedDeprecatedVersions` field of the `common/temp/package.json` file that is generated by Rush during installation.\n\nPNPM documentation: https://pnpm.io/package_json#pnpmalloweddeprecatedversions", "type": "object", From 7ec9579d5352218fef2333f6fbdd914b66819114 Mon Sep 17 00:00:00 2001 From: Kyle Lastimosa Date: Fri, 18 Oct 2024 14:14:43 -0400 Subject: [PATCH 2/2] modify pnpm-config.json rush init template --- .../rush-init/common/config/rush/pnpm-config.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/rush-lib/assets/rush-init/common/config/rush/pnpm-config.json b/libraries/rush-lib/assets/rush-init/common/config/rush/pnpm-config.json index 1e8df292ef2..be0014da9f5 100644 --- a/libraries/rush-lib/assets/rush-init/common/config/rush/pnpm-config.json +++ b/libraries/rush-lib/assets/rush-init/common/config/rush/pnpm-config.json @@ -269,6 +269,21 @@ /*[LINE "HYPOTHETICAL"]*/ "fsevents" ], + /** + * The `globalIgnoredOptionalDependencies` setting suppresses the installation of optional NPM + * dependencies specified in the list. This is useful when certain optional dependencies are + * not needed in your environment, such as platform-specific packages or dependencies that + * fail during installation but are not critical to your project. + * These settings are copied into the `pnpm.overrides` field of the `common/temp/package.json` + * file that is generated by Rush during installation, instructing PNPM to ignore the specified + * optional dependencies. + * + * PNPM documentation: https://pnpm.io/package_json#pnpmignoredoptionaldependencies + */ + "globalIgnoredOptionalDependencies": [ + /*[LINE "HYPOTHETICAL"]*/ "fsevents" + ], + /** * The `globalAllowedDeprecatedVersions` setting suppresses installation warnings for package * versions that the NPM registry reports as being deprecated. This is useful if the