Skip to content

Commit 8d66912

Browse files
alan-agius4filipesilva
authored andcommitted
refactor(@angular-devkit/build-angular): remove deprecated lazyModules option
BREAKING CHANGE: Server and Browser builder `lazyModules` option has been removed without replacement.
1 parent 0dc7327 commit 8d66912

File tree

9 files changed

+25
-168
lines changed

9 files changed

+25
-168
lines changed

packages/angular_devkit/build_angular/src/browser/schema.json

-9
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,6 @@
353353
"description": "Run the TypeScript type checker in a forked process.",
354354
"default": true
355355
},
356-
"lazyModules": {
357-
"description": "List of additional NgModule files that will be lazy loaded. Lazy router modules will be discovered automatically.",
358-
"type": "array",
359-
"items": {
360-
"type": "string"
361-
},
362-
"x-deprecated": "'SystemJsNgModuleLoader' is deprecated, and this is part of its usage. Use 'import()' syntax instead.",
363-
"default": []
364-
},
365356
"budgets": {
366357
"description": "Budget thresholds to ensure parts of your application stay within boundaries which you set.",
367358
"type": "array",

packages/angular_devkit/build_angular/src/browser/specs/lazy-module_spec.ts

+21-97
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
host,
1717
lazyModuleFiles,
1818
lazyModuleFnImport,
19-
lazyModuleStringImport,
2019
veEnabled,
2120
} from '../../test-utils';
2221

