Skip to content

Commit 74536d0

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
refactor(@angular-devkit/build-optimizer): update to use latest source-map version (0.7.3)
The latest version provides significant performance improvements.
1 parent 402349d commit 74536d0

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

packages/angular_devkit/build_optimizer/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ ts_library(
2626
),
2727
deps = [
2828
"@npm//@types/node",
29-
"@npm//@types/source-map",
3029
"@npm//@types/webpack",
30+
"@npm//source-map",
3131
"@npm//typescript",
3232
],
3333
)
@@ -48,7 +48,7 @@ ts_library(
4848
"//packages/angular_devkit/core",
4949
"@npm//@types/jasmine",
5050
"@npm//@types/node",
51-
"@npm//@types/source-map",
51+
"@npm//source-map",
5252
],
5353
# @external_end
5454
)

packages/angular_devkit/build_optimizer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"loader-utils": "1.2.3",
13-
"source-map": "0.5.6",
13+
"source-map": "0.7.3",
1414
"typescript": "3.5.3",
1515
"webpack-sources": "1.4.1"
1616
}

packages/angular_devkit/build_optimizer/src/build-optimizer/webpack-loader.ts

+31-18
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map';
9-
import * as webpack from 'webpack'; // tslint:disable-line:no-implicit-dependencies
9+
import * as webpack from 'webpack'; // tslint:disable-line:no-implicit-dependencies
1010

1111
const loaderUtils = require('loader-utils');
1212

1313
import { buildOptimizer } from './build-optimizer';
1414

15-
1615
interface BuildOptimizerLoaderOptions {
1716
sourceMap: boolean;
1817
}
@@ -21,17 +20,25 @@ export const buildOptimizerLoaderPath = __filename;
2120

2221
const alwaysProcess = (path: string) =>
2322
// Always process TS files.
24-
path.endsWith('.ts') || path.endsWith('.tsx')
23+
path.endsWith('.ts') ||
24+
path.endsWith('.tsx') ||
2525
// Always process factory files.
26-
|| path.endsWith('.ngfactory.js') || path.endsWith('.ngstyle.js');
27-
28-
export default function buildOptimizerLoader
29-
(this: webpack.loader.LoaderContext, content: string, previousSourceMap: RawSourceMap) {
26+
path.endsWith('.ngfactory.js') ||
27+
path.endsWith('.ngstyle.js');
28+
29+
export default function buildOptimizerLoader(
30+
this: webpack.loader.LoaderContext,
31+
content: string,
32+
previousSourceMap: RawSourceMap,
33+
) {
3034
this.cacheable();
35+
const callback = this.async();
36+
if (!callback) {
37+
throw new Error('Async loader support is required.');
38+
}
3139

32-
const skipBuildOptimizer = this._module
33-
&& this._module.factoryMeta
34-
&& this._module.factoryMeta.skipBuildOptimizer;
40+
const skipBuildOptimizer =
41+
this._module && this._module.factoryMeta && this._module.factoryMeta.skipBuildOptimizer;
3542

3643
if (!alwaysProcess(this.resourcePath) && skipBuildOptimizer) {
3744
// Skip loading processing this file with Build Optimizer if we determined in
@@ -56,9 +63,8 @@ export default function buildOptimizerLoader
5663
inputFilePath,
5764
outputFilePath,
5865
emitSourceMap: options.sourceMap,
59-
isSideEffectFree: this._module
60-
&& this._module.factoryMeta
61-
&& this._module.factoryMeta.sideEffectFree,
66+
isSideEffectFree:
67+
this._module && this._module.factoryMeta && this._module.factoryMeta.sideEffectFree,
6268
});
6369

6470
if (boOutput.emitSkipped || boOutput.content === null) {
@@ -89,10 +95,17 @@ export default function buildOptimizerLoader
8995
previousSourceMap.file = inputFilePath;
9096

9197
// Chain the sourcemaps.
92-
const consumer = new SourceMapConsumer(intermediateSourceMap);
93-
const generator = SourceMapGenerator.fromSourceMap(consumer);
94-
generator.applySourceMap(new SourceMapConsumer(previousSourceMap));
95-
newSourceMap = generator.toJSON();
98+
SourceMapConsumer.with(intermediateSourceMap, null, intermediate => {
99+
return SourceMapConsumer.with(previousSourceMap, null, previous => {
100+
const generator = SourceMapGenerator.fromSourceMap(intermediate);
101+
generator.applySourceMap(previous);
102+
103+
return generator.toJSON();
104+
});
105+
// tslint:disable-next-line: no-any
106+
}).then(map => callback(null, newContent, map as any), error => callback(error));
107+
108+
return;
96109
} else {
97110
// Otherwise just return our generated sourcemap.
98111
newSourceMap = intermediateSourceMap;
@@ -101,5 +114,5 @@ export default function buildOptimizerLoader
101114

102115
// Webpack typings for previousSourceMap are wrong, they are JSON objects and not strings.
103116
// tslint:disable-next-line:no-any
104-
this.callback(null, newContent, newSourceMap as any);
117+
callback(null, newContent, newSourceMap as any);
105118
}

packages/angular_devkit/core/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ ts_library(
3333
deps = [
3434
"@npm//rxjs",
3535
"@npm//@types/node",
36-
"@npm//@types/source-map",
3736
"@npm//ajv",
3837
"@npm//magic-string",
38+
"@npm//source-map",
3939
# @typings: es2015.core
4040
# @typings: es2015.symbol.wellknown
4141
# @typings: es2016.array.include

yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -9719,11 +9719,6 @@ [email protected]:
97199719
dependencies:
97209720
amdefine ">=0.0.4"
97219721

9722-
9723-
version "0.5.6"
9724-
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
9725-
integrity sha1-dc449SvwczxafwwRjYEzSiu19BI=
9726-
97279722
[email protected], source-map@^0.7.3:
97289723
version "0.7.3"
97299724
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"

0 commit comments

Comments
 (0)