Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): insert sourcemap source content w…
Browse files Browse the repository at this point in the history
…hen using fast path
  • Loading branch information
clydin authored and Keen Yee Liau committed Feb 13, 2020
1 parent 99e5e30 commit fcdea5a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/angular_devkit/build_angular/src/utils/process-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { I18nOptions } from './i18n-options';
const cacache = require('cacache');
const deserialize = ((v8 as unknown) as { deserialize(buffer: Buffer): unknown }).deserialize;

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

export interface ProcessBundleOptions {
filename: string;
Expand Down Expand Up @@ -255,6 +255,25 @@ async function mergeSourceMapsFast(first: RawSourceMap, second: RawSourceMap) {
map.file = second.file;
map.sourceRoot = sourceRoot;

// Add source content if present
if (first.sourcesContent) {
// Source content array is based on index of sources
const sourceContentMap = new Map<string, number>();
for (let i = 0; i < first.sources.length; i++) {
// make paths "absolute" so they can be compared (`./a.js` and `a.js` are equivalent)
sourceContentMap.set(path.resolve('/', first.sources[i]), i);
}
map.sourcesContent = [];
for (let i = 0; i < map.sources.length; i++) {
const contentIndex = sourceContentMap.get(path.resolve('/', map.sources[i]));
if (contentIndex === undefined) {
map.sourcesContent.push('');
} else {
map.sourcesContent.push(first.sourcesContent[contentIndex]);
}
}
}

// Put the sourceRoot back
if (sourceRoot) {
first.sourceRoot = sourceRoot;
Expand Down

0 comments on commit fcdea5a

Please sign in to comment.