Skip to content

Commit f2fbf40

Browse files
clydinvikerman
authored andcommitted
fix(@angular-devkit/build-angular): revert temporary TypeScript based differential loading
Memory usage has improved which allows the original babel based method to be reinstated.
1 parent 87de56b commit f2fbf40

File tree

5 files changed

+521
-400
lines changed

5 files changed

+521
-400
lines changed

packages/angular_devkit/build_angular/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"@angular-devkit/build-optimizer": "0.0.0",
1212
"@angular-devkit/build-webpack": "0.0.0",
1313
"@angular-devkit/core": "0.0.0",
14-
"@babel/core": "7.5.5",
15-
"@babel/preset-env": "7.5.5",
14+
"@babel/core": "7.7.5",
15+
"@babel/preset-env": "7.7.6",
1616
"@ngtools/webpack": "0.0.0",
1717
"ajv": "6.10.2",
1818
"autoprefixer": "9.6.1",

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
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 { transformAsync } from '@babel/core';
89
import { createHash } from 'crypto';
910
import * as fs from 'fs';
1011
import * as path from 'path';
1112
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map';
1213
import { minify } from 'terser';
13-
import { ScriptTarget, transpileModule } from 'typescript';
14-
import { SourceMapSource } from 'webpack-sources';
1514
import { manglingDisabled } from './mangle-options';
1615

1716
const cacache = require('cacache');
@@ -104,32 +103,37 @@ export async function process(options: ProcessBundleOptions): Promise<ProcessBun
104103
let downlevelMap;
105104
if (downlevel) {
106105
// Downlevel the bundle
107-
const transformResult = transpileModule(sourceCode, {
108-
fileName: downlevelFilename,
109-
compilerOptions: {
110-
downlevelIteration: true,
111-
sourceMap: !!sourceMap,
112-
target: ScriptTarget.ES5,
113-
},
106+
const transformResult = await transformAsync(sourceCode, {
107+
filename: options.filename,
108+
inputSourceMap: manualSourceMaps ? undefined : sourceMap,
109+
babelrc: false,
110+
presets: [
111+
[
112+
require.resolve('@babel/preset-env'),
113+
{
114+
// modules aren't needed since the bundles use webpack's custom module loading
115+
modules: false,
116+
// 'transform-typeof-symbol' generates slower code
117+
exclude: ['transform-typeof-symbol'],
118+
},
119+
],
120+
],
121+
minified: options.optimize,
122+
// `false` ensures it is disabled and prevents large file warnings
123+
compact: options.optimize || false,
124+
sourceMaps: !!sourceMap,
114125
});
115126

116-
downlevelCode = transformResult.outputText;
117-
118-
if (sourceMap && transformResult.sourceMapText) {
119-
if (manualSourceMaps) {
120-
downlevelMap = await mergeSourcemaps(sourceMap, JSON.parse(transformResult.sourceMapText));
121-
} else {
122-
// More accurate but significantly more costly
123-
const tempSource = new SourceMapSource(
124-
transformResult.outputText,
125-
downlevelFilename,
126-
JSON.parse(transformResult.sourceMapText),
127-
sourceCode,
128-
sourceMap,
129-
);
130-
131-
downlevelMap = tempSource.map();
132-
}
127+
if (!transformResult || !transformResult.code) {
128+
throw new Error(`Unknown error occurred processing bundle for "${options.filename}".`);
129+
}
130+
downlevelCode = transformResult.code;
131+
132+
if (manualSourceMaps && sourceMap && transformResult.map) {
133+
downlevelMap = await mergeSourcemaps(sourceMap, transformResult.map);
134+
} else {
135+
// undefined is needed here to normalize the property type
136+
downlevelMap = transformResult.map || undefined;
133137
}
134138
}
135139

packages/angular_devkit/build_angular/test/browser/differential_loading_spec_large.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ describe('Browser Builder with differential loading', () => {
9999
'vendor-es2016.js.map',
100100
'vendor-es5.js',
101101
'vendor-es5.js.map',
102-
] as PathFragment[];
102+
].sort((a, b) => a.localeCompare(b)) as PathFragment[];
103103

104-
expect(Object.keys(files)).toEqual(jasmine.arrayWithExactContents(expectedOutputs));
104+
expect(Object.keys(files).sort((a, b) => a.localeCompare(b))).toEqual(jasmine.arrayWithExactContents(expectedOutputs));
105105
});
106106

107107
it('deactivates differential loading for watch mode', async () => {

tests/legacy-cli/e2e/tests/build/prod-build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export default async function () {
5454

5555
// Size checks in bytes
5656
if (ivyProject) {
57-
verifySize(mainES5Path, 167355);
57+
verifySize(mainES5Path, 173355);
5858
verifySize(mainES2015Path, 149806);
5959
} else {
60-
verifySize(mainES5Path, 184470);
60+
verifySize(mainES5Path, 184770);
6161
verifySize(mainES2015Path, 163627);
6262
}
6363

0 commit comments

Comments
 (0)