@@ -74,9 +74,7 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
7474 array : true ,
7575 } )
7676 . 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.' ,
8078 type : 'boolean' ,
8179 default : false ,
8280 } )
@@ -225,7 +223,7 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
225223
226224 const workflow = new NodeWorkflow ( this . context . root , {
227225 packageManager : packageManager . name ,
228- packageManagerForce : options . force ,
226+ packageManagerForce : this . packageManagerForce ( options . verbose ) ,
229227 // __dirname -> favor @schematics/update from this package
230228 // Otherwise, use packages from the active workspace (migrations)
231229 resolvePaths : [ __dirname , this . context . root ] ,
@@ -686,26 +684,8 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
686684 } ) ;
687685 } catch { }
688686
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/compiler-cli@14.0.0-rc.0
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/build-angular@14.0.0-rc.0
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- }
707687 const installationSuccess = await this . context . packageManager . installAll (
708- forceInstall ? [ '--force' ] : [ ] ,
688+ this . packageManagerForce ( options . verbose ) ? [ '--force' ] : [ ] ,
709689 this . context . root ,
710690 ) ;
711691
@@ -980,6 +960,33 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
980960
981961 return status ?? 0 ;
982962 }
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/compiler-cli@14.0.0-rc.0
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/build-angular@14.0.0-rc.0
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+ }
983990}
984991
985992/**
0 commit comments