From fcdea5a1d2e85933def5940d6482405104ed717e Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 12 Feb 2020 13:52:52 -0500 Subject: [PATCH] fix(@angular-devkit/build-angular): insert sourcemap source content when using fast path --- .../build_angular/src/utils/process-bundle.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/utils/process-bundle.ts b/packages/angular_devkit/build_angular/src/utils/process-bundle.ts index e6b34f90d6bb..8e5621b1701a 100644 --- a/packages/angular_devkit/build_angular/src/utils/process-bundle.ts +++ b/packages/angular_devkit/build_angular/src/utils/process-bundle.ts @@ -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; @@ -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(); + 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;