[rush] Add support for pnpm ignoredOptionalDependencies (#4928)

* add support for pnpm ignoredOptionalDependencies, resolve #4859

* modify pnpm-config.json rush init template
This commit is contained in:
Kyle Lastimosa 2024-10-19 04:15:05 +08:00 коммит произвёл GitHub
Родитель 0c7a1ed40e
Коммит 536cb5398d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
6 изменённых файлов: 58 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "add support for pnpm ignoredOptionalDependencies",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}

Просмотреть файл

@ -727,6 +727,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>;
@ -1086,6 +1087,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;

Просмотреть файл

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

Просмотреть файл

@ -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;
}

Просмотреть файл

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

Просмотреть файл

@ -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",