From 9b5653b13e2ea6085884fb608a6a1f9362f884ce 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] 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()); + } + }; +}