diff --git a/packages/metro-bundler/src/DeltaBundler/Serializers.js b/packages/metro-bundler/src/DeltaBundler/Serializers.js index 6db62ee4..b981914f 100644 --- a/packages/metro-bundler/src/DeltaBundler/Serializers.js +++ b/packages/metro-bundler/src/DeltaBundler/Serializers.js @@ -17,6 +17,7 @@ const DeltaPatcher = require('./DeltaPatcher'); const {fromRawMappings} = require('../Bundler/source-map'); import type {BundleOptions} from '../Server'; +import type {MappingsMap} from '../lib/SourceMap'; import type DeltaBundler, {Options as BuildOptions} from './'; import type {DeltaTransformResponse} from './DeltaTransformer'; @@ -73,6 +74,22 @@ async function fullSourceMap( }); } +async function fullSourceMapObject( + deltaBundler: DeltaBundler, + options: Options, +): Promise { + const {id, delta} = await _build(deltaBundler, { + ...options, + wrapModules: true, + }); + + const deltaPatcher = DeltaPatcher.get(id).applyDelta(delta); + + return fromRawMappings(deltaPatcher.getAllModules()).toMap(undefined, { + excludeSource: options.excludeSource, + }); +} + /** * Returns the full JS bundle, which can be directly parsed by a JS interpreter */ @@ -113,4 +130,5 @@ module.exports = { deltaBundle, fullBundle, fullSourceMap, + fullSourceMapObject, }; diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index b6b4cd4b..bd66ca1d 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -1142,8 +1142,16 @@ class Server { ); } - _sourceMapForURL(reqUrl: string): Promise { - const options = this._getOptionsFromUrl(reqUrl); + async _sourceMapForURL(reqUrl: string): Promise { + const options: DeltaBundlerOptions = this._getOptionsFromUrl(reqUrl); + + if (this._opts.useDeltaBundler) { + return await Serializers.fullSourceMapObject(this._deltaBundler, { + ...options, + deltaBundleId: this.optionsHash(options), + }); + } + // We're not properly reporting progress here. Reporting should be done // from within that function. const building = this.useCachedOrUpdateOrCreateBundle(