diff --git a/packages/angular_devkit/build_optimizer/BUILD b/packages/angular_devkit/build_optimizer/BUILD index 03cc8af56aa7..f4f48cadf65d 100644 --- a/packages/angular_devkit/build_optimizer/BUILD +++ b/packages/angular_devkit/build_optimizer/BUILD @@ -26,8 +26,8 @@ ts_library( ), deps = [ "@npm//@types/node", - "@npm//@types/source-map", "@npm//@types/webpack", + "@npm//source-map", "@npm//typescript", ], ) @@ -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 ) diff --git a/packages/angular_devkit/build_optimizer/package.json b/packages/angular_devkit/build_optimizer/package.json index 9cb0814b4ea5..ddcd608a1923 100644 --- a/packages/angular_devkit/build_optimizer/package.json +++ b/packages/angular_devkit/build_optimizer/package.json @@ -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" } diff --git a/packages/angular_devkit/build_optimizer/src/build-optimizer/webpack-loader.ts b/packages/angular_devkit/build_optimizer/src/build-optimizer/webpack-loader.ts index ec4c138a7900..01d4acbb0f3d 100644 --- a/packages/angular_devkit/build_optimizer/src/build-optimizer/webpack-loader.ts +++ b/packages/angular_devkit/build_optimizer/src/build-optimizer/webpack-loader.ts @@ -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; } @@ -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 @@ -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) { @@ -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; @@ -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); } diff --git a/packages/angular_devkit/core/BUILD b/packages/angular_devkit/core/BUILD index 8710c3943062..ac754af851a2 100644 --- a/packages/angular_devkit/core/BUILD +++ b/packages/angular_devkit/core/BUILD @@ -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 diff --git a/yarn.lock b/yarn.lock index a22be71b5b4a..faa3cf59b9e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9719,11 +9719,6 @@ source-map@0.1.x: dependencies: amdefine ">=0.0.4" -source-map@0.5.6: - version "0.5.6" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" - integrity sha1-dc449SvwczxafwwRjYEzSiu19BI= - source-map@0.7.3, source-map@^0.7.3: version "0.7.3" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"