@@ -613,7 +613,7 @@ async function addOverrides(
613
613
)
614
614
}
615
615
if ( spinner ) {
616
- spinner . text = `Adding overrides${ isWorkspace ? ` to ${ workspaceName } ` : '' } ...`
616
+ spinner . text = `Adding overrides${ workspaceName ? ` to ${ workspaceName } ` : '' } ...`
617
617
}
618
618
const depAliasMap = new Map < string , { id : string ; version : string } > ( )
619
619
// Chunk package names to process them in parallel 3 at a time.
@@ -636,7 +636,7 @@ async function addOverrides(
636
636
pkgSpec = `${ regSpecStartsLike } ^${ version } `
637
637
depObj [ origPkgName ] = pkgSpec
638
638
state . added . add ( regPkgName )
639
- if ( isWorkspace ) {
639
+ if ( workspaceName ) {
640
640
state . addedInWorkspaces . add ( workspaceName )
641
641
}
642
642
}
@@ -646,55 +646,58 @@ async function addOverrides(
646
646
} )
647
647
}
648
648
}
649
- // Chunk package names to process them in parallel 3 at a time.
650
- await pEach ( overridesDataObjects , 3 , async ( { overrides, type } ) => {
651
- const overrideExists = hasOwn ( overrides , origPkgName )
652
- if ( overrideExists || thingScanner ( thingToScan , origPkgName ) ) {
653
- const oldSpec = overrideExists ? overrides [ origPkgName ] : undefined
654
- const depAlias = depAliasMap . get ( origPkgName )
655
- const regSpecStartsLike = `npm:${ regPkgName } @`
656
- let newSpec = `${ regSpecStartsLike } ^${ pin ? version : major } `
657
- let thisVersion = version
658
- if ( depAlias && type === 'npm' ) {
659
- // With npm one may not set an override for a package that one directly
660
- // depends on unless both the dependency and the override itself share
661
- // the exact same spec. To make this limitation easier to deal with,
662
- // overrides may also be defined as a reference to a spec for a direct
663
- // dependency by prefixing the name of the package to match the version
664
- // of with a $.
665
- // https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
666
- newSpec = `$${ origPkgName } `
667
- } else if ( overrideExists ) {
668
- const thisSpec = oldSpec . startsWith ( '$' )
669
- ? ( depAlias ?. id ?? newSpec )
670
- : ( oldSpec ?? newSpec )
671
- if ( thisSpec . startsWith ( regSpecStartsLike ) ) {
672
- if ( pin ) {
673
- thisVersion =
674
- semver . major (
675
- semver . coerce ( npa ( thisSpec ) . rawSpec ) ?. version ?? version
676
- ) === major
677
- ? version
678
- : ( ( await fetchPackageManifest ( thisSpec ) ) ?. version ?? version )
649
+ if ( isRoot ) {
650
+ // Chunk package names to process them in parallel 3 at a time.
651
+ await pEach ( overridesDataObjects , 3 , async ( { overrides, type } ) => {
652
+ const overrideExists = hasOwn ( overrides , origPkgName )
653
+ if ( overrideExists || thingScanner ( thingToScan , origPkgName ) ) {
654
+ const oldSpec = overrideExists ? overrides [ origPkgName ] : undefined
655
+ const depAlias = depAliasMap . get ( origPkgName )
656
+ const regSpecStartsLike = `npm:${ regPkgName } @`
657
+ let newSpec = `${ regSpecStartsLike } ^${ pin ? version : major } `
658
+ let thisVersion = version
659
+ if ( depAlias && type === 'npm' ) {
660
+ // With npm one may not set an override for a package that one directly
661
+ // depends on unless both the dependency and the override itself share
662
+ // the exact same spec. To make this limitation easier to deal with,
663
+ // overrides may also be defined as a reference to a spec for a direct
664
+ // dependency by prefixing the name of the package to match the version
665
+ // of with a $.
666
+ // https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
667
+ newSpec = `$${ origPkgName } `
668
+ } else if ( overrideExists ) {
669
+ const thisSpec = oldSpec . startsWith ( '$' )
670
+ ? ( depAlias ?. id ?? newSpec )
671
+ : ( oldSpec ?? newSpec )
672
+ if ( thisSpec . startsWith ( regSpecStartsLike ) ) {
673
+ if ( pin ) {
674
+ thisVersion =
675
+ semver . major (
676
+ semver . coerce ( npa ( thisSpec ) . rawSpec ) ?. version ?? version
677
+ ) === major
678
+ ? version
679
+ : ( ( await fetchPackageManifest ( thisSpec ) ) ?. version ??
680
+ version )
681
+ }
682
+ newSpec = `${ regSpecStartsLike } ^${ pin ? thisVersion : semver . major ( thisVersion ) } `
683
+ } else {
684
+ newSpec = oldSpec
679
685
}
680
- newSpec = `${ regSpecStartsLike } ^${ pin ? thisVersion : semver . major ( thisVersion ) } `
681
- } else {
682
- newSpec = oldSpec
683
686
}
684
- }
685
- if ( newSpec !== oldSpec ) {
686
- overrides [ origPkgName ] = newSpec
687
- const addedOrUpdated = overrideExists ? 'updated' : 'added'
688
- state [ addedOrUpdated ] . add ( regPkgName )
689
- if ( isWorkspace ) {
690
- const addedOrUpdatedIn = overrideExists
691
- ? 'updatedInWorkspaces '
692
- : 'addedInWorkspaces'
693
- state [ addedOrUpdatedIn ] . add ( workspaceName )
687
+ if ( newSpec !== oldSpec ) {
688
+ overrides [ origPkgName ] = newSpec
689
+ const addedOrUpdated = overrideExists ? 'updated' : 'added'
690
+ state [ addedOrUpdated ] . add ( regPkgName )
691
+ if ( workspaceName ) {
692
+ const addedOrUpdatedIn = overrideExists
693
+ ? 'updatedInWorkspaces'
694
+ : 'addedInWorkspaces '
695
+ state [ addedOrUpdatedIn ] . add ( workspaceName )
696
+ }
694
697
}
695
698
}
696
- }
697
- } )
699
+ } )
700
+ }
698
701
} )
699
702
if ( workspaceGlobs ) {
700
703
const workspacePkgJsonPaths = await tinyGlob ( workspaceGlobs , {
0 commit comments