Skip to content

Commit 38947d8

Browse files
alan-agius4vikerman
authored andcommitted
refactor(@angular-devkit/build-angular): remove differential loading version 1.0
1 parent c195830 commit 38947d8

File tree

10 files changed

+88
-165
lines changed

10 files changed

+88
-165
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/build-options.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ export interface BuildOptions {
8686
/* Append script target version to filename. */
8787
esVersionInFileName?: boolean;
8888

89-
/* When specified it will be used instead of the script target in the tsconfig.json. */
90-
scriptTargetOverride?: ScriptTarget;
91-
9289
experimentalRollupPass?: boolean;
9390
}
9491

@@ -106,4 +103,5 @@ export interface WebpackConfigOptions<T = BuildOptions> {
106103
tsConfig: ParsedConfiguration;
107104
tsConfigPath: string;
108105
supportES2015: boolean;
106+
differentialLoadingMode?: boolean;
109107
}

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from 'webpack';
2626
import { RawSource } from 'webpack-sources';
2727
import { AssetPatternClass, ExtraEntryPoint } from '../../../browser/schema';
28-
import { BuildBrowserFeatures, fullDifferential } from '../../../utils';
28+
import { BuildBrowserFeatures } from '../../../utils';
2929
import { manglingDisabled } from '../../../utils/mangle-options';
3030
import { BundleBudgetPlugin } from '../../plugins/bundle-budget';
3131
import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin';
@@ -62,7 +62,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
6262
const entryPoints: { [key: string]: string[] } = {};
6363

6464
const targetInFileName = getEsVersionForFileName(
65-
fullDifferential ? buildOptions.scriptTargetOverride : tsConfig.options.target,
65+
tsConfig.options.target,
6666
buildOptions.esVersionInFileName,
6767
);
6868

@@ -114,16 +114,14 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
114114
}
115115
}
116116

