From 09ee6d9cbe363f2255a68edec7ea54fa58853c90 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Fri, 29 Sep 2017 05:38:15 -0700 Subject: [PATCH] Add Source Map support to e2e deltas in chrome debugger Reviewed By: jeanlauliac Differential Revision: D5917380 fbshipit-source-id: 31391bc03c420b8e7af5c840fbea2fb0dd5f7bbc --- .../src/Server/__tests__/Server-test.js | 40 ++++++++++++++----- packages/metro-bundler/src/Server/index.js | 12 ++++-- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/packages/metro-bundler/src/Server/__tests__/Server-test.js b/packages/metro-bundler/src/Server/__tests__/Server-test.js index dc8287e1..178dd212 100644 --- a/packages/metro-bundler/src/Server/__tests__/Server-test.js +++ b/packages/metro-bundler/src/Server/__tests__/Server-test.js @@ -576,6 +576,35 @@ describe('processRequest', () => { ); }); + it('Passes the full url as the sourcemap url', () => { + return server + .buildBundleFromUrl( + 'http://localhost:8081/path/to/foo.bundle?dev=false&runModule=false&excludeSource=true', + ) + .then(() => + expect(Bundler.prototype.bundle).toBeCalledWith({ + assetPlugins: [], + dev: false, + entryFile: 'path/to/foo.js', + entryModuleOnly: false, + excludeSource: true, + generateSourceMaps: false, + hot: true, + inlineSourceMap: false, + isolateModuleIDs: false, + minify: false, + onProgress: null, + platform: null, + resolutionResponse: null, + runBeforeMainModule: ['InitializeCore'], + runModule: false, + sourceMapUrl: + 'http://localhost:8081/path/to/foo.map?dev=false&runModule=false&excludeSource=true', + unbundle: false, + }), + ); + }); + it('ignores the `hot` parameter (since it is not used anymore)', () => { return server .buildBundleFromUrl( @@ -662,17 +691,6 @@ describe('processRequest', () => { }); }); - describe('_getOptionsFromUrl', () => { - it('ignores protocol, host and port of the passed in URL', () => { - const short = - '/path/to/entry-file.js??platform=ios&dev=true&minify=false'; - const long = `http://localhost:8081${short}`; - expect(server._getOptionsFromUrl(long)).toEqual( - server._getOptionsFromUrl(short), - ); - }); - }); - // ensures that vital properties exist on fake request objects function scaffoldReq(req) { if (!req.headers) { diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index bd66ca1d..0e109f9b 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -891,7 +891,13 @@ class Server { req: IncomingMessage, mres: MultipartResponse, ): {options: DeltaBundlerOptions, buildID: string} { - const options = this._getOptionsFromUrl(req.url); + const options = this._getOptionsFromUrl( + url.format({ + ...url.parse(req.url), + protocol: 'http', + host: req.headers.host, + }), + ); const buildID = this.getNewBuildID(); @@ -1236,10 +1242,8 @@ class Server { return { sourceMapUrl: url.format({ - hash: urlObj.hash, + ...urlObj, pathname: pathname.replace(/\.(bundle|delta)$/, '.map'), - query: urlObj.query, - search: urlObj.search, }), entryFile, deltaBundleId,