Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(@angular-devkit/build-angular): remove workaround for fidelity and performance of babel sourcemaps #22646

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
},
};
});