Skip to content

Commit

Permalink
fixup! feat(@angular-devkit/build-angular): Identify third-party sour…
Browse files Browse the repository at this point in the history
…ces in sourcemaps
  • Loading branch information
alan-agius4 committed Jul 12, 2022
1 parent f036376 commit 555341d
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export class DevToolsIgnorePlugin {
constructor(private options: Options) {}

apply(compiler: Compiler) {
const { SourceMapSource } = compiler.webpack.sources;
const { RawSource } = compiler.webpack.sources;

compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING,
additionalAssets: true,
},
(assets) => {
let vendorsTest: RegExp | null = null;
Expand All @@ -55,16 +56,25 @@ export class DevToolsIgnorePlugin {
}

for (const [name, asset] of Object.entries(assets)) {
const map = asset.map() as Object & SourceMap;
if (!map) {
// Instead of using `asset.map` we process the map files RawSource.
// This is because `.map()` is slow and take several seconds.
if (!name.endsWith('.map')) {
// Ignore non map files
continue;
}

const mapContent = asset.source().toString();
if (!mapContent) {
continue;
}

const map = JSON.parse(mapContent) as SourceMap;

map[IGNORE_LIST] = Object.entries(map.sources)
.filter(([, source]) => vendorsTest?.test(source) || runtimeTest?.test(source))
.map(([index]) => +index);

compilation.updateAsset(name, new SourceMapSource(asset.source(), name, map));
compilation.updateAsset(name, new RawSource(JSON.stringify(map, undefined, 2)));
}
},
);
Expand Down

0 comments on commit 555341d

Please sign in to comment.