Skip to content

Commit 537bf5e

Browse files
clydinalexeagle
authored andcommitted
fix(@schematics/angular): reduce package installs for 8.0 migrations (angular#14324)
This provides a ~30% performance improvement for a hello world project.
1 parent b9479b5 commit 537bf5e

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

packages/schematics/angular/migrations/update-8/codelyzer-5.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
import { JsonParseMode, parseJsonAst } from '@angular-devkit/core';
1010
import {
1111
Rule,
12-
SchematicContext,
1312
Tree,
1413
} from '@angular-devkit/schematics';
15-
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
1614
import {
1715
NodeDependency,
1816
NodeDependencyType,
@@ -78,7 +76,7 @@ export const updateTsLintConfig = (): Rule => {
7876
};
7977

8078
export const updatePackageJson = () => {
81-
return (host: Tree, context: SchematicContext) => {
79+
return (host: Tree) => {
8280
const dependency: NodeDependency = {
8381
type: NodeDependencyType.Dev,
8482
name: 'codelyzer',
@@ -87,8 +85,5 @@ export const updatePackageJson = () => {
8785
};
8886

8987
addPackageJsonDependency(host, dependency);
90-
context.addTask(new NodePackageInstallTask());
91-
92-
return host;
9388
};
9489
};

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {
10-
Rule,
11-
chain,
12-
} from '@angular-devkit/schematics';
9+
import { Rule, chain } from '@angular-devkit/schematics';
10+
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
1311
import { updatePackageJson, updateTsLintConfig } from './codelyzer-5';
1412
import { updateES5Projects } from './differential-loading';
1513
import { dropES2015Polyfills } from './drop-es6-polyfills';
@@ -27,6 +25,12 @@ export default function(): Rule {
2725
updateES5Projects(),
2826
updateBuilders(),
2927
removeAngularHttp(),
28+
(tree, context) => {
29+
const packageChanges = tree.actions.some(a => a.path.endsWith('/package.json'));
30+
if (packageChanges) {
31+
context.addTask(new NodePackageInstallTask());
32+
}
33+
},
3034
]);
3135
};
3236
}

packages/schematics/angular/migrations/update-8/remove-angular-http.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { SchematicContext, Tree } from '@angular-devkit/schematics';
10-
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
9+
import { Tree } from '@angular-devkit/schematics';
1110
import { removePackageJsonDependency } from '../../utility/dependencies';
1211

1312
export const removeAngularHttp = () => {
14-
return (host: Tree, context: SchematicContext) => {
13+
return (host: Tree) => {
1514
removePackageJsonDependency(host, '@angular/http');
16-
context.addTask(new NodePackageInstallTask());
17-
18-
return host;
1915
};
2016
};

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { SchematicContext, Tree } from '@angular-devkit/schematics';
9-
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
8+
import { Tree } from '@angular-devkit/schematics';
109
import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies';
1110
import { latestVersions } from '../../utility/latest-versions';
1211

1312
export function updateBuilders() {
14-
return (host: Tree, context: SchematicContext) => {
15-
let updates = false;
16-
13+
return (host: Tree) => {
1714
let current = getPackageJsonDependency(host, '@angular-devkit/build-angular');
1815
if (current && current.version !== latestVersions.DevkitBuildAngular) {
19-
updates = true;
2016
addPackageJsonDependency(
2117
host,
2218
{
@@ -30,7 +26,6 @@ export function updateBuilders() {
3026

3127
current = getPackageJsonDependency(host, '@angular-devkit/build-ng-packagr');
3228
if (current && current.version !== latestVersions.DevkitBuildNgPackagr) {
33-
updates = true;
3429
addPackageJsonDependency(
3530
host,
3631
{
@@ -44,7 +39,6 @@ export function updateBuilders() {
4439

4540
current = getPackageJsonDependency(host, 'zone.js');
4641
if (current && current.version !== latestVersions.ZoneJs) {
47-
updates = true;
4842
addPackageJsonDependency(
4943
host,
5044
{
@@ -55,9 +49,5 @@ export function updateBuilders() {
5549
},
5650
);
5751
}
58-
59-
if (updates) {
60-
context.addTask(new NodePackageInstallTask());
61-
}
6252
};
6353
}

0 commit comments

Comments
 (0)