@@ -74,9 +74,7 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
74
74
array : true ,
75
75
} )
76
76
. option ( 'force' , {
77
- description :
78
- 'Ignore peer dependency version mismatches. ' +
79
- `Passes the '--force' flag to the package manager when installing packages.` ,
77
+ description : 'Ignore peer dependency version mismatches.' ,
80
78
type : 'boolean' ,
81
79
default : false ,
82
80
} )
@@ -225,7 +223,7 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
225
223
226
224
const workflow = new NodeWorkflow ( this . context . root , {
227
225
packageManager : packageManager . name ,
228
- packageManagerForce : options . force ,
226
+ packageManagerForce : this . packageManagerForce ( options . verbose ) ,
229
227
// __dirname -> favor @schematics/update from this package
230
228
// Otherwise, use packages from the active workspace (migrations)
231
229
resolvePaths : [ __dirname , this . context . root ] ,
@@ -686,26 +684,8 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
686
684
} ) ;
687
685
} catch { }
688
686
689
- let forceInstall = false ;
690
- // npm 7+ can fail due to it incorrectly resolving peer dependencies that have valid SemVer
691
- // ranges during an update. Update will set correct versions of dependencies within the
692
- // package.json file. The force option is set to workaround these errors.
693
- // Example error:
694
- // npm ERR! Conflicting peer dependency: @angular/[email protected]
695
- // npm ERR! node_modules/@angular/compiler-cli
696
- // npm ERR! peer @angular/compiler-cli@"^14.0.0 || ^14.0.0-rc" from @angular-devkit/[email protected]
697
- // npm ERR! node_modules/@angular-devkit/build-angular
698
- // npm ERR! dev @angular-devkit/build-angular@"~14.0.0-rc.0" from the root project
699
- if (
700
- this . context . packageManager . name === PackageManager . Npm &&
701
- this . context . packageManager . version &&
702
- semver . gte ( this . context . packageManager . version , '7.0.0' , { includePrerelease : true } )
703
- ) {
704
- logVerbose ( 'NPM 7+ detected -- enabling force option for package installation' ) ;
705
- forceInstall = true ;
706
- }
707
687
const installationSuccess = await this . context . packageManager . installAll (
708
- forceInstall ? [ '--force' ] : [ ] ,
688
+ this . packageManagerForce ( options . verbose ) ? [ '--force' ] : [ ] ,
709
689
this . context . root ,
710
690
) ;
711
691
@@ -980,6 +960,33 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
980
960
981
961
return status ?? 0 ;
982
962
}
963
+
964
+ private packageManagerForce ( verbose : boolean ) : boolean {
965
+ // npm 7+ can fail due to it incorrectly resolving peer dependencies that have valid SemVer
966
+ // ranges during an update. Update will set correct versions of dependencies within the
967
+ // package.json file. The force option is set to workaround these errors.
968
+ // Example error:
969
+ // npm ERR! Conflicting peer dependency: @angular/[email protected]
970
+ // npm ERR! node_modules/@angular/compiler-cli
971
+ // npm ERR! peer @angular/compiler-cli@"^14.0.0 || ^14.0.0-rc" from @angular-devkit/[email protected]
972
+ // npm ERR! node_modules/@angular-devkit/build-angular
973
+ // npm ERR! dev @angular-devkit/build-angular@"~14.0.0-rc.0" from the root project
974
+ if (
975
+ this . context . packageManager . name === PackageManager . Npm &&
976
+ this . context . packageManager . version &&
977
+ semver . gte ( this . context . packageManager . version , '7.0.0' , { includePrerelease : true } )
978
+ ) {
979
+ if ( verbose ) {
980
+ this . context . logger . info (
981
+ 'NPM 7+ detected -- enabling force option for package installation' ,
982
+ ) ;
983
+ }
984
+
985
+ return true ;
986
+ }
987
+
988
+ return false ;
989
+ }
983
990
}
984
991
985
992
/**
0 commit comments