Skip to content

Commit 5125db3

Browse files
Alan AgiusKeen Yee Liau
authored andcommitted
fix(@schematics/angular): differential loading migration should run only for projects using @angular-devkit/build-angular:browser
Differential loading migration should run only when the project is using `@angular-devkit/build-angular:browser` as it's browser builder. Otherwise we might break applications that are using different builders. Fixes #14389
1 parent fc05076 commit 5125db3

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

packages/schematics/angular/migrations/update-8/differential-loading.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,26 @@ function updateProjects(): Rule {
9797
}
9898

9999
// Older projects app and spec ts configs had script and module set in them.
100-
const tsConfigs = [];
101100
const architect = project.architect;
102-
if (isJsonObject(architect)
101+
if (!(isJsonObject(architect)
103102
&& isJsonObject(architect.build)
104-
&& isJsonObject(architect.build.options)
105-
&& typeof architect.build.options.tsConfig === 'string') {
106-
tsConfigs.push(architect.build.options.tsConfig);
103+
&& architect.build.builder === '@angular-devkit/build-angular:browser')
104+
) {
105+
// Skip projects who's build builder is not build-angular:browser
106+
continue;
107+
}
108+
109+
const tsConfigs = [];
110+
const buildOptionsConfig = architect.build.options;
111+
if (isJsonObject(buildOptionsConfig) && typeof buildOptionsConfig.tsConfig === 'string') {
112+
tsConfigs.push(buildOptionsConfig.tsConfig);
107113
}
108114

109-
if (isJsonObject(architect)
110-
&& isJsonObject(architect.test)
111-
&& isJsonObject(architect.test.options)
112-
&& typeof architect.test.options.tsConfig === 'string') {
113-
tsConfigs.push(architect.test.options.tsConfig);
115+
const testConfig = architect.test;
116+
if (isJsonObject(testConfig)
117+
&& isJsonObject(testConfig.options)
118+
&& typeof testConfig.options.tsConfig === 'string') {
119+
tsConfigs.push(testConfig.options.tsConfig);
114120
}
115121

116122
for (const tsConfig of tsConfigs) {

packages/schematics/angular/migrations/update-8/differential-loading_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,19 @@ describe('Migration to version 8', () => {
113113
expect(specsCompilerOptions.target).toBeUndefined();
114114
expect(specsCompilerOptions.module).toBeUndefined();
115115
});
116+
117+
it(`should not update projects which browser builder is not 'build-angular:browser'`, () => {
118+
tree.delete('/browserslist');
119+
const config = JSON.parse(tree.readContent('angular.json'));
120+
config
121+
.projects['migration-test']
122+
.architect
123+
.build
124+
.builder = '@dummy/builders:browser';
125+
126+
tree.overwrite('angular.json', JSON.stringify(config));
127+
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
128+
expect(tree2.exists('/browserslist')).toBe(false);
129+
});
116130
});
117131
});

0 commit comments

Comments
 (0)