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