Skip to content

Commit 871b272

Browse files
authored
Support Windows path separator (#198)
Fixes #197
1 parent e259470 commit 871b272

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

src/lib/html.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function getNodePath(parts: string[], depthIndex: number): string {
111111

112112
const WEBPACK_FILENAME_PREFIX = 'webpack:///';
113113
const WEBPACK_FILENAME_PREFIX_LENGTH = WEBPACK_FILENAME_PREFIX.length;
114+
const PATH_SEPARATOR_REGEX = /[\\/]/;
114115

115116
function splitFilename(file: string): string[] {
116117
const webpackPrefixIndex = file.indexOf(WEBPACK_FILENAME_PREFIX);
@@ -124,7 +125,7 @@ function splitFilename(file: string): string[] {
124125
].filter(Boolean);
125126
}
126127

127-
return file.split('/');
128+
return file.split(PATH_SEPARATOR_REGEX);
128129
}
129130

130131
function getTreeNodesMap(fileDataMap: FileDataMap): TreeNodesMap {

tests/unit/__snapshots__/html.test.ts.snap

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,75 @@ exports['html getWebTreeMapData should collapse non-contributing nodes 1'] = {
134134
]
135135
}
136136

137+
exports['html getWebTreeMapData should merge mixed paths 1'] = {
138+
"name": "/",
139+
"data": {
140+
"$area": 21
141+
},
142+
"children": [
143+
{
144+
"name": "c:",
145+
"data": {
146+
"$area": 21
147+
},
148+
"children": [
149+
{
150+
"name": "a/b/c.js",
151+
"data": {
152+
"$area": 1
153+
}
154+
},
155+
{
156+
"name": "d",
157+
"data": {
158+
"$area": 20
159+
},
160+
"children": [
161+
{
162+
"name": "e.js",
163+
"data": {
164+
"$area": 2
165+
}
166+
},
167+
{
168+
"name": "f.js",
169+
"data": {
170+
"$area": 3
171+
}
172+
},
173+
{
174+
"name": "g",
175+
"data": {
176+
"$area": 9
177+
},
178+
"children": [
179+
{
180+
"name": "h.js",
181+
"data": {
182+
"$area": 4
183+
}
184+
},
185+
{
186+
"name": "i.js",
187+
"data": {
188+
"$area": 5
189+
}
190+
}
191+
]
192+
},
193+
{
194+
"name": "j/i.js",
195+
"data": {
196+
"$area": 6
197+
}
198+
}
199+
]
200+
}
201+
]
202+
}
203+
]
204+
}
205+
137206
exports['html getWebTreeMapData should not create node for zero size files 1'] = {
138207
"name": "/",
139208
"data": {

tests/unit/html.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,18 @@ describe('html', () => {
108108

109109
snapshot(getWebTreeMapData(fileDataMap));
110110
});
111+
112+
it('should merge mixed paths', () => {
113+
const fileDataMap: FileDataMap = {
114+
'c:/a/b/c.js': { size: 1 },
115+
'c:\\d\\e.js': { size: 2 },
116+
'c:/d/f.js': { size: 3 },
117+
'c:\\d\\g\\h.js': { size: 4 },
118+
'c:/d/g/i.js': { size: 5 },
119+
'c:\\d\\j\\i.js': { size: 6 },
120+
};
121+
122+
snapshot(getWebTreeMapData(fileDataMap));
123+
});
111124
});
112125
});

0 commit comments

Comments
 (0)