Skip to content

Commit

Permalink
refactor(@angular-devkit/build-optimizer): update to use latest sourc…
Browse files Browse the repository at this point in the history
…e-map version (0.7.3)

The latest version provides significant performance improvements.
  • Loading branch information
clydin authored and Keen Yee Liau committed Aug 8, 2019
1 parent 402349d commit 74536d0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/angular_devkit/build_optimizer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ ts_library(
),
deps = [
"@npm//@types/node",
"@npm//@types/source-map",
"@npm//@types/webpack",
"@npm//source-map",
"@npm//typescript",
],
)
Expand All @@ -48,7 +48,7 @@ ts_library(
"//packages/angular_devkit/core",
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//@types/source-map",
"@npm//source-map",
],
# @external_end
)
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"loader-utils": "1.2.3",
"source-map": "0.5.6",
"source-map": "0.7.3",
"typescript": "3.5.3",
"webpack-sources": "1.4.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map';
import * as webpack from 'webpack'; // tslint:disable-line:no-implicit-dependencies
import * as webpack from 'webpack'; // tslint:disable-line:no-implicit-dependencies

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

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


interface BuildOptimizerLoaderOptions {
sourceMap: boolean;
}
Expand All @@ -21,17 +20,25 @@ export const buildOptimizerLoaderPath = __filename;

const alwaysProcess = (path: string) =>
// Always process TS files.
path.endsWith('.ts') || path.endsWith('.tsx')
path.endsWith('.ts') ||
path.endsWith('.tsx') ||
// Always process factory files.
|| path.endsWith('.ngfactory.js') || path.endsWith('.ngstyle.js');

export default function buildOptimizerLoader
(this: webpack.loader.LoaderContext, content: string, previousSourceMap: RawSourceMap) {
path.endsWith('.ngfactory.js') ||
path.endsWith('.ngstyle.js');

export default function buildOptimizerLoader(
this: webpack.loader.LoaderContext,
content: string,
previousSourceMap: RawSourceMap,
) {
this.cacheable();
const callback = this.async();
if (!callback) {
throw new Error('Async loader support is required.');
}

const skipBuildOptimizer = this._module
&& this._module.factoryMeta
&& this._module.factoryMeta.skipBuildOptimizer;
const skipBuildOptimizer =
this._module && this._module.factoryMeta && this._module.factoryMeta.skipBuildOptimizer;

if (!alwaysProcess(this.resourcePath) && skipBuildOptimizer) {
// Skip loading processing this file with Build Optimizer if we determined in
Expand All @@ -56,9 +63,8 @@ export default function buildOptimizerLoader
inputFilePath,
outputFilePath,
emitSourceMap: options.sourceMap,
isSideEffectFree: this._module
&& this._module.factoryMeta
&& this._module.factoryMeta.sideEffectFree,
isSideEffectFree:
this._module && this._module.factoryMeta && this._module.factoryMeta.sideEffectFree,
});

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

// Chain the sourcemaps.
const consumer = new SourceMapConsumer(intermediateSourceMap);
const generator = SourceMapGenerator.fromSourceMap(consumer);
generator.applySourceMap(new SourceMapConsumer(previousSourceMap));
newSourceMap = generator.toJSON();
SourceMapConsumer.with(intermediateSourceMap, null, intermediate => {
return SourceMapConsumer.with(previousSourceMap, null, previous => {
const generator = SourceMapGenerator.fromSourceMap(intermediate);
generator.applySourceMap(previous);

return generator.toJSON();
});
// tslint:disable-next-line: no-any
}).then(map => callback(null, newContent, map as any), error => callback(error));

return;
} else {
// Otherwise just return our generated sourcemap.
newSourceMap = intermediateSourceMap;
Expand All @@ -101,5 +114,5 @@ export default function buildOptimizerLoader

// Webpack typings for previousSourceMap are wrong, they are JSON objects and not strings.
// tslint:disable-next-line:no-any
this.callback(null, newContent, newSourceMap as any);
callback(null, newContent, newSourceMap as any);
}
2 changes: 1 addition & 1 deletion packages/angular_devkit/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ ts_library(
deps = [
"@npm//rxjs",
"@npm//@types/node",
"@npm//@types/source-map",
"@npm//ajv",
"@npm//magic-string",
"@npm//source-map",
# @typings: es2015.core
# @typings: es2015.symbol.wellknown
# @typings: es2016.array.include
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9719,11 +9719,6 @@ [email protected]:
dependencies:
amdefine ">=0.0.4"

[email protected]:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
integrity sha1-dc449SvwczxafwwRjYEzSiu19BI=

[email protected], source-map@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
Expand Down

0 comments on commit 74536d0

Please sign in to comment.