Skip to content

Commit

Permalink
fix(@schematics/angular): ensure Angular builders are migrated to lat…
Browse files Browse the repository at this point in the history
…est 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.
  • Loading branch information
clydin authored and alexeagle committed Apr 22, 2019
1 parent 36be8cd commit 9b5653b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/schematics/angular/migrations/update-8/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -23,6 +24,7 @@ export default function(): Rule {
updatePackageJson(),
dropES2015Polyfills(),
updateES5Projects(),
updateBuilders(),
]);
};
}
49 changes: 49 additions & 0 deletions packages/schematics/angular/migrations/update-8/update-builders.ts
Original file line number Diff line number Diff line change
@@ -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());
}
};
}

0 comments on commit 9b5653b

Please sign in to comment.