From 629396edf3e8f038d8fbbb34fcae2713b98341c2 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 22 Apr 2019 13:59:58 -0400 Subject: [PATCH 1/2] fix(@schematics/angular): ensure Angular builders are migrated to latest versions The package group format required to automatically update the builder packages was not supported until CLI 7.2. For older CLI versions performing the update, this new migration will update the builders instead. Once the CLI is updated to at least 7.2, the update algorithm itself will handle the update. --- .../angular/migrations/update-8/index.ts | 2 + .../migrations/update-8/update-builders.ts | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 packages/schematics/angular/migrations/update-8/update-builders.ts diff --git a/packages/schematics/angular/migrations/update-8/index.ts b/packages/schematics/angular/migrations/update-8/index.ts index 2916796169f5..a6eef2d88642 100644 --- a/packages/schematics/angular/migrations/update-8/index.ts +++ b/packages/schematics/angular/migrations/update-8/index.ts @@ -13,6 +13,7 @@ import { import { updatePackageJson, updateTsLintConfig } from './codelyzer-5'; import { updateES5Projects } from './differential-loading'; import { dropES2015Polyfills } from './drop-es6-polyfills'; +import { updateBuilders } from './update-builders'; export { updateLazyModulePaths } from './update-lazy-module-paths'; @@ -23,6 +24,7 @@ export default function(): Rule { updatePackageJson(), dropES2015Polyfills(), updateES5Projects(), + updateBuilders(), ]); }; } diff --git a/packages/schematics/angular/migrations/update-8/update-builders.ts b/packages/schematics/angular/migrations/update-8/update-builders.ts new file mode 100644 index 000000000000..92e59007081d --- /dev/null +++ b/packages/schematics/angular/migrations/update-8/update-builders.ts @@ -0,0 +1,49 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +import { SchematicContext, Tree } from '@angular-devkit/schematics'; +import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; +import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies'; +import { latestVersions } from '../../utility/latest-versions'; + +export function updateBuilders() { + return (host: Tree, context: SchematicContext) => { + let updates = false; + + let current = getPackageJsonDependency(host, '@angular-devkit/build-angular'); + if (current && current.version !== latestVersions.DevkitBuildAngular) { + updates = true; + addPackageJsonDependency( + host, + { + type: current.type, + name: '@angular-devkit/build-angular', + version: latestVersions.DevkitBuildAngular, + overwrite: true, + }, + ); + } + + current = getPackageJsonDependency(host, '@angular-devkit/build-ng-packagr'); + if (current && current.version !== latestVersions.DevkitBuildNgPackagr) { + updates = true; + addPackageJsonDependency( + host, + { + type: current.type, + name: '@angular-devkit/build-ng-packagr', + version: latestVersions.DevkitBuildNgPackagr, + overwrite: true, + }, + ); + } + + if (updates) { + context.addTask(new NodePackageInstallTask()); + } + }; +} From 95bf71bbd28810a587531bb228dd947706a9bba9 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 22 Apr 2019 14:45:19 -0400 Subject: [PATCH 2/2] fix(@schematics/angular): skip E2E projects when migrating browserslist --- .../angular/migrations/update-8/differential-loading.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/schematics/angular/migrations/update-8/differential-loading.ts b/packages/schematics/angular/migrations/update-8/differential-loading.ts index dcc7084a058d..badc3a320b6f 100644 --- a/packages/schematics/angular/migrations/update-8/differential-loading.ts +++ b/packages/schematics/angular/migrations/update-8/differential-loading.ts @@ -88,14 +88,17 @@ function updateBrowserlist(): Rule { } // For all projects - for (const projectName of Object.keys(angularJson.projects)) { - const project = angularJson.projects[projectName]; + for (const [name, project] of Object.entries(angularJson.projects)) { if (!isJsonObject(project)) { continue; } if (typeof project.root != 'string' || project.projectType !== 'application') { continue; } + if (name.endsWith('-e2e')) { + // Skip existing separate E2E projects + continue; + } const browserslistPath = join(normalize(project.root), '/browserslist'); const source = tree.read(browserslistPath);