Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 3f77a46

Browse files
committed
[Sources] Fix webpack roots (#5861)
1 parent da1fbef commit 3f77a46

File tree

13 files changed

+134
-128
lines changed

13 files changed

+134
-128
lines changed

src/actions/tests/ui.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ describe("setProjectDirectoryRoot", () => {
102102
const { dispatch, getState } = store;
103103
await dispatch(actions.newSource(makeSource("js/scopes.js")));
104104
await dispatch(actions.newSource(makeSource("lib/vendor.js")));
105-
dispatch(actions.setProjectDirectoryRoot("/js"));
105+
dispatch(
106+
actions.setProjectDirectoryRoot("http://localhost:8000/examples/js")
107+
);
106108
const filteredSources = getRelativeSources(getState());
107109
const firstSource = filteredSources[0];
108110

src/components/PrimaryPanes/SourcesTree.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class SourcesTree extends Component<Props, State> {
194194
getIcon = (sources, item, depth) => {
195195
const { debuggeeUrl, projectRoot } = this.props;
196196

197-
if (item.path === "/Webpack") {
197+
if (item.path === "webpack://") {
198198
return <Svg name="webpack" />;
199199
}
200200
if (item.path === "/Angular") {
@@ -307,11 +307,20 @@ class SourcesTree extends Component<Props, State> {
307307
>
308308
{arrow}
309309
{icon}
310-
<span className="label"> {item.name} </span>
310+
<span className="label"> {this.renderItemName(item.name)} </span>
311311
</div>
312312
);
313313
};
314314

315+
renderItemName(name) {
316+
const hosts = {
317+
"ng://": "Angular",
318+
"webpack://": "Webpack"
319+
};
320+
321+
return hosts[name] || name;
322+
}
323+
315324
renderEmptyElement(message) {
316325
return <div className="no-sources-message">{message}</div>;
317326
}

src/selectors/getRelativeSources.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function formatSource(source: Source, root): RelativeSource {
3131
export function getRelativeSources(state: State): RelativeSource[] {
3232
const sources = getSources(state);
3333
const root = getProjectDirectoryRoot(state);
34-
3534
return sources
3635
.valueSeq()
3736
.toJS()

src/test/mochitest/browser_dbg-sources.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ add_task(async function() {
3333

3434
ok(
3535
expanded.has(
36-
`/example.com/browser/devtools/client/debugger/new/test/mochitest/examples/nested/nested/`
36+
`example.com/browser/devtools/client/debugger/new/test/mochitest/examples/nested/nested/`
3737
),
3838
"Nodes in path are automatically expanded"
3939
);

src/utils/sources-tree/addToTree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function isUnderRoot(url, projectRoot) {
2727
return true;
2828
}
2929

30-
return `/${url.group}${url.path}`.startsWith(projectRoot);
30+
return `${url.group}${url.path}`.startsWith(projectRoot);
3131
}
3232

3333
function removeProjectRoot(parts, projectRoot) {
@@ -112,7 +112,7 @@ function traverseTree(
112112

113113
let path = "";
114114
return parts.reduce((subTree, part, index) => {
115-
path = `${path}/${part}`;
115+
path = path ? `${path}/${part}` : part;
116116
const debuggeeHostIfRoot = index === 0 ? debuggeeHost : null;
117117
return findOrCreateNode(
118118
parts,

src/utils/sources-tree/getDirectories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function findSource(sourceTree: Node, sourceUrl: string): Node {
3434

3535
export function getDirectories(sourceUrl: string, sourceTree: Node) {
3636
const url = getURL(sourceUrl);
37-
const fullUrl = `/${url.group}${url.path}`;
37+
const fullUrl = `${url.group}${url.path}`;
3838
const parentMap = createParentMap(sourceTree);
3939
const source = findSource(sourceTree, fullUrl);
4040
if (!source) {

src/utils/sources-tree/getURL.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export function getURL(sourceUrl: string, debuggeeUrl: string = ""): ParsedURL {
4646
// A Webpack source is a special case
4747
return merge(def, {
4848
path: path,
49-
group: "Webpack",
49+
group: "webpack://",
5050
filename: filename
5151
});
5252

5353
case "ng:":
5454
// An Angular source is a special case
5555
return merge(def, {
5656
path: path,
57-
group: "Angular",
57+
group: "ng://",
5858
filename: filename
5959
});
6060

src/utils/sources-tree/tests/__snapshots__/addToTree.spec.js.snap

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,86 @@
22

33
exports[`sources-tree addToTree can add a file to an intermediate directory 1`] = `
44
" - root path=
5-
- unpkg.com path=/unpkg.com
6-
7-
- mode path=/unpkg.com/[email protected]/mode
8-
- xml path=/unpkg.com/[email protected]/mode/xml
9-
- xml.js path=/unpkg.com/[email protected]/mode/xml/xml.js source_id=server1.conn13.child1/39
10-
- [email protected] path=/unpkg.com/[email protected] source_id=server1.conn13.child1/37
5+
- unpkg.com path=unpkg.com
6+
7+
- mode path=unpkg.com/[email protected]/mode
8+
- xml path=unpkg.com/[email protected]/mode/xml
9+
- xml.js path=unpkg.com/[email protected]/mode/xml/xml.js source_id=server1.conn13.child1/39
10+
- [email protected] path=unpkg.com/[email protected] source_id=server1.conn13.child1/37
1111
"
1212
`;
1313

1414
exports[`sources-tree addToTree correctly parses file sources 1`] = `
1515
" - root path=
16-
- file:// path=/file://
17-
- a path=/file:///a
18-
- b.js path=/file:///a/b.js source_id=undefined
16+
- file:// path=file://
17+
- a path=file:///a
18+
- b.js path=file:///a/b.js source_id=undefined
1919
"
2020
`;
2121

2222
exports[`sources-tree addToTree does not attempt to add two of the same directory 1`] = `
2323
" - root path=
24-
- davidwalsh.name path=/davidwalsh.name
24+
- davidwalsh.name path=davidwalsh.name
2525
- (index) path=https://davidwalsh.name/ source_id=server1.conn13.child1/37
26-
- wp-content path=/davidwalsh.name/wp-content
27-
- prism.js path=/davidwalsh.name/wp-content/prism.js source_id=server1.conn13.child1/39
26+
- wp-content path=davidwalsh.name/wp-content
27+
- prism.js path=davidwalsh.name/wp-content/prism.js source_id=server1.conn13.child1/39
2828
"
2929
`;
3030

3131
exports[`sources-tree addToTree does not attempt to add two of the same file 1`] = `
3232
" - root path=
33-
- davidwalsh.name path=/davidwalsh.name
33+
- davidwalsh.name path=davidwalsh.name
3434
- (index) path=https://davidwalsh.name/ source_id=server1.conn13.child1/37
3535
"
3636
`;
3737

3838
exports[`sources-tree addToTree excludes javascript: URLs from the tree 1`] = `
3939
" - root path=
40-
- example.com path=/example.com
41-
- source1.js path=/example.com/source1.js source_id=undefined
40+
- example.com path=example.com
41+
- source1.js path=example.com/source1.js source_id=undefined
4242
"
4343
`;
4444

4545
exports[`sources-tree addToTree replaces a file with a directory 1`] = `
4646
" - root path=
47-
- unpkg.com path=/unpkg.com
48-
49-
- mode path=/unpkg.com/[email protected]/mode
50-
- xml path=/unpkg.com/[email protected]/mode/xml
51-
- xml.js path=/unpkg.com/[email protected]/mode/xml/xml.js source_id=server1.conn13.child1/39
52-
- [email protected] path=/unpkg.com/[email protected] source_id=server1.conn13.child1/37
47+
- unpkg.com path=unpkg.com
48+
49+
- mode path=unpkg.com/[email protected]/mode
50+
- xml path=unpkg.com/[email protected]/mode/xml
51+
- xml.js path=unpkg.com/[email protected]/mode/xml/xml.js source_id=server1.conn13.child1/39
52+
- [email protected] path=unpkg.com/[email protected] source_id=server1.conn13.child1/37
5353
"
5454
`;
5555

5656
exports[`sources-tree addToTree supports data URLs 1`] = `
5757
" - root path=
58-
- (no domain) path=/(no domain)
58+
- (no domain) path=(no domain)
5959
- data:text/html,<script>console.log(123)</script> path=data:text/html,<script>console.log(123)</script> source_id=server1.conn13.child1/39
6060
"
6161
`;
6262

6363
exports[`sources-tree addToTree uses debuggeeUrl as default 1`] = `
6464
" - root path=
65-
- localhost:4242 path=/localhost:4242
66-
- components path=/localhost:4242/components
67-
- Header.js path=/localhost:4242/components/Header.js source_id=undefined
68-
- TodoItem.js path=/localhost:4242/components/TodoItem.js source_id=undefined
69-
- TodoTextInput.js path=/localhost:4242/components/TodoTextInput.js source_id=undefined
70-
- reducers path=/localhost:4242/reducers
71-
- index.js path=/localhost:4242/reducers/index.js source_id=undefined
72-
- index.js path=/localhost:4242/index.js source_id=undefined
73-
- resource:// path=/resource://
74-
- modules path=/resource:///modules
75-
- ExtensionContent.jsm path=/resource:///modules/ExtensionContent.jsm source_id=undefined
76-
- voz37vlg5.codesandbox.io path=/voz37vlg5.codesandbox.io
77-
- static path=/voz37vlg5.codesandbox.io/static
78-
- js path=/voz37vlg5.codesandbox.io/static/js
79-
- components path=/voz37vlg5.codesandbox.io/static/js/components
80-
- TodoItem.js path=/voz37vlg5.codesandbox.io/static/js/components/TodoItem.js source_id=undefined
65+
- localhost:4242 path=localhost:4242
66+
- components path=localhost:4242/components
67+
- Header.js path=localhost:4242/components/Header.js source_id=undefined
68+
- TodoItem.js path=localhost:4242/components/TodoItem.js source_id=undefined
69+
- TodoTextInput.js path=localhost:4242/components/TodoTextInput.js source_id=undefined
70+
- reducers path=localhost:4242/reducers
71+
- index.js path=localhost:4242/reducers/index.js source_id=undefined
72+
- index.js path=localhost:4242/index.js source_id=undefined
73+
- resource:// path=resource://
74+
- modules path=resource:///modules
75+
- ExtensionContent.jsm path=resource:///modules/ExtensionContent.jsm source_id=undefined
76+
- voz37vlg5.codesandbox.io path=voz37vlg5.codesandbox.io
77+
- static path=voz37vlg5.codesandbox.io/static
78+
- js path=voz37vlg5.codesandbox.io/static/js
79+
- components path=voz37vlg5.codesandbox.io/static/js/components
80+
- TodoItem.js path=voz37vlg5.codesandbox.io/static/js/components/TodoItem.js source_id=undefined
8181
"
8282
`;
8383

8484
exports[`sources-tree addToTree uses projectRoot to filter the list 1`] = `
8585
" - root path=
86-
- components path=/components
87-
- Header.js path=/components/Header.js source_id=undefined
88-
- TodoItem.js path=/components/TodoItem.js source_id=undefined
89-
- TodoTextInput.js path=/components/TodoTextInput.js source_id=undefined
9086
"
9187
`;

src/utils/sources-tree/tests/__snapshots__/collapseTree.spec.js.snap

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22

33
exports[`sources tree collapseTree can collapse a single source 1`] = `
44
" - root path=
5-
- example.com path=/example.com
6-
- a/b path=/example.com/a/b
7-
- c.js path=/example.com/a/b/c.js source_id=undefined
5+
- example.com path=example.com
6+
- a/b path=example.com/a/b
7+
- c.js path=example.com/a/b/c.js source_id=undefined
88
"
99
`;
1010

1111
exports[`sources tree collapseTree correctly merges in a collapsed source with a deeper level 1`] = `
1212
" - root path=
13-
- example.com path=/example.com
14-
- a/b path=/example.com/a/b
15-
- c/d path=/example.com/a/b/c/d
16-
- e.js path=/example.com/a/b/c/d/e.js source_id=undefined
17-
- c.js path=/example.com/a/b/c.js source_id=undefined
13+
- example.com path=example.com
14+
- a/b path=example.com/a/b
15+
- c/d path=example.com/a/b/c/d
16+
- e.js path=example.com/a/b/c/d/e.js source_id=undefined
17+
- c.js path=example.com/a/b/c.js source_id=undefined
1818
"
1919
`;
2020

2121
exports[`sources tree collapseTree correctly merges in a collapsed source with a shallower level 1`] = `
2222
" - root path=
23-
- example.com path=/example.com
24-
- a/b path=/example.com/a/b
25-
- c.js path=/example.com/a/b/c.js source_id=undefined
26-
- x.js path=/example.com/a/b/x.js source_id=undefined
23+
- example.com path=example.com
24+
- a/b path=example.com/a/b
25+
- c.js path=example.com/a/b/c.js source_id=undefined
26+
- x.js path=example.com/a/b/x.js source_id=undefined
2727
"
2828
`;
2929

3030
exports[`sources tree collapseTree correctly merges in a collapsed source with the same level 1`] = `
3131
" - root path=
32-
- example.com path=/example.com
33-
- a/b path=/example.com/a/b
34-
- c/d path=/example.com/a/b/c/d
35-
- e.js path=/example.com/a/b/c/d/e.js source_id=undefined
36-
- c.js path=/example.com/a/b/c.js source_id=undefined
32+
- example.com path=example.com
33+
- a/b path=example.com/a/b
34+
- c/d path=example.com/a/b/c/d
35+
- e.js path=example.com/a/b/c/d/e.js source_id=undefined
36+
- c.js path=example.com/a/b/c.js source_id=undefined
3737
"
3838
`;

src/utils/sources-tree/tests/__snapshots__/sortTree.spec.js.snap

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,72 @@
22

33
exports[`sources-tree sortEntireTree alphabetically sorts children 1`] = `
44
" - root path=
5-
- example.com path=/example.com
6-
- foo path=/example.com/foo
7-
- a_source3.js path=/example.com/foo/a_source3.js source_id=undefined
8-
- b_source2.js path=/example.com/foo/b_source2.js source_id=undefined
9-
- source1.js path=/example.com/source1.js source_id=undefined
5+
- example.com path=example.com
6+
- foo path=example.com/foo
7+
- a_source3.js path=example.com/foo/a_source3.js source_id=undefined
8+
- b_source2.js path=example.com/foo/b_source2.js source_id=undefined
9+
- source1.js path=example.com/source1.js source_id=undefined
1010
"
1111
`;
1212

1313
exports[`sources-tree sortEntireTree puts folder at the top of the sort 1`] = `
1414
" - root path=
15-
- example.com path=/example.com
16-
- folder path=/example.com/folder
17-
- b path=/example.com/folder/b
18-
- b.js path=/example.com/folder/b/b.js source_id=undefined
19-
- c path=/example.com/folder/c
15+
- example.com path=example.com
16+
- folder path=example.com/folder
17+
- b path=example.com/folder/b
18+
- b.js path=example.com/folder/b/b.js source_id=undefined
19+
- c path=example.com/folder/c
2020
- (index) path=http://example.com/folder/c/ source_id=undefined
21-
- a.js path=/example.com/folder/a.js source_id=undefined
21+
- a.js path=example.com/folder/a.js source_id=undefined
2222
"
2323
`;
2424

2525
exports[`sources-tree sortEntireTree puts root debugee url at the top of the sort 1`] = `
2626
" - root path=
27-
- example.com path=/example.com
28-
- b.js path=/example.com/b.js source_id=undefined
29-
- api.example.com path=/api.example.com
30-
- a.js path=/api.example.com/a.js source_id=undefined
31-
- demo.com path=/demo.com
32-
- c.js path=/demo.com/c.js source_id=undefined
27+
- example.com path=example.com
28+
- b.js path=example.com/b.js source_id=undefined
29+
- api.example.com path=api.example.com
30+
- a.js path=api.example.com/a.js source_id=undefined
31+
- demo.com path=demo.com
32+
- c.js path=demo.com/c.js source_id=undefined
3333
"
3434
`;
3535

3636
exports[`sources-tree sortEntireTree puts root debugee url at the top of the sort 2`] = `
3737
" - root path=
38-
- demo.com path=/demo.com
39-
- c.js path=/demo.com/c.js source_id=undefined
40-
- api.example.com path=/api.example.com
41-
- a.js path=/api.example.com/a.js source_id=undefined
42-
- example.com path=/example.com
43-
- b.js path=/example.com/b.js source_id=undefined
38+
- demo.com path=demo.com
39+
- c.js path=demo.com/c.js source_id=undefined
40+
- api.example.com path=api.example.com
41+
- a.js path=api.example.com/a.js source_id=undefined
42+
- example.com path=example.com
43+
- b.js path=example.com/b.js source_id=undefined
4444
"
4545
`;
4646

4747
exports[`sources-tree sortEntireTree sorts folders first 1`] = `
4848
" - root path=
49-
- example.com path=/example.com
49+
- example.com path=example.com
5050
- (index) path=http://example.com source_id=undefined
51-
- b.js path=/example.com/b.js
52-
- b_source.js path=/example.com/b.js/b_source.js source_id=undefined
53-
- d path=/example.com/d
54-
- d_source.js path=/example.com/d/d_source.js source_id=undefined
55-
- a.js path=/example.com/a.js source_id=undefined
56-
- b2 path=/example.com/b2 source_id=undefined
57-
- c.js path=/example.com/c.js source_id=undefined
51+
- b.js path=example.com/b.js
52+
- b_source.js path=example.com/b.js/b_source.js source_id=undefined
53+
- d path=example.com/d
54+
- d_source.js path=example.com/d/d_source.js source_id=undefined
55+
- a.js path=example.com/a.js source_id=undefined
56+
- b2 path=example.com/b2 source_id=undefined
57+
- c.js path=example.com/c.js source_id=undefined
5858
"
5959
`;
6060

6161
exports[`sources-tree sortEntireTree sorts folders first 2`] = `
6262
" - root path=
63-
- example.com path=/example.com
63+
- example.com path=example.com
6464
- (index) path=http://example.com source_id=undefined
65-
- b.js path=/example.com/b.js
66-
- b_source.js path=/example.com/b.js/b_source.js source_id=undefined
67-
- d path=/example.com/d
68-
- d_source.js path=/example.com/d/d_source.js source_id=undefined
69-
- a.js path=/example.com/a.js source_id=undefined
70-
- b2 path=/example.com/b2 source_id=undefined
71-
- c.js path=/example.com/c.js source_id=undefined
65+
- b.js path=example.com/b.js
66+
- b_source.js path=example.com/b.js/b_source.js source_id=undefined
67+
- d path=example.com/d
68+
- d_source.js path=example.com/d/d_source.js source_id=undefined
69+
- a.js path=example.com/a.js source_id=undefined
70+
- b2 path=example.com/b2 source_id=undefined
71+
- c.js path=example.com/c.js source_id=undefined
7272
"
7373
`;

0 commit comments

Comments
 (0)