Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): remove workaround for fideli…
Browse files Browse the repository at this point in the history
…ty and performance of babel sourcemaps

With this change we remove the workaround for fidelity and performance of babel sourcemaps as this is no longer needed as Babel now uses `@ampproject/remapping` to merge sourcemaps.

See babel/babel#14209 for more context.
  • Loading branch information
alan-agius4 authored and filipesilva committed Feb 7, 2022
1 parent 2fb099c commit 7c92bec
Showing 1 changed file with 1 addition and 26 deletions.
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

import remapping from '@ampproject/remapping';
import { custom } from 'babel-loader';
import { ScriptTarget } from 'typescript';
import { loadEsmModule } from '../utils/load-esm';
Expand All @@ -23,9 +22,6 @@ interface AngularCustomOptions extends Omit<ApplicationPresetOptions, 'instrumen

export type AngularBabelLoaderOptions = AngularCustomOptions & Record<string, unknown>;

// Extract Sourcemap input type from the remapping function since it is not currently exported
type SourceMapInput = Exclude<Parameters<typeof remapping>[0], unknown[]>;

/**
* Cached instance of the compiler-cli linker's needsLinking function.
*/
Expand Down Expand Up @@ -218,7 +214,7 @@ export default custom<ApplicationPresetOptions>(() => {
// Using `false` disables babel from attempting to locate sourcemaps or process any inline maps.
// The babel types do not include the false option even though it is valid
// eslint-disable-next-line @typescript-eslint/no-explicit-any
inputSourceMap: false as any,
inputSourceMap: configuration.options.inputSourceMap ?? (false as any),
presets: [
...(configuration.options.presets || []),
[
Expand All @@ -242,26 +238,5 @@ export default custom<ApplicationPresetOptions>(() => {
],
};
},
result(result, { map: inputSourceMap }) {
if (result.map && inputSourceMap) {
// Merge the intermediate sourcemap generated by babel with the input source map.
// The casting is required due to slight differences in the types for babel and
// `@ampproject/remapping` source map objects but both are compatible with Webpack.
// This method for merging is used because it provides more accurate output
// and is faster while using less memory.
result.map = {
// Convert the SourceMap back to simple plain object.
// This is needed because otherwise code-coverage will fail with `don't know how to turn this value into a node`
// Which is thrown by Babel if it is invoked again from `istanbul-lib-instrument`.
// https://github.com/babel/babel/blob/780aa48d2a34dc55f556843074b6aed45e7eabeb/packages/babel-types/src/converters/valueToNode.ts#L115-L130
...(remapping(
[result.map as SourceMapInput, inputSourceMap as SourceMapInput],
() => null,
) as typeof result.map),
};
}

return result;
},
};
});

0 comments on commit 7c92bec

Please sign in to comment.