diff --git a/packages/metro/src/lib/SourceMap.js b/packages/metro/src/lib/SourceMap.js index 453c049f..5851f2b9 100644 --- a/packages/metro/src/lib/SourceMap.js +++ b/packages/metro/src/lib/SourceMap.js @@ -23,7 +23,10 @@ export type IndexMapSection = { export type RawMappings = Array; -type FBExtensions = {x_facebook_offsets: Array}; +type FBExtensions = { + x_facebook_offsets: Array, + x_metro_module_paths: Array, +}; export type {MappingsMap}; export type IndexMap = { diff --git a/packages/metro/src/shared/output/unbundle/build-unbundle-sourcemap-with-metadata.js b/packages/metro/src/shared/output/unbundle/build-unbundle-sourcemap-with-metadata.js index ede170b4..0c727198 100644 --- a/packages/metro/src/shared/output/unbundle/build-unbundle-sourcemap-with-metadata.js +++ b/packages/metro/src/shared/output/unbundle/build-unbundle-sourcemap-with-metadata.js @@ -41,11 +41,22 @@ module.exports = ({ sourcePath: '', }; + // Add map of module id -> source to sourcemap + const module_paths = []; + startupModules.forEach(m => { + module_paths[m.id] = m.sourcePath; + }); + lazyModules.forEach(m => { + module_paths[m.id] = m.sourcePath; + }); + const map = combineSourceMapsAddingOffsets( [startupModule].concat(lazyModules), + module_paths, moduleGroups, options, ); delete map.x_facebook_offsets[Number.MIN_SAFE_INTEGER]; + return map; }; diff --git a/packages/metro/src/shared/output/unbundle/util.js b/packages/metro/src/shared/output/unbundle/util.js index 3b4d565b..cc946cbf 100644 --- a/packages/metro/src/shared/output/unbundle/util.js +++ b/packages/metro/src/shared/output/unbundle/util.js @@ -66,6 +66,7 @@ function combineSourceMaps( function combineSourceMapsAddingOffsets( modules: $ReadOnlyArray, + x_metro_module_paths: Array, moduleGroups?: ?ModuleGroups, options?: ?CombineOptions, ): FBIndexMap { @@ -76,7 +77,7 @@ function combineSourceMapsAddingOffsets( moduleGroups, options, ); - return {sections, version: 3, x_facebook_offsets}; + return {sections, version: 3, x_facebook_offsets, x_metro_module_paths}; } function combineMaps(