Skip to content

Commit fcdea5a

Browse files
clydinKeen Yee Liau
authored andcommitted
fix(@angular-devkit/build-angular): insert sourcemap source content when using fast path
1 parent 99e5e30 commit fcdea5a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { I18nOptions } from './i18n-options';
2727
const cacache = require('cacache');
2828
const deserialize = ((v8 as unknown) as { deserialize(buffer: Buffer): unknown }).deserialize;
2929

30-
// If code size is larger than 500KB, consider lower fidelity but faster sourcemap merge
31-
const FAST_SOURCEMAP_THRESHOLD = 500 * 1024;
30+
// If code size is larger than 1MB, consider lower fidelity but faster sourcemap merge
31+
const FAST_SOURCEMAP_THRESHOLD = 1024 * 1024;
3232

3333
export interface ProcessBundleOptions {
3434
filename: string;
@@ -255,6 +255,25 @@ async function mergeSourceMapsFast(first: RawSourceMap, second: RawSourceMap) {
255255
map.file = second.file;
256256
map.sourceRoot = sourceRoot;
257257

258+
// Add source content if present
259+
if (first.sourcesContent) {
260+
// Source content array is based on index of sources
261+
const sourceContentMap = new Map<string, number>();
262+
for (let i = 0; i < first.sources.length; i++) {
263+
// make paths "absolute" so they can be compared (`./a.js` and `a.js` are equivalent)
264+
sourceContentMap.set(path.resolve('/', first.sources[i]), i);
265+
}
266+
map.sourcesContent = [];
267+
for (let i = 0; i < map.sources.length; i++) {
268+
const contentIndex = sourceContentMap.get(path.resolve('/', map.sources[i]));
269+
if (contentIndex === undefined) {
270+
map.sourcesContent.push('');
271+
} else {
272+
map.sourcesContent.push(first.sourcesContent[contentIndex]);
273+
}
274+
}
275+
}
276+
258277
// Put the sourceRoot back
259278
if (sourceRoot) {
260279
first.sourceRoot = sourceRoot;

0 commit comments

Comments
 (0)