-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathnormalizeMap.js
46 lines (35 loc) · 903 Bytes
/
normalizeMap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
export default (map) => {
const result = map;
if (result.sources) {
result.sources = normalizeArr(result.sources);
}
if (result.file) {
[result.file] = normalizeArr([result.file]);
}
if (result.sourceRoot) {
[result.sourceRoot] = normalizeArr([result.sourceRoot]);
}
return result;
};
function normalizeArr(arr) {
return arr.map((str) => {
const normilized = removeCWD(str);
if (str === normilized) {
return str;
}
if (str.replace(/\\/g, '/') === normilized) {
return normilized;
}
return `${normilized} - (normalized for test)`;
});
}
function removeCWD(str) {
const isWin = process.platform === 'win32';
let cwd = process.cwd();
if (isWin) {
// eslint-disable-next-line no-param-reassign
str = str.replace(/\\/g, '/');
cwd = cwd.replace(/\\/g, '/');
}
return str.replace(new RegExp(cwd, 'g'), '');
}