117-
let differentialLoadingNeeded = false;
117+
const differentialLoadingMode = !!wco.differentialLoadingMode;
118118
if (wco.buildOptions.platform !== 'server') {
119-
const buildBrowserFeatures = new BuildBrowserFeatures(
120-
projectRoot,
121-
tsConfig.options.target || ScriptTarget.ES5,
122-
);
123-
124-
differentialLoadingNeeded = buildBrowserFeatures.isDifferentialLoadingNeeded();
119+
if (differentialLoadingMode || tsConfig.options.target === ScriptTarget.ES5) {
120+
const buildBrowserFeatures = new BuildBrowserFeatures(
121+
projectRoot,
122+
tsConfig.options.target || ScriptTarget.ES5,
123+
);
125124

126-
if ((buildOptions.scriptTargetOverride || tsConfig.options.target) === ScriptTarget.ES5) {
127125
if (
128126
buildOptions.es5BrowserSupport ||
129127
(buildOptions.es5BrowserSupport === undefined && buildBrowserFeatures.isEs5SupportNeeded())
@@ -141,26 +139,21 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
141139
: [noModuleScript];
142140
}
143141

144-
// For full build differential loading we don't need to generate a seperate polyfill file
145-
// because they will be loaded exclusivly based on module and nomodule
146-
const polyfillsChunkName =
147-
fullDifferential && differentialLoadingNeeded ? 'polyfills' : 'polyfills-es5';
148-
142+
const polyfillsChunkName = 'polyfills-es5';
149143
entryPoints[polyfillsChunkName] = [path.join(__dirname, '..', 'es5-polyfills.js')];
150-
if (!fullDifferential && differentialLoadingNeeded) {
144+
if (differentialLoadingMode) {
151145
// Add zone.js legacy support to the es5 polyfills
152146
// This is a noop execution-wise if zone-evergreen is not used.
153147
entryPoints[polyfillsChunkName].push('zone.js/dist/zone-legacy');
154148
}
155149
if (!buildOptions.aot) {
156-
// If not performing a full differential build the JIT polyfills need to be added to ES5
157-
if (!fullDifferential && differentialLoadingNeeded) {
150+
if (differentialLoadingMode) {
158151
entryPoints[polyfillsChunkName].push(path.join(__dirname, '..', 'jit-polyfills.js'));
159152
}
160153
entryPoints[polyfillsChunkName].push(path.join(__dirname, '..', 'es5-jit-polyfills.js'));
161154
}
162155
// If not performing a full differential build the polyfills need to be added to ES5 bundle
163-
if (!fullDifferential && buildOptions.polyfills) {
156+
if (buildOptions.polyfills) {
164157
entryPoints[polyfillsChunkName].push(path.resolve(root, buildOptions.polyfills));
165158
}
166159
}
@@ -411,7 +404,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
411404
mangle:
412405
!manglingDisabled &&
413406
buildOptions.platform !== 'server' &&
414-
(!differentialLoadingNeeded || (differentialLoadingNeeded && fullDifferential)),
407+
!differentialLoadingMode,
415408
};
416409

417410
extraMinimizers.push(

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
NgToolsLoader,
1616
PLATFORM
1717
} from '@ngtools/webpack';
18-
import { fullDifferential } from '../../../utils';
1918
import { WebpackConfigOptions, BuildOptions } from '../build-options';
2019

2120
function _pluginOptionsOverrides(
@@ -33,10 +32,6 @@ function _pluginOptionsOverrides(
3332
}
3433
}
3534

36-
if (fullDifferential && buildOptions.scriptTargetOverride) {
37-
compilerOptions.target = buildOptions.scriptTargetOverride;
38-
}
39-
4035
if (buildOptions.preserveSymlinks) {
4136
compilerOptions.preserveSymlinks = true;
4237
}

packages/angular_devkit/build_angular/src/browser/index.ts

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
99
import {
10-
BuildResult,
1110
EmittedFiles,
1211
WebpackLoggingCallback,
1312
runWebpack,
@@ -25,7 +24,7 @@ import * as findCacheDirectory from 'find-cache-dir';
2524
import * as fs from 'fs';
2625
import * as path from 'path';
2726
import { Observable, from, of } from 'rxjs';
28-
import { bufferCount, catchError, concatMap, map, mergeScan, switchMap } from 'rxjs/operators';
27+
import { catchError, concatMap, map, switchMap } from 'rxjs/operators';
2928
import { ScriptTarget } from 'typescript';
3029
import * as webpack from 'webpack';
3130
import { NgBuildAnalyticsPlugin } from '../../plugins/webpack/analytics';
@@ -57,7 +56,6 @@ import { ExecutionTransformer } from '../transforms';
5756
import {
5857
BuildBrowserFeatures,
5958
deleteOutputDir,
60-
fullDifferential,
6159
normalizeAssetPatterns,
6260
normalizeOptimization,
6361
normalizeSourceMaps,
@@ -111,7 +109,7 @@ export async function buildBrowserWebpackConfigFromContext(
111109
options: BrowserBuilderSchema,
112110
context: BuilderContext,
113111
host: virtualFs.Host<fs.Stats> = new NodeJsSyncHost(),
114-
): Promise<{ config: webpack.Configuration[]; projectRoot: string; projectSourceRoot?: string }> {
112+
): Promise<{ config: webpack.Configuration; projectRoot: string; projectSourceRoot?: string }> {
115113
return generateBrowserWebpackConfigFromContext(
116114
options,
117115
context,
@@ -164,7 +162,7 @@ async function initialize(
164162
host: virtualFs.Host<fs.Stats>,
165163
webpackConfigurationTransform?: ExecutionTransformer<webpack.Configuration>,
166164
): Promise<{
167-
config: webpack.Configuration[];
165+
config: webpack.Configuration;
168166
projectRoot: string;
169167
projectSourceRoot?: string;
170168
i18n: I18nOptions;
@@ -182,10 +180,7 @@ async function initialize(
182180

183181
let transformedConfig;
184182
if (webpackConfigurationTransform) {
185-
transformedConfig = [];
186-
for (const c of config) {
187-
transformedConfig.push(await webpackConfigurationTransform(c));
188-
}
183+
transformedConfig = await webpackConfigurationTransform(config);
189184
}
190185

191186
if (options.deleteOutputPath) {
@@ -218,7 +213,7 @@ export function buildWebpackBrowser(
218213

219214
return from(initialize(options, context, host, transforms.webpackConfiguration)).pipe(
220215
// tslint:disable-next-line: no-big-function
221-
switchMap(({ config: configs, projectRoot, projectSourceRoot, i18n }) => {
216+
switchMap(({ config, projectRoot, projectSourceRoot, i18n }) => {
222217
const tsConfig = readTsconfig(options.tsConfig, context.workspaceRoot);
223218
const target = tsConfig.options.target || ScriptTarget.ES5;
224219
const buildBrowserFeatures = new BuildBrowserFeatures(projectRoot, target);
@@ -233,40 +228,23 @@ export function buildWebpackBrowser(
233228
`);
234229
}
235230

236-
const useBundleDownleveling =
237-
isDifferentialLoadingNeeded && !(fullDifferential || options.watch);
231+
const useBundleDownleveling = isDifferentialLoadingNeeded && !options.watch;
238232
const startTime = Date.now();
239233

240-
return from(configs).pipe(
241-
// the concurrency parameter (3rd parameter of mergeScan) is deliberately
242-
// set to 1 to make sure the build steps are executed in sequence.
243-
mergeScan(
244-
(lastResult, config) => {
245-
// Make sure to only run the 2nd build step, if 1st one succeeded
246-
if (lastResult.success) {
247-
return runWebpack(config, context, {
248-
logging:
249-
transforms.logging ||
250-
(useBundleDownleveling
251-
? () => {}
252-
: createBrowserLoggingCallback(!!options.verbose, context.logger)),
253-
});
254-
} else {
255-
return of();
256-
}
257-
},
258-
{ success: true } as BuildResult,
259-
1,
260-
),
261-
bufferCount(configs.length),
234+
return runWebpack(config, context, {
235+
logging:
236+
transforms.logging ||
237+
(useBundleDownleveling
238+
? () => {}
239+
: createBrowserLoggingCallback(!!options.verbose, context.logger)),
240+
}).pipe(
262241
// tslint:disable-next-line: no-big-function
263-
switchMap(async buildEvents => {
264-
configs.length = 0;
265-
const success = buildEvents.every(r => r.success);
242+
concatMap(async buildEvent => {
243+
const { webpackStats, success, emittedFiles = [] } = buildEvent;
244+
266245
if (!success && useBundleDownleveling) {
267246
// If using bundle downleveling then there is only one build
268247
// If it fails show any diagnostic messages and bail
269-
const webpackStats = buildEvents[0].webpackStats;
270248
if (webpackStats && webpackStats.warnings.length > 0) {
271249
context.logger.warn(statsWarningsToString(webpackStats, { colors: true }));
272250
}
@@ -285,18 +263,12 @@ export function buildWebpackBrowser(
285263
'scripts',
286264
).map(x => x.bundleName);
287265

288-
const [firstBuild, secondBuild] = buildEvents;
289-
if (isDifferentialLoadingNeeded && (fullDifferential || options.watch)) {
290-
moduleFiles = firstBuild.emittedFiles || [];
266+
if (isDifferentialLoadingNeeded && options.watch) {
267+
moduleFiles = emittedFiles;
291268
files = moduleFiles.filter(
292269
x => x.extension === '.css' || (x.name && scriptsEntryPointName.includes(x.name)),
293270
);
294-
295-
if (buildEvents.length === 2) {
296-
noModuleFiles = secondBuild.emittedFiles;
297-
}
298-
} else if (isDifferentialLoadingNeeded && !fullDifferential) {
299-
const { emittedFiles = [], webpackStats } = firstBuild;
271+
} else if (isDifferentialLoadingNeeded) {
300272
moduleFiles = [];
301273
noModuleFiles = [];
302274

@@ -526,7 +498,6 @@ export function buildWebpackBrowser(
526498
context.logger.error(statsErrorsToString(webpackStats, { colors: true }));
527499
}
528500
} else {
529-
const { emittedFiles = [] } = firstBuild;
530501
files = emittedFiles.filter(x => x.name !== 'polyfills-es5');
531502
noModuleFiles = emittedFiles.filter(x => x.name === 'polyfills-es5');
532503
}

packages/angular_devkit/build_angular/src/dev-server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function serveWebpackBrowser(
126126
);
127127

128128
// No differential loading for dev-server, hence there is just one config
129-
let webpackConfig = webpackConfigResult.config[0];
129+
let webpackConfig = webpackConfigResult.config;
130130

131131
const port = await checkPort(options.port || 0, options.host || 'localhost', 4200);
132132
const webpackDevServerConfig = (webpackConfig.devServer = buildServerConfig(

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async function execute(options: ExtractI18nBuilderOptions, context: BuilderConte
119119
}
120120
};
121121

122-
return runWebpack(config[0], context, { logging }).toPromise();
122+
return runWebpack(config, context, { logging }).toPromise();
123123
}
124124

125125
export default createBuilder<JsonObject & ExtractI18nBuilderOptions>(execute);

packages/angular_devkit/build_angular/src/karma/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function initialize(
6161

6262
return [
6363
karma,
64-
webpackConfigurationTransformer ? await webpackConfigurationTransformer(config[0]) : config[0],
64+
webpackConfigurationTransformer ? await webpackConfigurationTransformer(config) : config,
6565
];
6666
}
6767

packages/angular_devkit/build_angular/src/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ async function buildServerWebpackConfig(
106106
],
107107
);
108108

109-
return config[0];
109+
return config;
110110
}

packages/angular_devkit/build_angular/src/utils/build-browser-features.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import * as browserslist from 'browserslist';
1010
import { feature, features } from 'caniuse-lite';
1111
import * as ts from 'typescript';
1212

13-
const fullDifferentialEnv = process.env['NG_BUILD_DIFFERENTIAL_FULL'];
14-
export const fullDifferential =
15-
fullDifferentialEnv !== undefined &&
16-
fullDifferentialEnv !== '0' &&
17-
fullDifferentialEnv.toLowerCase() !== 'false';
18-
1913
export class BuildBrowserFeatures {
2014
private readonly _supportedBrowsers: string[];
2115
private readonly _es6TargetOrLater: boolean;

0 commit comments

Comments
 (0)