@@ -75,9 +75,7 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
7575 array : true ,
7676 } )
7777 . 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.' ,
8179 type : 'boolean' ,
8280 default : false ,
8381 } )
@@ -227,7 +225,7 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
227225
228226 const workflow = new NodeWorkflow ( this . context . root , {
229227 packageManager : packageManager . name ,
230- packageManagerForce : options . force ,
228+ packageManagerForce : this . packageManagerForce ( options . verbose ) ,
231229 // __dirname -> favor @schematics/update from this package
232230 // Otherwise, use packages from the active workspace (migrations)
233231 resolvePaths : [ __dirname , this . context . root ] ,
@@ -693,26 +691,8 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
693691 } ) ;
694692 } catch { }
695693
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/compiler-cli@14.0.0-rc.0
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/build-angular@14.0.0-rc.0
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- }
714694 const installationSuccess = await this . context . packageManager . installAll (
715- forceInstall ? [ '--force' ] : [ ] ,
695+ this . packageManagerForce ( options . verbose ) ? [ '--force' ] : [ ] ,
716696 this . context . root ,
717697 ) ;
718698
@@ -992,6 +972,33 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
992972
993973 return status ?? 0 ;
994974 }
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/compiler-cli@14.0.0-rc.0
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/build-angular@14.0.0-rc.0
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+ }
9951002}
9961003
9971004/**
0 commit comments