Skip to content

[rush] Add support for pnpm ignoredOptionalDependencies #4928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "add support for pnpm ignoredOptionalDependencies",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
2 changes: 2 additions & 0 deletions common/reviews/api/rush-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ export interface _IPnpmOptionsJson extends IPackageManagerOptionsJsonBase {
alwaysInjectDependenciesFromOtherSubspaces?: boolean;
autoInstallPeers?: boolean;
globalAllowedDeprecatedVersions?: Record<string, string>;
globalIgnoredOptionalDependencies?: string[];
globalNeverBuiltDependencies?: string[];
globalOverrides?: Record<string, string>;
globalPackageExtensions?: Record<string, IPnpmPackageExtension>;
Expand Down Expand Up @@ -1061,6 +1062,7 @@ export class PnpmOptionsConfiguration extends PackageManagerOptionsConfiguration
readonly alwaysInjectDependenciesFromOtherSubspaces: boolean | undefined;
readonly autoInstallPeers: boolean | undefined;
readonly globalAllowedDeprecatedVersions: Record<string, string> | undefined;
readonly globalIgnoredOptionalDependencies: string[] | undefined;
readonly globalNeverBuiltDependencies: string[] | undefined;
readonly globalOverrides: Record<string, string> | undefined;
readonly globalPackageExtensions: Record<string, IPnpmPackageExtension> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export interface IPnpmOptionsJson extends IPackageManagerOptionsJsonBase {
* {@inheritDoc PnpmOptionsConfiguration.globalNeverBuiltDependencies}
*/
globalNeverBuiltDependencies?: string[];
/**
* {@inheritDoc PnpmOptionsConfiguration.globalIgnoredOptionalDependencies}
*/
globalIgnoredOptionalDependencies?: string[];
/**
* {@inheritDoc PnpmOptionsConfiguration.globalAllowedDeprecatedVersions}
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions libraries/rush-lib/src/schemas/pnpm-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading