This repository was archived by the owner on Jul 13, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcommon.js
More file actions
90 lines (74 loc) · 2.57 KB
/
Copy pathcommon.js
File metadata and controls
90 lines (74 loc) · 2.57 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Environment
*/
export var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
export var isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
export var isWindows = typeof process !== 'undefined' && typeof process.platform === 'string' && process.platform.match(/^win/);
var envGlobal = typeof self !== 'undefined' ? self : global;
export { envGlobal as global }
export function pathToFileUrl(filePath) {
return 'file://' + (isWindows ? '/' : '') + filePath;
}
export function fileUrlToPath(fileUrl) {
if (fileUrl.substr(0, 7) !== 'file://')
throw new RangeError(fileUrl + ' is not a valid file url');
if (isWindows)
return fileUrl.substr(8).replace(/\//g, '/');
else
return fileUrl.substr(7);
}
/*
* Environment baseURI
*/
export var baseURI;
// environent baseURI detection
if (typeof document != 'undefined' && document.getElementsByTagName) {
baseURI = document.baseURI;
if (!baseURI) {
var bases = document.getElementsByTagName('base');
baseURI = bases[0] && bases[0].href || window.location.href;
}
}
else if (typeof location != 'undefined') {
baseURI = location.href;
}
// sanitize out the hash and querystring
if (baseURI) {
baseURI = baseURI.split('#')[0].split('?')[0];
baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
}
else if (typeof process != 'undefined' && process.cwd) {
baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd();
if (isWindows)
baseURI = baseURI.replace(/\\/g, '/');
}
else {
throw new TypeError('No environment baseURI');
}
// ensure baseURI has trailing "/"
if (baseURI[baseURI.length - 1] !== '/')
baseURI += '/';
/*
* LoaderError with chaining for loader stacks
*/
var errArgs = new Error(0, '_').fileName == '_';
function LoaderError__Check_error_message_above_for_loader_stack(childErr, newMessage) {
// Convert file:/// URLs to paths in Node
if (!isBrowser)
newMessage = newMessage.replace(isWindows ? /file:\/\/\//g : /file:\/\//g, '');
var message = (childErr.message || childErr) + '\n ' + newMessage;
var err;
if (errArgs && childErr.fileName)
err = new Error(message, childErr.fileName, childErr.lineNumber);
else
err = new Error(message);
var stack = childErr.originalErr ? childErr.originalErr.stack : childErr.stack;
if (isNode)
// node doesn't show the message otherwise
err.stack = message + '\n ' + stack;
else
err.stack = stack;
err.originalErr = childErr.originalErr || childErr;
return err;
}
export { LoaderError__Check_error_message_above_for_loader_stack as addToError }