Skip to content

Commit 03a6ac4

Browse files
committed
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.
1 parent 96fe768 commit 03a6ac4

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

packages/schematics/angular/migrations/update-8/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { updatePackageJson, updateTsLintConfig } from './codelyzer-5';
1414
import { updateES5Projects } from './differential-loading';
1515
import { dropES2015Polyfills } from './drop-es6-polyfills';
16+
import { updateBuilders } from './update-builders';
1617

1718
export { updateLazyModulePaths } from './update-lazy-module-paths';
1819

@@ -23,6 +24,7 @@ export default function(): Rule {
2324
updatePackageJson(),
2425
dropES2015Polyfills(),
2526
updateES5Projects(),
27+
updateBuilders(),
2628
]);
2729
};
2830
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { SchematicContext, Tree } from '@angular-devkit/schematics';
9+
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
10+
import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies';
11+
import { latestVersions } from '../../utility/latest-versions';
12+
13+
export function updateBuilders() {
14+
return (host: Tree, context: SchematicContext) => {
15+
let updates = false;
16+
17+
let current = getPackageJsonDependency(host, '@angular-devkit/build-angular');
18+
if (current && current.version !== latestVersions.DevkitBuildAngular) {
19+
updates = true;
20+
addPackageJsonDependency(
21+
host,
22+
{
23+
type: current.type,
24+
name: '@angular-devkit/build-angular',
25+
version: latestVersions.DevkitBuildAngular,
26+
overwrite: true,
27+
},
28+
);
29+
}
30+
31+
current = getPackageJsonDependency(host, '@angular-devkit/build-ng-packagr');
32+
if (current && current.version !== latestVersions.DevkitBuildNgPackagr) {
33+
updates = true;
34+
addPackageJsonDependency(
35+
host,
36+
{
37+
type: current.type,
38+
name: '@angular-devkit/build-ng-packagr',
39+
version: latestVersions.DevkitBuildNgPackagr,
40+
overwrite: true,
41+
},
42+
);
43+
}
44+
45+
if (updates) {
46+
context.addTask(new NodePackageInstallTask());
47+
}
48+
};
49+
};

0 commit comments

Comments
 (0)