@@ -54,40 +53,30 @@ describe('Browser Builder lazy modules', () => {
5453
logs.includes('Module not found');
5554
}
5655

57-
const cases: [string, Record<string, string>][] = [
58-
['string', lazyModuleStringImport],
59-
['function', lazyModuleFnImport],
60-
];
61-
for (const [name, imports] of cases) {
62-
describe(`Load children ${name} syntax`, () => {
63-
it('supports lazy bundle for lazy routes with JIT', async () => {
64-
host.writeMultipleFiles(lazyModuleFiles);
65-
host.writeMultipleFiles(imports);
66-
67-
if (name === 'string') {
68-
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
69-
}
70-
71-
const { files } = await browserBuild(architect, host, target);
72-
expect('lazy-lazy-module.js' in files).toBe(true);
73-
});
56+
describe(`Load children syntax`, () => {
57+
it('supports lazy bundle for lazy routes with JIT', async () => {
58+
host.writeMultipleFiles(lazyModuleFiles);
59+
host.writeMultipleFiles(lazyModuleFnImport);
7460

75-
it('supports lazy bundle for lazy routes with AOT', async () => {
76-
host.writeMultipleFiles(lazyModuleFiles);
77-
host.writeMultipleFiles(imports);
78-
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
61+
const { files } = await browserBuild(architect, host, target);
62+
expect('lazy-lazy-module.js' in files).toBe(true);
63+
});
7964

80-
const { files } = await browserBuild(architect, host, target, { aot: true });
81-
if (!veEnabled) {
82-
const data = await files['lazy-lazy-module.js'];
83-
expect(data).not.toBeUndefined('Lazy module output bundle does not exist');
84-
expect(data).toContain('LazyModule.ɵmod');
85-
} else {
86-
expect(files['lazy-lazy-module-ngfactory.js']).not.toBeUndefined();
87-
}
88-
});
65+
it('supports lazy bundle for lazy routes with AOT', async () => {
66+
host.writeMultipleFiles(lazyModuleFiles);
67+
host.writeMultipleFiles(lazyModuleFnImport);
68+
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
69+
70+
const { files } = await browserBuild(architect, host, target, { aot: true });
71+
if (!veEnabled) {
72+
const data = await files['lazy-lazy-module.js'];
73+
expect(data).not.toBeUndefined('Lazy module output bundle does not exist');
74+
expect(data).toContain('LazyModule.ɵmod');
75+
} else {
76+
expect(files['lazy-lazy-module-ngfactory.js']).not.toBeUndefined();
77+
}
8978
});
90-
}
79+
});
9180

9281
// Errors for missing lazy routes are only supported with function syntax.
9382
// `ngProgram.listLazyRoutes` will ignore invalid lazy routes in the route map.
@@ -202,69 +191,4 @@ describe('Browser Builder lazy modules', () => {
202191
expect(files['two.js']).not.toBeUndefined();
203192
expect(files['common.js']).toBeUndefined();
204193
});
205-
206-
it(`supports extra lazy modules array in JIT`, async () => {
207-
host.writeMultipleFiles(lazyModuleFiles);
208-
host.writeMultipleFiles({
209-
'src/app/app.component.ts': `
210-
import { Component, SystemJsNgModuleLoader } from '@angular/core';
211-
212-
@Component({
213-
selector: 'app-root',
214-
templateUrl: './app.component.html',
215-
styleUrls: ['./app.component.css'],
216-
})
217-
export class AppComponent {
218-
title = 'app';
219-
constructor(loader: SystemJsNgModuleLoader) {
220-
// Module will be split at build time and loaded when requested below
221-
loader.load('src/app/lazy/lazy.module#LazyModule')
222-
.then((factory) => { /* Use factory here */ });
223-
}
224-
}`,
225-
});
226-
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
227-
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
228-
229-
const { files } = await browserBuild(architect, host, target, {
230-
lazyModules: ['src/app/lazy/lazy.module'],
231-
});
232-
expect(files['src-app-lazy-lazy-module.js']).not.toBeUndefined();
233-
});
234-
235-
it(`supports extra lazy modules array in AOT`, async () => {
236-
host.writeMultipleFiles(lazyModuleFiles);
237-
host.writeMultipleFiles({
238-
'src/app/app.component.ts': `
239-
import { Component, SystemJsNgModuleLoader } from '@angular/core';
240-
241-
@Component({
242-
selector: 'app-root',
243-
templateUrl: './app.component.html',
244-
styleUrls: ['./app.component.css'],
245-
})
246-
export class AppComponent {
247-
title = 'app';
248-
constructor(loader: SystemJsNgModuleLoader) {
249-
// Module will be split at build time and loaded when requested below
250-
loader.load('src/app/lazy/lazy.module#LazyModule')
251-
.then((factory) => { /* Use factory here */ });
252-
}
253-
}`,
254-
});
255-
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
256-
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
257-
const { files } = await browserBuild(architect, host, target, {
258-
lazyModules: ['src/app/lazy/lazy.module'],
259-
aot: true,
260-
});
261-
262-
if (!veEnabled) {
263-
const data = await files['src-app-lazy-lazy-module.js'];
264-
expect(data).not.toBeUndefined('Lazy module output bundle does not exist');
265-
expect(data).toContain('LazyModule.ɵmod');
266-
} else {
267-
expect(files['src-app-lazy-lazy-module-ngfactory.js']).not.toBeUndefined();
268-
}
269-
});
270194
});

packages/angular_devkit/build_angular/src/browser/specs/no-entry-module_spec.ts

-18
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,4 @@ describe('Browser Builder no entry module', () => {
2727

2828
await browserBuild(architect, host, target, { baseHref: '/myUrl' });
2929
});
30-
31-
it('reports warning when no bootstrap code', async () => {
32-
if (!veEnabled) {
33-
pending('Does not apply to Ivy.');
34-
35-
return;
36-
}
37-
38-
host.replaceInFile('src/main.ts', /./g, '');
39-
host.appendToFile('src/main.ts', `import './app/app.module';`);
40-
41-
const logger = new logging.Logger('');
42-
const logs: string[] = [];
43-
logger.subscribe(e => logs.push(e.message));
44-
45-
await browserBuild(architect, host, target, { baseHref: '/myUrl' }, { logger });
46-
expect(logs.join().includes('Lazy routes discovery is not enabled')).toBe(true);
47-
});
4830
});

packages/angular_devkit/build_angular/src/server/schema.json

-9
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,6 @@
228228
"description": "Run the TypeScript type checker in a forked process.",
229229
"default": true
230230
},
231-
"lazyModules": {
232-
"description": "List of additional NgModule files that will be lazy loaded. Lazy router modules will be discovered automatically.",
233-
"type": "array",
234-
"items": {
235-
"type": "string"
236-
},
237-
"x-deprecated": "'SystemJsNgModuleLoader' is deprecated, and this is part of its usage. Use 'import()' syntax instead.",
238-
"default": []
239-
},
240231
"watch": {
241232
"type": "boolean",
242233
"description": "Run build when files change.",

packages/angular_devkit/build_angular/src/test-utils.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export const lazyModuleFiles: { [path: string]: string } = {
147147
`,
148148
};
149149

150-
export const lazyModuleStringImport: { [path: string]: string } = {
150+
export const lazyModuleFnImport: { [path: string]: string } = {
151151
'src/app/app.module.ts': `
152152
import { BrowserModule } from '@angular/platform-browser';
153153
import { NgModule } from '@angular/core';
@@ -162,19 +162,12 @@ export const lazyModuleStringImport: { [path: string]: string } = {
162162
imports: [
163163
BrowserModule,
164164
RouterModule.forRoot([
165-
{ path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
165+
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
166166
])
167167
],
168168
providers: [],
169169
bootstrap: [AppComponent]
170170
})
171171
export class AppModule { }
172-
`,
173-
};
174-
175-
export const lazyModuleFnImport: { [path: string]: string } = {
176-
'src/app/app.module.ts': lazyModuleStringImport['src/app/app.module.ts'].replace(
177-
`loadChildren: './lazy/lazy.module#LazyModule'`,
178-
`loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule)`,
179-
),
172+
`,
180173
};

