From 07a6116376d93cf2770277c61f57afaa7c4a89b9 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Wed, 30 May 2018 14:12:44 +0100 Subject: [PATCH] fix(@schematics/update): stabilize package list before continuing Fix https://github.com/angular/angular-cli/issues/10875 --- packages/schematics/update/update/index.ts | 14 ++++++++++---- packages/schematics/update/update/index_spec.ts | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/schematics/update/update/index.ts b/packages/schematics/update/update/index.ts index c2e00a0c11f3..20b4f3f65ff2 100644 --- a/packages/schematics/update/update/index.ts +++ b/packages/schematics/update/update/index.ts @@ -790,10 +790,16 @@ export default function(options: UpdateSchema): Rule { map(npmPackageJsonMap => { // Augment the command line package list with packageGroups and forward peer dependencies. - npmPackageJsonMap.forEach((npmPackageJson) => { - _addPackageGroup(packages, allDependencies, npmPackageJson, logger); - _addPeerDependencies(packages, allDependencies, npmPackageJson, logger); - }); + // Each added package may uncover new package groups and peer dependencies, so we must + // repeat this process until the package list stabilizes. + let lastPackagesSize; + do { + lastPackagesSize = packages.size; + npmPackageJsonMap.forEach((npmPackageJson) => { + _addPackageGroup(packages, allDependencies, npmPackageJson, logger); + _addPeerDependencies(packages, allDependencies, npmPackageJson, logger); + }); + } while (packages.size > lastPackagesSize); // Build the PackageInfo for each module. const packageInfoMap = new Map(); diff --git a/packages/schematics/update/update/index_spec.ts b/packages/schematics/update/update/index_spec.ts index 99a2c9964b78..448620e9b014 100644 --- a/packages/schematics/update/update/index_spec.ts +++ b/packages/schematics/update/update/index_spec.ts @@ -161,9 +161,11 @@ describe('@schematics/update', () => { dependencies['@angular/animations'] = '5.1.0'; dependencies['@angular/common'] = '5.1.0'; dependencies['@angular/compiler'] = '5.1.0'; + dependencies['@angular/compiler-cli'] = '5.1.0'; dependencies['@angular/platform-browser'] = '5.1.0'; dependencies['rxjs'] = '5.5.0'; dependencies['zone.js'] = '0.8.26'; + dependencies['typescript'] = '2.4.2'; host.sync.write( normalize('/package.json'), virtualFs.stringToFileBuffer(JSON.stringify(packageJson)), @@ -176,6 +178,9 @@ describe('@schematics/update', () => { map(tree => { const packageJson = JSON.parse(tree.readContent('/package.json')); expect(packageJson['dependencies']['@angular/core'][0]).toBe('6'); + expect(packageJson['dependencies']['rxjs'][0]).toBe('6'); + expect(packageJson['dependencies']['typescript'][0]).toBe('2'); + expect(packageJson['dependencies']['typescript'][2]).toBe('7'); // Check install task. expect(schematicRunner.tasks).toEqual([