From ccbe4bc78c17f5c97b3b88ee185ea34be5a94427 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 28 Sep 2017 09:11:08 -0700 Subject: [PATCH] Use Delta Bundler for symbolication of errors endpoint Reviewed By: jeanlauliac Differential Revision: D5913798 fbshipit-source-id: 5a8aaa6b39aa864424eabb94748cbff24b463b81 --- .../src/DeltaBundler/Serializers.js | 18 ++++++++++++++++++ packages/metro-bundler/src/Server/index.js | 12 ++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) 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(