Skip to content

Commit aeaa97c

Browse files
alan-agius4mgechev
authored andcommitted
feat(@schematics/angular): add migration for dependencies (#15421)
1 parent 99d4fd6 commit aeaa97c

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77
*/
88

99
import { Rule, chain } from '@angular-devkit/schematics';
10+
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
1011
import { UpdateLibraries } from './ivy-libraries';
12+
import { updateDependencies } from './update-dependencies';
1113
import { UpdateWorkspaceConfig } from './update-workspace-config';
1214

1315
export default function(): Rule {
1416
return () => {
1517
return chain([
1618
UpdateWorkspaceConfig(),
1719
UpdateLibraries(),
20+
updateDependencies(),
21+
(tree, context) => {
22+
const packageChanges = tree.actions.some(a => a.path.endsWith('/package.json'));
23+
if (packageChanges) {
24+
context.addTask(new NodePackageInstallTask());
25+
}
26+
},
1827
]);
1928
};
2029
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 { Tree } from '@angular-devkit/schematics';
9+
import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies';
10+
import { latestVersions } from '../../utility/latest-versions';
11+
12+
export function updateDependencies() {
13+
return (host: Tree) => {
14+
const dependenciesToUpdate: Record<string, string> = {
15+
'@angular/pwa': latestVersions.AngularPWA,
16+
'@angular-devkit/build-angular': latestVersions.DevkitBuildAngular,
17+
'@angular-devkit/build-ng-packagr': latestVersions.DevkitBuildNgPackagr,
18+
'@angular-devkit/build-webpack': latestVersions.DevkitBuildWebpack,
19+
'zone.js': latestVersions.ZoneJs,
20+
tsickle: latestVersions.tsickle,
21+
'ng-packagr': latestVersions.ngPackagr,
22+
'web-animations-js': '^2.3.2',
23+
};
24+
25+
for (const [name, version] of Object.entries(dependenciesToUpdate)) {
26+
const current = getPackageJsonDependency(host, name);
27+
if (!current || current.version === version) {
28+
continue;
29+
}
30+
31+
addPackageJsonDependency(host, {
32+
type: current.type,
33+
name,
34+
version,
35+
overwrite: true,
36+
});
37+
}
38+
};
39+
}

0 commit comments

Comments
 (0)