packages/angular_devkit/build_angular/src/utils/build-options.ts

-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ export interface BuildOptions {
7171
scripts: ExtraEntryPoint[];
7272
styles: ExtraEntryPoint[];
7373
stylePreprocessorOptions?: { includePaths: string[] };
74-
/** @deprecated SystemJsNgModuleLoader is deprecated, and this is part of its usage. */
75-
lazyModules: string[];
7674
platform?: 'browser' | 'server';
7775
fileReplacements: NormalizedFileReplacement[];
7876

packages/angular_devkit/build_angular/src/utils/normalize-builder-schema.ts

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export function normalizeBrowserSchema(
5959
&& options.stylePreprocessorOptions.includePaths
6060
|| [],
6161
},
62-
lazyModules: options.lazyModules || [],
6362
// Using just `--poll` will result in a value of 0 which is very likely not the intention
6463
// A value of 0 is falsy and will disable polling rather then enable
6564
// 500 ms is a sensible default in this case

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
503503
plugins: [
504504
// Always replace the context for the System.import in angular/core to prevent warnings.
505505
// https://github.com/angular/angular/issues/11580
506-
// With VE the correct context is added in @ngtools/webpack, but Ivy doesn't need it at all.
507-
new ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)/),
506+
new ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)/, projectRoot, {}),
508507
new DedupeModuleResolvePlugin({ verbose: buildOptions.verbose }),
509508
...extraPlugins,
510509
],

packages/angular_devkit/build_angular/src/webpack/configs/typescript.ts

-20
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ function canUseIvyPlugin(wco: WebpackConfigOptions): boolean {
3636
return false;
3737
}
3838

39-
// Lazy modules option uses the deprecated string format for lazy routes
40-
if (wco.buildOptions.lazyModules && wco.buildOptions.lazyModules.length > 0) {
41-
return false;
42-
}
43-
4439
return true;
4540
}
4641

@@ -131,27 +126,15 @@ function _createAotPlugin(
131126
compilerOptions.enableIvy = false;
132127
}
133128

134-
const additionalLazyModules: { [module: string]: string } = {};
135-
if (buildOptions.lazyModules) {
136-
for (const lazyModule of buildOptions.lazyModules) {
137-
additionalLazyModules[lazyModule] = path.resolve(
138-
root,
139-
lazyModule,
140-
);
141-
}
142-
}
143-
144129
let pluginOptions: AngularCompilerPluginOptions = {
145130
mainPath: path.join(root, buildOptions.main),
146131
...i18nFileAndFormat,
147132
locale: buildOptions.i18nLocale,
148133
platform: buildOptions.platform === 'server' ? PLATFORM.Server : PLATFORM.Browser,
149134
missingTranslation: buildOptions.i18nMissingTranslation,
150135
sourceMap: buildOptions.sourceMap.scripts,
151-
additionalLazyModules,
152136
nameLazyFiles: buildOptions.namedChunks,
153137
forkTypeChecker: buildOptions.forkTypeChecker,
154-
contextElementDependencyConstructor: require('webpack/lib/dependencies/ContextElementDependency'),
155138
logger: wco.logger,
156139
directTemplateLoading: true,
157140
...options,
@@ -246,12 +229,9 @@ export function getTypescriptWorkerPlugin(wco: WebpackConfigOptions, workerTsCon
246229
platform: PLATFORM.Browser,
247230
sourceMap: buildOptions.sourceMap.scripts,
248231
forkTypeChecker: buildOptions.forkTypeChecker,
249-
contextElementDependencyConstructor: require('webpack/lib/dependencies/ContextElementDependency'),
250232
logger: wco.logger,
251233
// Run no transformers.
252234
platformTransformers: [],
253-
// Don't attempt lazy route discovery.
254-
discoverLazyRoutes: false,
255235
};
256236

257237
pluginOptions = _pluginOptionsOverrides(buildOptions, pluginOptions);

0 commit comments

Comments
 (0)