@@ -380,6 +380,15 @@ export class WorkspaceInstallManager extends BaseInstallManager {
380380 shrinkwrapIsUpToDate = false ;
381381 }
382382
383+ const {
384+ rushConfigurationJson : { pnpmVersion } ,
385+ pnpmOptions,
386+ commonRushConfigFolder
387+ } = this . rushConfiguration ;
388+ if ( pnpmVersion === undefined ) {
389+ throw new Error ( 'Unexpected: pnpmVersion is not defined in rush.json' ) ;
390+ }
391+
383392 // Check if overrides and globalOverrides are the same
384393 const {
385394 globalOverrides = { } ,
@@ -389,8 +398,11 @@ export class WorkspaceInstallManager extends BaseInstallManager {
389398 globalOnlyBuiltDependencies,
390399 globalNeverBuiltDependencies,
391400 minimumReleaseAgeMinutes,
392- minimumReleaseAgeExclude
393- } : PnpmOptionsConfiguration = subspace . getPnpmOptions ( ) || this . rushConfiguration . pnpmOptions ;
401+ minimumReleaseAgeExclude,
402+ globalPeerDependencyRules,
403+ globalAllowedDeprecatedVersions,
404+ globalPatchedDependencies
405+ } : PnpmOptionsConfiguration = subspace . getPnpmOptions ( ) || pnpmOptions ;
394406
395407 const overridesAreEqual : boolean = Objects . areDeepEqual < Record < string , string > > (
396408 globalOverrides ,
@@ -452,15 +464,12 @@ export class WorkspaceInstallManager extends BaseInstallManager {
452464
453465 // Set catalog definitions in the workspace file if specified
454466 if ( catalogs ) {
455- if (
456- this . rushConfiguration . rushConfigurationJson . pnpmVersion !== undefined &&
457- semver . lt ( this . rushConfiguration . rushConfigurationJson . pnpmVersion , '9.5.0' )
458- ) {
467+ if ( semver . lt ( pnpmVersion , '9.5.0' ) ) {
459468 this . _terminal . writeWarningLine (
460469 Colorize . yellow (
461- `Your version of pnpm (${ this . rushConfiguration . rushConfigurationJson . pnpmVersion } ) ` +
470+ `Your version of pnpm (${ pnpmVersion } ) ` +
462471 `doesn't support the "globalCatalogs" fields in ` +
463- `${ this . rushConfiguration . commonRushConfigFolder } /${ RushConstants . pnpmConfigFilename } . ` +
472+ `${ commonRushConfigFolder } /${ RushConstants . pnpmConfigFilename } . ` +
464473 'Remove these fields or upgrade to pnpm 9.5.0 or newer.'
465474 )
466475 ) ;
@@ -470,10 +479,7 @@ export class WorkspaceInstallManager extends BaseInstallManager {
470479 }
471480
472481 // Set allowBuilds in the workspace file for pnpm 11+ (replaces onlyBuiltDependencies/neverBuiltDependencies)
473- if (
474- this . rushConfiguration . rushConfigurationJson . pnpmVersion !== undefined &&
475- semver . gte ( this . rushConfiguration . rushConfigurationJson . pnpmVersion , '11.0.0' )
476- ) {
482+ if ( semver . gte ( pnpmVersion , '11.0.0' ) ) {
477483 if ( globalAllowBuilds ) {
478484 workspaceFile . allowBuilds = globalAllowBuilds ;
479485 } else if ( globalOnlyBuiltDependencies || globalNeverBuiltDependencies ) {
@@ -494,12 +500,12 @@ export class WorkspaceInstallManager extends BaseInstallManager {
494500
495501 workspaceFile . allowBuilds = allowBuilds ;
496502 }
497- } else if ( globalAllowBuilds && this . rushConfiguration . rushConfigurationJson . pnpmVersion !== undefined ) {
503+ } else if ( globalAllowBuilds && pnpmVersion !== undefined ) {
498504 this . _terminal . writeWarningLine (
499505 Colorize . yellow (
500- `Your version of pnpm (${ this . rushConfiguration . rushConfigurationJson . pnpmVersion } ) ` +
506+ `Your version of pnpm (${ pnpmVersion } ) ` +
501507 `doesn't support the "globalAllowBuilds" field in ` +
502- `${ this . rushConfiguration . commonRushConfigFolder } /${ RushConstants . pnpmConfigFilename } . ` +
508+ `${ commonRushConfigFolder } /${ RushConstants . pnpmConfigFilename } . ` +
503509 'Remove this field or upgrade to pnpm 11.0.0 or newer.'
504510 )
505511 ) ;
@@ -508,31 +514,23 @@ export class WorkspaceInstallManager extends BaseInstallManager {
508514 // For pnpm 11+, the following settings must be written to pnpm-workspace.yaml because pnpm 11
509515 // no longer reads the "pnpm" field of package.json (where Rush writes them for older pnpm).
510516 // See https://github.com/microsoft/rushstack/issues/5837
511- if (
512- this . rushConfiguration . rushConfigurationJson . pnpmVersion !== undefined &&
513- semver . gte ( this . rushConfiguration . rushConfigurationJson . pnpmVersion , '11.0.0' )
514- ) {
515- const pnpmOptions : PnpmOptionsConfiguration =
516- subspace . getPnpmOptions ( ) || this . rushConfiguration . pnpmOptions ;
517- workspaceFile . overrides = pnpmOptions . globalOverrides ;
518- workspaceFile . packageExtensions = pnpmOptions . globalPackageExtensions ;
519- workspaceFile . peerDependencyRules = pnpmOptions . globalPeerDependencyRules ;
520- workspaceFile . allowedDeprecatedVersions = pnpmOptions . globalAllowedDeprecatedVersions ;
521- workspaceFile . patchedDependencies = pnpmOptions . globalPatchedDependencies ;
517+ if ( semver . gte ( pnpmVersion , '11.0.0' ) ) {
518+ workspaceFile . overrides = globalOverrides ;
519+ workspaceFile . packageExtensions = globalPackageExtensions ;
520+ workspaceFile . peerDependencyRules = globalPeerDependencyRules ;
521+ workspaceFile . allowedDeprecatedVersions = globalAllowedDeprecatedVersions ;
522+ workspaceFile . patchedDependencies = globalPatchedDependencies ;
522523 }
523524
524525 // Set minimumReleaseAge/minimumReleaseAgeExclude in the workspace file.
525526 // pnpm does not read these fields from package.json, only from pnpm-workspace.yaml or .npmrc.
526527 if ( minimumReleaseAgeMinutes !== undefined || minimumReleaseAgeExclude ) {
527- if (
528- this . rushConfiguration . rushConfigurationJson . pnpmVersion !== undefined &&
529- semver . lt ( this . rushConfiguration . rushConfigurationJson . pnpmVersion , '10.16.0' )
530- ) {
528+ if ( semver . lt ( pnpmVersion , '10.16.0' ) ) {
531529 this . _terminal . writeWarningLine (
532530 Colorize . yellow (
533- `Your version of pnpm (${ this . rushConfiguration . rushConfigurationJson . pnpmVersion } ) ` +
531+ `Your version of pnpm (${ pnpmVersion } ) ` +
534532 `doesn't support the "minimumReleaseAgeMinutes" or "minimumReleaseAgeExclude" fields in ` +
535- `${ this . rushConfiguration . commonRushConfigFolder } /${ RushConstants . pnpmConfigFilename } . ` +
533+ `${ commonRushConfigFolder } /${ RushConstants . pnpmConfigFilename } . ` +
536534 'Remove these fields or upgrade to pnpm 10.16.0 or newer.'
537535 )
538536 ) ;
0 commit comments