From 3a1af41a5dfb6537880ee91759838cd3816f2937 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Thu, 23 Feb 2017 02:32:08 -0800 Subject: [PATCH] Discard protocol, host, and port of URLs in bundle options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: HTTP request URLs don’t include protocol, host and port. Stack frames URLs, on the other hand, contain full URLs. These full URLs are used to get the correct bundle to build the source map from. The method that creates option objects from URLs therefore now discards leading protocol, host and port to ensure that cached bundles can be reused for symbolication rather than triggering rebuilds. Reviewed By: jeanlauliac, cpojer Differential Revision: D4598077 fbshipit-source-id: 262df187bcdf7099011371e8b55ae692c6e1a942 --- packager/src/Server/__tests__/Server-test.js | 9 +++++++++ packager/src/Server/index.js | 14 ++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packager/src/Server/__tests__/Server-test.js b/packager/src/Server/__tests__/Server-test.js index 5e32f529c39..1cb3db2d907 100644 --- a/packager/src/Server/__tests__/Server-test.js +++ b/packager/src/Server/__tests__/Server-test.js @@ -540,6 +540,15 @@ 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/packager/src/Server/index.js b/packager/src/Server/index.js index 2f3224e681d..3b21e87730a 100644 --- a/packager/src/Server/index.js +++ b/packager/src/Server/index.js @@ -793,6 +793,8 @@ class Server { const symbolicatingLogEntry = log(createActionStartEntry('Symbolicating')); + debug('Start symbolication'); + /* $FlowFixMe: where is `rowBody` defined? Is it added by * the `connect` framework? */ Promise.resolve(req.rawBody).then(body => { @@ -842,6 +844,7 @@ class Server { }); }).then( stack => { + debug('Symbolication done'); res.end(JSON.stringify({stack: stack})); process.nextTick(() => { log(createActionEndEntry(symbolicatingLogEntry)); @@ -918,6 +921,7 @@ class Server { } { // `true` to parse the query param as an object. const urlObj = url.parse(reqUrl, true); + /* $FlowFixMe: `pathname` could be empty for an invalid URL */ const pathname = decodeURIComponent(urlObj.pathname); @@ -931,9 +935,6 @@ class Server { return true; }).join('.') + '.js'; - const sourceMapUrlObj = Object.assign({}, urlObj); - sourceMapUrlObj.pathname = pathname.replace(/\.bundle$/, '.map'); - // try to get the platform from the url /* $FlowFixMe: `query` could be empty for an invalid URL */ const platform = urlObj.query.platform || @@ -948,7 +949,12 @@ class Server { const dev = this._getBoolOptionFromQuery(urlObj.query, 'dev', true); const minify = this._getBoolOptionFromQuery(urlObj.query, 'minify', false); return { - sourceMapUrl: url.format(sourceMapUrlObj), + sourceMapUrl: url.format({ + hash: urlObj.hash, + pathname: pathname.replace(/\.bundle$/, '.map'), + query: urlObj.query, + search: urlObj.search, + }), entryFile: entryFile, dev, minify,