Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit e2eda58

Browse files
authored
Merge pull request #698 from tromey/relative-source-urls
Compute sourceRoot when only relative URLs are seen
2 parents bc7bb95 + c72ecf4 commit e2eda58

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* Doesn't really matter what is in here. */
2+
// # sourceMappingURL=noroot2.js.map

packages/devtools-source-map/src/tests/fixtures/noroot2.js.map

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/devtools-source-map/src/tests/source-map.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ describe("source maps", () => {
5050
const urls = await setupBundleFixture("noroot");
5151
expect(urls).toEqual(["http://example.com/heart.js"]);
5252
});
53+
54+
test("Non-existing sourceRoot resolution with relative URLs", async () => {
55+
const urls = await setupBundleFixture("noroot2");
56+
expect(urls).toEqual(["http://example.com/heart.js"]);
57+
});
5358
});
5459

5560
describe("hasMappedSource", async () => {

packages/devtools-source-map/src/utils/fetchSourceMap.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const { SourceMapConsumer } = require("source-map");
1111

1212
const path = require("./path");
1313

14+
const URL_ISH = new RegExp("^[a-z]+:/");
15+
1416
import type {
1517
Location,
1618
Source,
@@ -28,10 +30,17 @@ function _setSourceMapRoot(
2830
absSourceMapURL: string,
2931
source: Source
3032
) {
31-
// No need to do this fiddling if we won't be fetching any sources over the
32-
// wire.
33+
// No need to do this fiddling if we won't be fetching any sources
34+
// over the wire. However, we do still want to if any of the source
35+
// URLs are relative. What's difficult is that we want to pretend
36+
// that some non-URLs, like "webpack:/whatever", are actually URLs.
3337
if (sourceMap.hasContentsOfAllSources()) {
34-
return;
38+
const allURLsAreAbsolute = sourceMap.sources.every(sourceName => {
39+
return URL_ISH.test(sourceName);
40+
});
41+
if (allURLsAreAbsolute) {
42+
return;
43+
}
3544
}
3645

3746
// If it's already a URL, just leave it alone.

0 commit comments

Comments
 (0)