Skip to content

Commit ae9cf1c

Browse files
rafecafacebook-github-bot
authored andcommitted
Fix the parsing of the HMR legacy URLs
Reviewed By: mjesun Differential Revision: D13060504 fbshipit-source-id: 54cfda78eae335d6df47217ed12ccc3a656f3e4a
1 parent 0007de3 commit ae9cf1c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

packages/metro/src/HmrServer/__tests__/HmrServer-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
const HmrServer = require('..');
1313

1414
const getGraphId = require('../../lib/getGraphId');
15+
1516
jest.mock('../../lib/transformHelpers', () => ({
1617
getResolveDependencyFn: () => (from, to) =>
17-
`${from.replace(/\.$/, '')}${to}.js`,
18+
`${require('path').resolve(from, to)}.js`,
1819
}));
1920

2021
describe('HmrServer', () => {

packages/metro/src/lib/__tests__/parseOptionsFromUrl-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ describe('parseOptionsFromUrl', () => {
105105
).toMatchObject({hot: true});
106106
});
107107

108+
it('retrieves stuff from HMR urls', () => {
109+
expect(
110+
parseOptionsFromUrl('my/bundle.bundle', new Set([])).options,
111+
).toMatchObject({entryFile: './my/bundle'});
112+
});
113+
108114
describe.each([
109115
['dev', true],
110116
['minify', false],

packages/metro/src/lib/parseOptionsFromUrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function parseOptionsFromUrl(
5252
// Backwards compatibility. Options used to be as added as '.' to the
5353
// entry module name. We can safely remove these options.
5454
const entryFileRelativeToProjectRoot = pathname
55-
.replace(/^\//, './') // We want to produce a relative path to project root
55+
.replace(/^(?:\.?\/)?/, './') // We want to produce a relative path to project root
5656
.split('.')
5757
.filter(part => {
5858
if (part === 'map') {

0 commit comments

Comments
 (0)