@opensumi/ide-components 2.17.9 → 2.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +32588 -11405
- package/lib/button/index.d.ts.map +1 -1
- package/lib/button/index.js +1 -1
- package/lib/button/index.js.map +1 -1
- package/lib/dialog/index.js +3 -3
- package/lib/dialog/index.js.map +1 -1
- package/lib/icon/icon.d.ts.map +1 -1
- package/lib/icon/icon.js +3 -3
- package/lib/icon/icon.js.map +1 -1
- package/lib/icon/util.d.ts +10 -2
- package/lib/icon/util.d.ts.map +1 -1
- package/lib/icon/util.js +13 -5
- package/lib/icon/util.js.map +1 -1
- package/lib/input/ValidateInput.js +1 -1
- package/lib/input/ValidateInput.js.map +1 -1
- package/lib/recycle-list/RecycleList.d.ts +5 -1
- package/lib/recycle-list/RecycleList.d.ts.map +1 -1
- package/lib/recycle-list/RecycleList.js +5 -19
- package/lib/recycle-list/RecycleList.js.map +1 -1
- package/lib/recycle-tree/RecycleTree.d.ts +2 -5
- package/lib/recycle-tree/RecycleTree.d.ts.map +1 -1
- package/lib/recycle-tree/RecycleTree.js +39 -68
- package/lib/recycle-tree/RecycleTree.js.map +1 -1
- package/lib/recycle-tree/basic/tree-service.d.ts +1 -1
- package/lib/recycle-tree/basic/tree-service.d.ts.map +1 -1
- package/lib/recycle-tree/basic/tree-service.js +3 -3
- package/lib/recycle-tree/basic/tree-service.js.map +1 -1
- package/lib/recycle-tree/prompt/PromptHandle.d.ts +1 -1
- package/lib/recycle-tree/prompt/PromptHandle.d.ts.map +1 -1
- package/lib/recycle-tree/prompt/PromptHandle.js +9 -9
- package/lib/recycle-tree/prompt/PromptHandle.js.map +1 -1
- package/lib/recycle-tree/tree/Tree.d.ts +2 -2
- package/lib/recycle-tree/tree/Tree.d.ts.map +1 -1
- package/lib/recycle-tree/tree/Tree.js +4 -4
- package/lib/recycle-tree/tree/Tree.js.map +1 -1
- package/lib/recycle-tree/tree/TreeNode.d.ts +2 -5
- package/lib/recycle-tree/tree/TreeNode.d.ts.map +1 -1
- package/lib/recycle-tree/tree/TreeNode.js +32 -65
- package/lib/recycle-tree/tree/TreeNode.js.map +1 -1
- package/lib/recycle-tree/tree/decoration/CompositeDecoration.d.ts +1 -1
- package/lib/recycle-tree/tree/decoration/CompositeDecoration.d.ts.map +1 -1
- package/lib/recycle-tree/tree/decoration/CompositeDecoration.js +2 -2
- package/lib/recycle-tree/tree/decoration/CompositeDecoration.js.map +1 -1
- package/lib/recycle-tree/tree/decoration/Decoration.d.ts +9 -9
- package/lib/recycle-tree/tree/decoration/Decoration.d.ts.map +1 -1
- package/lib/recycle-tree/tree/decoration/Decoration.js +11 -11
- package/lib/recycle-tree/tree/decoration/Decoration.js.map +1 -1
- package/lib/recycle-tree/tree/decoration/DecorationManager.d.ts +1 -1
- package/lib/recycle-tree/tree/decoration/DecorationManager.d.ts.map +1 -1
- package/lib/recycle-tree/tree/decoration/DecorationManager.js +3 -3
- package/lib/recycle-tree/tree/decoration/DecorationManager.js.map +1 -1
- package/lib/recycle-tree/tree/model/TreeModel.d.ts +1 -1
- package/lib/recycle-tree/tree/model/TreeModel.d.ts.map +1 -1
- package/lib/recycle-tree/tree/model/TreeModel.js +2 -2
- package/lib/recycle-tree/tree/model/TreeModel.js.map +1 -1
- package/lib/recycle-tree/tree/model/treeState/TreeStateManager.d.ts +1 -1
- package/lib/recycle-tree/tree/model/treeState/TreeStateManager.d.ts.map +1 -1
- package/lib/recycle-tree/tree/model/treeState/TreeStateManager.js +8 -7
- package/lib/recycle-tree/tree/model/treeState/TreeStateManager.js.map +1 -1
- package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.d.ts +1 -1
- package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.d.ts.map +1 -1
- package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.js +3 -3
- package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.js.map +1 -1
- package/lib/recycle-tree/types/watcher.d.ts +1 -1
- package/lib/recycle-tree/types/watcher.d.ts.map +1 -1
- package/lib/select/index.js +1 -1
- package/lib/select/index.js.map +1 -1
- package/lib/utils/index.d.ts +3 -8
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +3 -8
- package/lib/utils/index.js.map +1 -1
- package/package.json +3 -2
- package/lib/utils/cancellation.d.ts +0 -23
- package/lib/utils/cancellation.d.ts.map +0 -1
- package/lib/utils/cancellation.js +0 -116
- package/lib/utils/cancellation.js.map +0 -1
- package/lib/utils/disposable.d.ts +0 -37
- package/lib/utils/disposable.d.ts.map +0 -1
- package/lib/utils/disposable.js +0 -140
- package/lib/utils/disposable.js.map +0 -1
- package/lib/utils/event.d.ts +0 -189
- package/lib/utils/event.d.ts.map +0 -1
- package/lib/utils/event.js +0 -562
- package/lib/utils/event.js.map +0 -1
- package/lib/utils/iterator.d.ts +0 -14
- package/lib/utils/iterator.d.ts.map +0 -1
- package/lib/utils/iterator.js +0 -9
- package/lib/utils/iterator.js.map +0 -1
- package/lib/utils/linkedList.d.ts +0 -18
- package/lib/utils/linkedList.d.ts.map +0 -1
- package/lib/utils/linkedList.js +0 -139
- package/lib/utils/linkedList.js.map +0 -1
- package/lib/utils/os.d.ts +0 -4
- package/lib/utils/os.d.ts.map +0 -1
- package/lib/utils/os.js +0 -22
- package/lib/utils/os.js.map +0 -1
- package/lib/utils/path.d.ts +0 -92
- package/lib/utils/path.d.ts.map +0 -1
- package/lib/utils/path.js +0 -1694
- package/lib/utils/path.js.map +0 -1
- package/lib/utils/process.d.ts +0 -6
- package/lib/utils/process.d.ts.map +0 -1
- package/lib/utils/process.js +0 -23
- package/lib/utils/process.js.map +0 -1
package/lib/utils/path.js
DELETED
|
@@ -1,1694 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.delimiter = exports.sep = exports.toNamespacedPath = exports.parse = exports.format = exports.extname = exports.basename = exports.dirname = exports.relative = exports.resolve = exports.join = exports.isAbsolute = exports.normalize = exports.posix = exports.win32 = exports.Path = void 0;
|
|
4
|
-
// Modify from @opensumi/ide-core-common/src/path.ts
|
|
5
|
-
const os_1 = require("./os");
|
|
6
|
-
const SystemPathSeparatorRegex = os_1.isWindows ? /\\/g : /\//g;
|
|
7
|
-
/**
|
|
8
|
-
* On POSIX:
|
|
9
|
-
* ┌──────────────────────┬────────────┐
|
|
10
|
-
* │ dir │ base │
|
|
11
|
-
* ├──────┬ ├──────┬─────┤
|
|
12
|
-
* │ root │ │ name │ ext │
|
|
13
|
-
* " / home/user/dir / file .txt "
|
|
14
|
-
* └──────┴───────────────┴──────┴─────┘
|
|
15
|
-
*
|
|
16
|
-
* On Windows:
|
|
17
|
-
* ┌──────────────────────┬────────────┐
|
|
18
|
-
* │ dir │ base │
|
|
19
|
-
* ├──────┬ ├──────┬─────┤
|
|
20
|
-
* │ root │ │ name │ ext │
|
|
21
|
-
* " /c: / home/user/dir / file .txt "
|
|
22
|
-
* └──────┴───────────────┴──────┴─────┘
|
|
23
|
-
*/
|
|
24
|
-
class Path {
|
|
25
|
-
/**
|
|
26
|
-
* The raw should be normalized, meaning that only '/' is allowed as a path separator.
|
|
27
|
-
*/
|
|
28
|
-
constructor(raw) {
|
|
29
|
-
raw = raw.replace(SystemPathSeparatorRegex, Path.separator);
|
|
30
|
-
this.raw = Path.normalizeDrive(raw);
|
|
31
|
-
const firstIndex = raw.indexOf(Path.separator);
|
|
32
|
-
const lastIndex = raw.lastIndexOf(Path.separator);
|
|
33
|
-
this.isAbsolute = firstIndex === 0;
|
|
34
|
-
this.base = lastIndex === -1 ? raw : raw.substr(lastIndex + 1);
|
|
35
|
-
this.isRoot = this.isAbsolute && firstIndex === lastIndex && (!this.base || Path.isDrive(this.base));
|
|
36
|
-
this.root = this.computeRoot();
|
|
37
|
-
const extIndex = this.base.lastIndexOf('.');
|
|
38
|
-
// 处理无后缀文件或者 dot 打头的无后缀文件
|
|
39
|
-
// file like 'a/b/c/test'
|
|
40
|
-
if (extIndex === -1) {
|
|
41
|
-
this.name = this.base;
|
|
42
|
-
this.ext = '';
|
|
43
|
-
}
|
|
44
|
-
else if (extIndex === 0) {
|
|
45
|
-
// dot file like `a/b/c/.eslintrc`
|
|
46
|
-
this.name = this.base;
|
|
47
|
-
this.ext = '';
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
this.name = this.base.substr(0, extIndex);
|
|
51
|
-
this.ext = this.base.substr(extIndex);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
static isDrive(segment) {
|
|
55
|
-
return segment.endsWith(':');
|
|
56
|
-
}
|
|
57
|
-
static splitPath(path) {
|
|
58
|
-
return path.split(Path.separator).filter((path) => !!path);
|
|
59
|
-
}
|
|
60
|
-
static isRelative(path) {
|
|
61
|
-
return !path.startsWith(Path.separator);
|
|
62
|
-
}
|
|
63
|
-
static pathDepth(path) {
|
|
64
|
-
return path.split(Path.separator).length;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* vscode-uri always normalizes drive letters to lower case:
|
|
68
|
-
* https://github.com/Microsoft/vscode-uri/blob/b1d3221579f97f28a839b6f996d76fc45e9964d8/src/index.ts#L1025
|
|
69
|
-
* Theia path should be adjusted to this.
|
|
70
|
-
*/
|
|
71
|
-
static normalizeDrive(path) {
|
|
72
|
-
// lower-case windows drive letters in /C:/fff or C:/fff
|
|
73
|
-
if (path.length >= 3 && path.charCodeAt(0) === 47 /* '/' */ && path.charCodeAt(2) === 58 /* ':' */) {
|
|
74
|
-
const code = path.charCodeAt(1);
|
|
75
|
-
if (code >= 65 /* A */ && code <= 90 /* Z */) {
|
|
76
|
-
path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (path.length >= 2 && path.charCodeAt(1) === 58 /* ':' */) {
|
|
80
|
-
const code = path.charCodeAt(0);
|
|
81
|
-
if (code >= 65 /* A */ && code <= 90 /* Z */) {
|
|
82
|
-
path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return path;
|
|
86
|
-
}
|
|
87
|
-
computeRoot() {
|
|
88
|
-
// '/' -> '/'
|
|
89
|
-
// '/c:' -> '/c:'
|
|
90
|
-
if (this.isRoot) {
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
// 'foo/bar' -> `undefined`
|
|
94
|
-
if (!this.isAbsolute) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
const index = this.raw.indexOf(Path.separator, Path.separator.length);
|
|
98
|
-
if (index === -1) {
|
|
99
|
-
// '/foo/bar' -> '/'
|
|
100
|
-
return new Path(Path.separator);
|
|
101
|
-
}
|
|
102
|
-
// '/c:/foo/bar' -> '/c:'
|
|
103
|
-
// '/foo/bar' -> '/'
|
|
104
|
-
return new Path(this.raw.substr(0, index)).root;
|
|
105
|
-
}
|
|
106
|
-
get dir() {
|
|
107
|
-
if (this._dir === undefined) {
|
|
108
|
-
this._dir = this.computeDir();
|
|
109
|
-
}
|
|
110
|
-
return this._dir;
|
|
111
|
-
}
|
|
112
|
-
computeDir() {
|
|
113
|
-
if (this.isRoot) {
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
const lastIndex = this.raw.lastIndexOf(Path.separator);
|
|
117
|
-
if (lastIndex === -1) {
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
if (this.isAbsolute) {
|
|
121
|
-
const firstIndex = this.raw.indexOf(Path.separator);
|
|
122
|
-
if (firstIndex === lastIndex) {
|
|
123
|
-
return new Path(this.raw.substr(0, firstIndex + 1));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return new Path(this.raw.substr(0, lastIndex));
|
|
127
|
-
}
|
|
128
|
-
join(...paths) {
|
|
129
|
-
const code = this.raw.charCodeAt(0);
|
|
130
|
-
const isWindows = isWindowsDeviceRoot(code);
|
|
131
|
-
/**
|
|
132
|
-
* 只针对 IDE 后端运行在 Windows 的情况
|
|
133
|
-
* join('C:\\path\\to\\file', 'path/to/other') === 'C:\\path\\to\\file\\path\\to\\other'
|
|
134
|
-
*/
|
|
135
|
-
if (isWindows) {
|
|
136
|
-
return new Path(exports.win32.join(this.raw, ...paths));
|
|
137
|
-
}
|
|
138
|
-
const relativePath = paths.filter((s) => !!s).join(Path.separator);
|
|
139
|
-
if (!relativePath) {
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
if (this.raw.endsWith(Path.separator) || relativePath.startsWith(Path.separator)) {
|
|
143
|
-
return new Path(exports.posix.join(this.raw, relativePath));
|
|
144
|
-
}
|
|
145
|
-
return new Path(exports.posix.join(this.raw, Path.separator, relativePath));
|
|
146
|
-
}
|
|
147
|
-
toString() {
|
|
148
|
-
return this.raw;
|
|
149
|
-
}
|
|
150
|
-
relative(path) {
|
|
151
|
-
if (this.raw === path.raw) {
|
|
152
|
-
return new Path('');
|
|
153
|
-
}
|
|
154
|
-
if (!this.raw || !path.raw) {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
const raw = this.base ? this.raw + Path.separator : this.raw;
|
|
158
|
-
if (!path.raw.startsWith(raw)) {
|
|
159
|
-
return undefined;
|
|
160
|
-
}
|
|
161
|
-
const relativePath = path.raw.substr(raw.length);
|
|
162
|
-
return new Path(relativePath);
|
|
163
|
-
}
|
|
164
|
-
isEqualOrParent(path) {
|
|
165
|
-
return !!this.relative(path);
|
|
166
|
-
}
|
|
167
|
-
isEqual(path) {
|
|
168
|
-
return this.raw === path.raw;
|
|
169
|
-
}
|
|
170
|
-
relativity(path) {
|
|
171
|
-
const relative = this.relative(path);
|
|
172
|
-
if (relative) {
|
|
173
|
-
const relativeStr = relative.toString();
|
|
174
|
-
if (relativeStr === '') {
|
|
175
|
-
return 0;
|
|
176
|
-
}
|
|
177
|
-
return relativeStr.split(Path.separator).length;
|
|
178
|
-
}
|
|
179
|
-
return -1;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
exports.Path = Path;
|
|
183
|
-
Path.separator = '/';
|
|
184
|
-
const CHAR_UPPERCASE_A = 65; /* A */
|
|
185
|
-
const CHAR_LOWERCASE_A = 97; /* a */
|
|
186
|
-
const CHAR_UPPERCASE_Z = 90; /* Z */
|
|
187
|
-
const CHAR_LOWERCASE_Z = 122; /* z */
|
|
188
|
-
const CHAR_DOT = 46; /* . */
|
|
189
|
-
const CHAR_FORWARD_SLASH = 47; /* / */
|
|
190
|
-
const CHAR_BACKWARD_SLASH = 92; /* \ */
|
|
191
|
-
const CHAR_COLON = 58; /* : */
|
|
192
|
-
const CHAR_QUESTION_MARK = 63; /* ? */
|
|
193
|
-
class ErrorInvalidArgType extends Error {
|
|
194
|
-
constructor(name, expected, actual) {
|
|
195
|
-
// determiner: 'must be' or 'must not be'
|
|
196
|
-
let determiner;
|
|
197
|
-
if (typeof expected === 'string' && expected.indexOf('not ') === 0) {
|
|
198
|
-
determiner = 'must not be';
|
|
199
|
-
expected = expected.replace(/^not /, '');
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
determiner = 'must be';
|
|
203
|
-
}
|
|
204
|
-
const type = name.indexOf('.') !== -1 ? 'property' : 'argument';
|
|
205
|
-
let msg = `The "${name}" ${type} ${determiner} of type ${expected}`;
|
|
206
|
-
msg += `. Received type ${typeof actual}`;
|
|
207
|
-
super(msg);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function validateString(value, name) {
|
|
211
|
-
if (typeof value !== 'string') {
|
|
212
|
-
throw new ErrorInvalidArgType(name, 'string', value);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
function isPathSeparator(code) {
|
|
216
|
-
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
217
|
-
}
|
|
218
|
-
function isPosixPathSeparator(code) {
|
|
219
|
-
return code === CHAR_FORWARD_SLASH;
|
|
220
|
-
}
|
|
221
|
-
function isWindowsDeviceRoot(code) {
|
|
222
|
-
return ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) || (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z));
|
|
223
|
-
}
|
|
224
|
-
// Resolves . and .. elements in a path with directory names
|
|
225
|
-
function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
|
|
226
|
-
let res = '';
|
|
227
|
-
let lastSegmentLength = 0;
|
|
228
|
-
let lastSlash = -1;
|
|
229
|
-
let dots = 0;
|
|
230
|
-
let code;
|
|
231
|
-
for (let i = 0; i <= path.length; ++i) {
|
|
232
|
-
if (i < path.length) {
|
|
233
|
-
code = path.charCodeAt(i);
|
|
234
|
-
}
|
|
235
|
-
else if (isPathSeparator(code)) {
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
code = CHAR_FORWARD_SLASH;
|
|
240
|
-
}
|
|
241
|
-
if (isPathSeparator(code)) {
|
|
242
|
-
if (lastSlash === i - 1 || dots === 1) {
|
|
243
|
-
// NOOP
|
|
244
|
-
}
|
|
245
|
-
else if (lastSlash !== i - 1 && dots === 2) {
|
|
246
|
-
if (res.length < 2 ||
|
|
247
|
-
lastSegmentLength !== 2 ||
|
|
248
|
-
res.charCodeAt(res.length - 1) !== CHAR_DOT ||
|
|
249
|
-
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
|
|
250
|
-
if (res.length > 2) {
|
|
251
|
-
const lastSlashIndex = res.lastIndexOf(separator);
|
|
252
|
-
if (lastSlashIndex === -1) {
|
|
253
|
-
res = '';
|
|
254
|
-
lastSegmentLength = 0;
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
res = res.slice(0, lastSlashIndex);
|
|
258
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
|
|
259
|
-
}
|
|
260
|
-
lastSlash = i;
|
|
261
|
-
dots = 0;
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
else if (res.length === 2 || res.length === 1) {
|
|
265
|
-
res = '';
|
|
266
|
-
lastSegmentLength = 0;
|
|
267
|
-
lastSlash = i;
|
|
268
|
-
dots = 0;
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (allowAboveRoot) {
|
|
273
|
-
if (res.length > 0) {
|
|
274
|
-
res += `${separator}..`;
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
res = '..';
|
|
278
|
-
}
|
|
279
|
-
lastSegmentLength = 2;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
if (res.length > 0) {
|
|
284
|
-
res += separator + path.slice(lastSlash + 1, i);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
res = path.slice(lastSlash + 1, i);
|
|
288
|
-
}
|
|
289
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
290
|
-
}
|
|
291
|
-
lastSlash = i;
|
|
292
|
-
dots = 0;
|
|
293
|
-
}
|
|
294
|
-
else if (code === CHAR_DOT && dots !== -1) {
|
|
295
|
-
++dots;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
dots = -1;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return res;
|
|
302
|
-
}
|
|
303
|
-
function _format(sep, pathObject) {
|
|
304
|
-
const dir = pathObject.dir || pathObject.root;
|
|
305
|
-
const base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
|
|
306
|
-
if (!dir) {
|
|
307
|
-
return base;
|
|
308
|
-
}
|
|
309
|
-
if (dir === pathObject.root) {
|
|
310
|
-
return dir + base;
|
|
311
|
-
}
|
|
312
|
-
return dir + sep + base;
|
|
313
|
-
}
|
|
314
|
-
exports.win32 = {
|
|
315
|
-
// path.resolve([from ...], to)
|
|
316
|
-
resolve(...pathSegments) {
|
|
317
|
-
let resolvedDevice = '';
|
|
318
|
-
let resolvedTail = '';
|
|
319
|
-
let resolvedAbsolute = false;
|
|
320
|
-
for (let i = pathSegments.length - 1; i >= -1; i--) {
|
|
321
|
-
let path;
|
|
322
|
-
if (i >= 0) {
|
|
323
|
-
path = pathSegments[i];
|
|
324
|
-
}
|
|
325
|
-
else if (!resolvedDevice) {
|
|
326
|
-
path = process.cwd();
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
// Windows has the concept of drive-specific current working
|
|
330
|
-
// directories. If we've resolved a drive letter but not yet an
|
|
331
|
-
// absolute path, get cwd for that drive, or the process cwd if
|
|
332
|
-
// the drive cwd is not available. We're sure the device is not
|
|
333
|
-
// a UNC path at this points, because UNC paths are always absolute.
|
|
334
|
-
path = process.env['=' + resolvedDevice] || process.cwd();
|
|
335
|
-
// Verify that a cwd was found and that it actually points
|
|
336
|
-
// to our drive. If not, default to the drive's root.
|
|
337
|
-
if (path === undefined || path.slice(0, 3).toLowerCase() !== resolvedDevice.toLowerCase() + '\\') {
|
|
338
|
-
path = resolvedDevice + '\\';
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
validateString(path, 'path');
|
|
342
|
-
// Skip empty entries
|
|
343
|
-
if (path.length === 0) {
|
|
344
|
-
continue;
|
|
345
|
-
}
|
|
346
|
-
const len = path.length;
|
|
347
|
-
let rootEnd = 0;
|
|
348
|
-
let device = '';
|
|
349
|
-
let isAbsolute = false;
|
|
350
|
-
const code = path.charCodeAt(0);
|
|
351
|
-
// Try to match a root
|
|
352
|
-
if (len > 1) {
|
|
353
|
-
if (isPathSeparator(code)) {
|
|
354
|
-
// Possible UNC root
|
|
355
|
-
// If we started with a separator, we know we at least have an
|
|
356
|
-
// absolute path of some kind (UNC or otherwise)
|
|
357
|
-
isAbsolute = true;
|
|
358
|
-
if (isPathSeparator(path.charCodeAt(1))) {
|
|
359
|
-
// Matched double path separator at beginning
|
|
360
|
-
let j = 2;
|
|
361
|
-
let last = j;
|
|
362
|
-
// Match 1 or more non-path separators
|
|
363
|
-
for (; j < len; ++j) {
|
|
364
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if (j < len && j !== last) {
|
|
369
|
-
const firstPart = path.slice(last, j);
|
|
370
|
-
// Matched!
|
|
371
|
-
last = j;
|
|
372
|
-
// Match 1 or more path separators
|
|
373
|
-
for (; j < len; ++j) {
|
|
374
|
-
if (!isPathSeparator(path.charCodeAt(j))) {
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (j < len && j !== last) {
|
|
379
|
-
// Matched!
|
|
380
|
-
last = j;
|
|
381
|
-
// Match 1 or more non-path separators
|
|
382
|
-
for (; j < len; ++j) {
|
|
383
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
if (j === len) {
|
|
388
|
-
// We matched a UNC root only
|
|
389
|
-
device = '\\\\' + firstPart + '\\' + path.slice(last);
|
|
390
|
-
rootEnd = j;
|
|
391
|
-
}
|
|
392
|
-
else if (j !== last) {
|
|
393
|
-
// We matched a UNC root with leftovers
|
|
394
|
-
device = '\\\\' + firstPart + '\\' + path.slice(last, j);
|
|
395
|
-
rootEnd = j;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
rootEnd = 1;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
else if (isWindowsDeviceRoot(code)) {
|
|
405
|
-
// Possible device root
|
|
406
|
-
if (path.charCodeAt(1) === CHAR_COLON) {
|
|
407
|
-
device = path.slice(0, 2);
|
|
408
|
-
rootEnd = 2;
|
|
409
|
-
if (len > 2) {
|
|
410
|
-
if (isPathSeparator(path.charCodeAt(2))) {
|
|
411
|
-
// Treat separator following drive name as an absolute path
|
|
412
|
-
// indicator
|
|
413
|
-
isAbsolute = true;
|
|
414
|
-
rootEnd = 3;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
else if (isPathSeparator(code)) {
|
|
421
|
-
// `path` contains just a path separator
|
|
422
|
-
rootEnd = 1;
|
|
423
|
-
isAbsolute = true;
|
|
424
|
-
}
|
|
425
|
-
if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) {
|
|
426
|
-
// This path points to another device so it is not applicable
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
if (resolvedDevice.length === 0 && device.length > 0) {
|
|
430
|
-
resolvedDevice = device;
|
|
431
|
-
}
|
|
432
|
-
if (!resolvedAbsolute) {
|
|
433
|
-
resolvedTail = path.slice(rootEnd) + '\\' + resolvedTail;
|
|
434
|
-
resolvedAbsolute = isAbsolute;
|
|
435
|
-
}
|
|
436
|
-
if (resolvedDevice.length > 0 && resolvedAbsolute) {
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
// At this point the path should be resolved to a full absolute path,
|
|
441
|
-
// but handle relative paths to be safe (might happen when process.cwd()
|
|
442
|
-
// fails)
|
|
443
|
-
// Normalize the tail path
|
|
444
|
-
resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparator);
|
|
445
|
-
return resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail || '.';
|
|
446
|
-
},
|
|
447
|
-
normalize(path) {
|
|
448
|
-
validateString(path, 'path');
|
|
449
|
-
const len = path.length;
|
|
450
|
-
if (len === 0) {
|
|
451
|
-
return '.';
|
|
452
|
-
}
|
|
453
|
-
let rootEnd = 0;
|
|
454
|
-
let device;
|
|
455
|
-
let isAbsolute = false;
|
|
456
|
-
const code = path.charCodeAt(0);
|
|
457
|
-
// Try to match a root
|
|
458
|
-
if (len > 1) {
|
|
459
|
-
if (isPathSeparator(code)) {
|
|
460
|
-
// Possible UNC root
|
|
461
|
-
// If we started with a separator, we know we at least have an absolute
|
|
462
|
-
// path of some kind (UNC or otherwise)
|
|
463
|
-
isAbsolute = true;
|
|
464
|
-
if (isPathSeparator(path.charCodeAt(1))) {
|
|
465
|
-
// Matched double path separator at beginning
|
|
466
|
-
let j = 2;
|
|
467
|
-
let last = j;
|
|
468
|
-
// Match 1 or more non-path separators
|
|
469
|
-
for (; j < len; ++j) {
|
|
470
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
if (j < len && j !== last) {
|
|
475
|
-
const firstPart = path.slice(last, j);
|
|
476
|
-
// Matched!
|
|
477
|
-
last = j;
|
|
478
|
-
// Match 1 or more path separators
|
|
479
|
-
for (; j < len; ++j) {
|
|
480
|
-
if (!isPathSeparator(path.charCodeAt(j))) {
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (j < len && j !== last) {
|
|
485
|
-
// Matched!
|
|
486
|
-
last = j;
|
|
487
|
-
// Match 1 or more non-path separators
|
|
488
|
-
for (; j < len; ++j) {
|
|
489
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
490
|
-
break;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
if (j === len) {
|
|
494
|
-
// We matched a UNC root only
|
|
495
|
-
// Return the normalized version of the UNC root since there
|
|
496
|
-
// is nothing left to process
|
|
497
|
-
return '\\\\' + firstPart + '\\' + path.slice(last) + '\\';
|
|
498
|
-
}
|
|
499
|
-
else if (j !== last) {
|
|
500
|
-
// We matched a UNC root with leftovers
|
|
501
|
-
device = '\\\\' + firstPart + '\\' + path.slice(last, j);
|
|
502
|
-
rootEnd = j;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
rootEnd = 1;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
else if (isWindowsDeviceRoot(code)) {
|
|
512
|
-
// Possible device root
|
|
513
|
-
if (path.charCodeAt(1) === CHAR_COLON) {
|
|
514
|
-
device = path.slice(0, 2);
|
|
515
|
-
rootEnd = 2;
|
|
516
|
-
if (len > 2) {
|
|
517
|
-
if (isPathSeparator(path.charCodeAt(2))) {
|
|
518
|
-
// Treat separator following drive name as an absolute path
|
|
519
|
-
// indicator
|
|
520
|
-
isAbsolute = true;
|
|
521
|
-
rootEnd = 3;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
else if (isPathSeparator(code)) {
|
|
528
|
-
// `path` contains just a path separator, exit early to avoid unnecessary
|
|
529
|
-
// work
|
|
530
|
-
return '\\';
|
|
531
|
-
}
|
|
532
|
-
let tail;
|
|
533
|
-
if (rootEnd < len) {
|
|
534
|
-
tail = normalizeString(path.slice(rootEnd), !isAbsolute, '\\', isPathSeparator);
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
tail = '';
|
|
538
|
-
}
|
|
539
|
-
if (tail.length === 0 && !isAbsolute) {
|
|
540
|
-
tail = '.';
|
|
541
|
-
}
|
|
542
|
-
if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) {
|
|
543
|
-
tail += '\\';
|
|
544
|
-
}
|
|
545
|
-
if (device === undefined) {
|
|
546
|
-
if (isAbsolute) {
|
|
547
|
-
if (tail.length > 0) {
|
|
548
|
-
return '\\' + tail;
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
return '\\';
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
else if (tail.length > 0) {
|
|
555
|
-
return tail;
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
return '';
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
else if (isAbsolute) {
|
|
562
|
-
if (tail.length > 0) {
|
|
563
|
-
return device + '\\' + tail;
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
return device + '\\';
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
else if (tail.length > 0) {
|
|
570
|
-
return device + tail;
|
|
571
|
-
}
|
|
572
|
-
else {
|
|
573
|
-
return device;
|
|
574
|
-
}
|
|
575
|
-
},
|
|
576
|
-
isAbsolute(path) {
|
|
577
|
-
validateString(path, 'path');
|
|
578
|
-
const len = path.length;
|
|
579
|
-
if (len === 0) {
|
|
580
|
-
return false;
|
|
581
|
-
}
|
|
582
|
-
const code = path.charCodeAt(0);
|
|
583
|
-
if (isPathSeparator(code)) {
|
|
584
|
-
return true;
|
|
585
|
-
}
|
|
586
|
-
else if (isWindowsDeviceRoot(code)) {
|
|
587
|
-
// Possible device root
|
|
588
|
-
if (len > 2 && path.charCodeAt(1) === CHAR_COLON) {
|
|
589
|
-
if (isPathSeparator(path.charCodeAt(2))) {
|
|
590
|
-
return true;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return false;
|
|
595
|
-
},
|
|
596
|
-
join(...paths) {
|
|
597
|
-
if (paths.length === 0) {
|
|
598
|
-
return '.';
|
|
599
|
-
}
|
|
600
|
-
let joined;
|
|
601
|
-
let firstPart;
|
|
602
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
603
|
-
for (let i = 0; i < paths.length; ++i) {
|
|
604
|
-
const arg = paths[i];
|
|
605
|
-
validateString(arg, 'path');
|
|
606
|
-
if (arg.length > 0) {
|
|
607
|
-
if (joined === undefined) {
|
|
608
|
-
joined = firstPart = arg;
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
joined += '\\' + arg;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
if (joined === undefined) {
|
|
616
|
-
return '.';
|
|
617
|
-
}
|
|
618
|
-
// Make sure that the joined path doesn't start with two slashes, because
|
|
619
|
-
// normalize() will mistake it for an UNC path then.
|
|
620
|
-
//
|
|
621
|
-
// This step is skipped when it is very clear that the user actually
|
|
622
|
-
// intended to point at an UNC path. This is assumed when the first
|
|
623
|
-
// non-empty string arguments starts with exactly two slashes followed by
|
|
624
|
-
// at least one more non-slash character.
|
|
625
|
-
//
|
|
626
|
-
// Note that for normalize() to treat a path as an UNC path it needs to
|
|
627
|
-
// have at least 2 components, so we don't filter for that here.
|
|
628
|
-
// This means that the user can use join to construct UNC paths from
|
|
629
|
-
// a server name and a share name; for example:
|
|
630
|
-
// path.join('//server', 'share') -> '\\\\server\\share\\')
|
|
631
|
-
let needsReplace = true;
|
|
632
|
-
let slashCount = 0;
|
|
633
|
-
if (typeof firstPart === 'string' && isPathSeparator(firstPart.charCodeAt(0))) {
|
|
634
|
-
++slashCount;
|
|
635
|
-
const firstLen = firstPart.length;
|
|
636
|
-
if (firstLen > 1) {
|
|
637
|
-
if (isPathSeparator(firstPart.charCodeAt(1))) {
|
|
638
|
-
++slashCount;
|
|
639
|
-
if (firstLen > 2) {
|
|
640
|
-
if (isPathSeparator(firstPart.charCodeAt(2))) {
|
|
641
|
-
++slashCount;
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
// We matched a UNC path in the first part
|
|
645
|
-
needsReplace = false;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
if (needsReplace) {
|
|
652
|
-
// Find any more consecutive slashes we need to replace
|
|
653
|
-
for (; slashCount < joined.length; ++slashCount) {
|
|
654
|
-
if (!isPathSeparator(joined.charCodeAt(slashCount))) {
|
|
655
|
-
break;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
// Replace the slashes if needed
|
|
659
|
-
if (slashCount >= 2) {
|
|
660
|
-
joined = '\\' + joined.slice(slashCount);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
return exports.win32.normalize(joined);
|
|
664
|
-
},
|
|
665
|
-
// It will solve the relative path from `from` to `to`, for instance:
|
|
666
|
-
// from = 'C:\\orandea\\test\\aaa'
|
|
667
|
-
// to = 'C:\\orandea\\impl\\bbb'
|
|
668
|
-
// The output of the function should be: '..\\..\\impl\\bbb'
|
|
669
|
-
relative(from, to) {
|
|
670
|
-
validateString(from, 'from');
|
|
671
|
-
validateString(to, 'to');
|
|
672
|
-
if (from === to) {
|
|
673
|
-
return '';
|
|
674
|
-
}
|
|
675
|
-
const fromOrig = exports.win32.resolve(from);
|
|
676
|
-
const toOrig = exports.win32.resolve(to);
|
|
677
|
-
if (fromOrig === toOrig) {
|
|
678
|
-
return '';
|
|
679
|
-
}
|
|
680
|
-
from = fromOrig.toLowerCase();
|
|
681
|
-
to = toOrig.toLowerCase();
|
|
682
|
-
if (from === to) {
|
|
683
|
-
return '';
|
|
684
|
-
}
|
|
685
|
-
// Trim any leading backslashes
|
|
686
|
-
let fromStart = 0;
|
|
687
|
-
for (; fromStart < from.length; ++fromStart) {
|
|
688
|
-
if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) {
|
|
689
|
-
break;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
// Trim trailing backslashes (applicable to UNC paths only)
|
|
693
|
-
let fromEnd = from.length;
|
|
694
|
-
for (; fromEnd - 1 > fromStart; --fromEnd) {
|
|
695
|
-
if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) {
|
|
696
|
-
break;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
const fromLen = fromEnd - fromStart;
|
|
700
|
-
// Trim any leading backslashes
|
|
701
|
-
let toStart = 0;
|
|
702
|
-
for (; toStart < to.length; ++toStart) {
|
|
703
|
-
if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) {
|
|
704
|
-
break;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
// Trim trailing backslashes (applicable to UNC paths only)
|
|
708
|
-
let toEnd = to.length;
|
|
709
|
-
for (; toEnd - 1 > toStart; --toEnd) {
|
|
710
|
-
if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) {
|
|
711
|
-
break;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
const toLen = toEnd - toStart;
|
|
715
|
-
// Compare paths to find the longest common path from root
|
|
716
|
-
const length = fromLen < toLen ? fromLen : toLen;
|
|
717
|
-
let lastCommonSep = -1;
|
|
718
|
-
let i = 0;
|
|
719
|
-
for (; i <= length; ++i) {
|
|
720
|
-
if (i === length) {
|
|
721
|
-
if (toLen > length) {
|
|
722
|
-
if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
|
|
723
|
-
// We get here if `from` is the exact base path for `to`.
|
|
724
|
-
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
|
|
725
|
-
return toOrig.slice(toStart + i + 1);
|
|
726
|
-
}
|
|
727
|
-
else if (i === 2) {
|
|
728
|
-
// We get here if `from` is the device root.
|
|
729
|
-
// For example: from='C:\\'; to='C:\\foo'
|
|
730
|
-
return toOrig.slice(toStart + i);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
if (fromLen > length) {
|
|
734
|
-
if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
|
|
735
|
-
// We get here if `to` is the exact base path for `from`.
|
|
736
|
-
// For example: from='C:\\foo\\bar'; to='C:\\foo'
|
|
737
|
-
lastCommonSep = i;
|
|
738
|
-
}
|
|
739
|
-
else if (i === 2) {
|
|
740
|
-
// We get here if `to` is the device root.
|
|
741
|
-
// For example: from='C:\\foo\\bar'; to='C:\\'
|
|
742
|
-
lastCommonSep = 3;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
const fromCode = from.charCodeAt(fromStart + i);
|
|
748
|
-
const toCode = to.charCodeAt(toStart + i);
|
|
749
|
-
if (fromCode !== toCode) {
|
|
750
|
-
break;
|
|
751
|
-
}
|
|
752
|
-
else if (fromCode === CHAR_BACKWARD_SLASH) {
|
|
753
|
-
lastCommonSep = i;
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
// We found a mismatch before the first common path separator was seen, so
|
|
757
|
-
// return the original `to`.
|
|
758
|
-
if (i !== length && lastCommonSep === -1) {
|
|
759
|
-
return toOrig;
|
|
760
|
-
}
|
|
761
|
-
let out = '';
|
|
762
|
-
if (lastCommonSep === -1) {
|
|
763
|
-
lastCommonSep = 0;
|
|
764
|
-
}
|
|
765
|
-
// Generate the relative path based on the path difference between `to` and
|
|
766
|
-
// `from`
|
|
767
|
-
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
768
|
-
if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
|
|
769
|
-
if (out.length === 0) {
|
|
770
|
-
out += '..';
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
out += '\\..';
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
778
|
-
// the common path parts
|
|
779
|
-
if (out.length > 0) {
|
|
780
|
-
return out + toOrig.slice(toStart + lastCommonSep, toEnd);
|
|
781
|
-
}
|
|
782
|
-
else {
|
|
783
|
-
toStart += lastCommonSep;
|
|
784
|
-
if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
|
|
785
|
-
++toStart;
|
|
786
|
-
}
|
|
787
|
-
return toOrig.slice(toStart, toEnd);
|
|
788
|
-
}
|
|
789
|
-
},
|
|
790
|
-
toNamespacedPath(path) {
|
|
791
|
-
// Note: this will *probably* throw somewhere.
|
|
792
|
-
if (typeof path !== 'string') {
|
|
793
|
-
return path;
|
|
794
|
-
}
|
|
795
|
-
if (path.length === 0) {
|
|
796
|
-
return '';
|
|
797
|
-
}
|
|
798
|
-
const resolvedPath = exports.win32.resolve(path);
|
|
799
|
-
if (resolvedPath.length >= 3) {
|
|
800
|
-
if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
|
|
801
|
-
// Possible UNC root
|
|
802
|
-
if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
|
|
803
|
-
const code = resolvedPath.charCodeAt(2);
|
|
804
|
-
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
|
|
805
|
-
// Matched non-long UNC root, convert the path to a long UNC path
|
|
806
|
-
return '\\\\?\\UNC\\' + resolvedPath.slice(2);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) {
|
|
811
|
-
// Possible device root
|
|
812
|
-
if (resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
|
|
813
|
-
// Matched device root, convert the path to a long UNC path
|
|
814
|
-
return '\\\\?\\' + resolvedPath;
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
return path;
|
|
819
|
-
},
|
|
820
|
-
dirname(path) {
|
|
821
|
-
validateString(path, 'path');
|
|
822
|
-
const len = path.length;
|
|
823
|
-
if (len === 0) {
|
|
824
|
-
return '.';
|
|
825
|
-
}
|
|
826
|
-
let rootEnd = -1;
|
|
827
|
-
let end = -1;
|
|
828
|
-
let matchedSlash = true;
|
|
829
|
-
let offset = 0;
|
|
830
|
-
const code = path.charCodeAt(0);
|
|
831
|
-
// Try to match a root
|
|
832
|
-
if (len > 1) {
|
|
833
|
-
if (isPathSeparator(code)) {
|
|
834
|
-
// Possible UNC root
|
|
835
|
-
rootEnd = offset = 1;
|
|
836
|
-
if (isPathSeparator(path.charCodeAt(1))) {
|
|
837
|
-
// Matched double path separator at beginning
|
|
838
|
-
let j = 2;
|
|
839
|
-
let last = j;
|
|
840
|
-
// Match 1 or more non-path separators
|
|
841
|
-
for (; j < len; ++j) {
|
|
842
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
843
|
-
break;
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
if (j < len && j !== last) {
|
|
847
|
-
// Matched!
|
|
848
|
-
last = j;
|
|
849
|
-
// Match 1 or more path separators
|
|
850
|
-
for (; j < len; ++j) {
|
|
851
|
-
if (!isPathSeparator(path.charCodeAt(j))) {
|
|
852
|
-
break;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
if (j < len && j !== last) {
|
|
856
|
-
// Matched!
|
|
857
|
-
last = j;
|
|
858
|
-
// Match 1 or more non-path separators
|
|
859
|
-
for (; j < len; ++j) {
|
|
860
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
861
|
-
break;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
if (j === len) {
|
|
865
|
-
// We matched a UNC root only
|
|
866
|
-
return path;
|
|
867
|
-
}
|
|
868
|
-
if (j !== last) {
|
|
869
|
-
// We matched a UNC root with leftovers
|
|
870
|
-
// Offset by 1 to include the separator after the UNC root to
|
|
871
|
-
// treat it as a "normal root" on top of a (UNC) root
|
|
872
|
-
rootEnd = offset = j + 1;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
else if (isWindowsDeviceRoot(code)) {
|
|
879
|
-
// Possible device root
|
|
880
|
-
if (path.charCodeAt(1) === CHAR_COLON) {
|
|
881
|
-
rootEnd = offset = 2;
|
|
882
|
-
if (len > 2) {
|
|
883
|
-
if (isPathSeparator(path.charCodeAt(2))) {
|
|
884
|
-
rootEnd = offset = 3;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
else if (isPathSeparator(code)) {
|
|
891
|
-
// `path` contains just a path separator, exit early to avoid
|
|
892
|
-
// unnecessary work
|
|
893
|
-
return path;
|
|
894
|
-
}
|
|
895
|
-
for (let i = len - 1; i >= offset; --i) {
|
|
896
|
-
if (isPathSeparator(path.charCodeAt(i))) {
|
|
897
|
-
if (!matchedSlash) {
|
|
898
|
-
end = i;
|
|
899
|
-
break;
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
else {
|
|
903
|
-
// We saw the first non-path separator
|
|
904
|
-
matchedSlash = false;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
if (end === -1) {
|
|
908
|
-
if (rootEnd === -1) {
|
|
909
|
-
return '.';
|
|
910
|
-
}
|
|
911
|
-
else {
|
|
912
|
-
end = rootEnd;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
return path.slice(0, end);
|
|
916
|
-
},
|
|
917
|
-
basename(path, ext) {
|
|
918
|
-
if (ext !== undefined) {
|
|
919
|
-
validateString(ext, 'ext');
|
|
920
|
-
}
|
|
921
|
-
validateString(path, 'path');
|
|
922
|
-
let start = 0;
|
|
923
|
-
let end = -1;
|
|
924
|
-
let matchedSlash = true;
|
|
925
|
-
let i;
|
|
926
|
-
// Check for a drive letter prefix so as not to mistake the following
|
|
927
|
-
// path separator as an extra separator at the end of the path that can be
|
|
928
|
-
// disregarded
|
|
929
|
-
if (path.length >= 2) {
|
|
930
|
-
const drive = path.charCodeAt(0);
|
|
931
|
-
if (isWindowsDeviceRoot(drive)) {
|
|
932
|
-
if (path.charCodeAt(1) === CHAR_COLON) {
|
|
933
|
-
start = 2;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
938
|
-
if (ext.length === path.length && ext === path) {
|
|
939
|
-
return '';
|
|
940
|
-
}
|
|
941
|
-
let extIdx = ext.length - 1;
|
|
942
|
-
let firstNonSlashEnd = -1;
|
|
943
|
-
for (i = path.length - 1; i >= start; --i) {
|
|
944
|
-
const code = path.charCodeAt(i);
|
|
945
|
-
if (isPathSeparator(code)) {
|
|
946
|
-
// If we reached a path separator that was not part of a set of path
|
|
947
|
-
// separators at the end of the string, stop now
|
|
948
|
-
if (!matchedSlash) {
|
|
949
|
-
start = i + 1;
|
|
950
|
-
break;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
else {
|
|
954
|
-
if (firstNonSlashEnd === -1) {
|
|
955
|
-
// We saw the first non-path separator, remember this index in case
|
|
956
|
-
// we need it if the extension ends up not matching
|
|
957
|
-
matchedSlash = false;
|
|
958
|
-
firstNonSlashEnd = i + 1;
|
|
959
|
-
}
|
|
960
|
-
if (extIdx >= 0) {
|
|
961
|
-
// Try to match the explicit extension
|
|
962
|
-
if (code === ext.charCodeAt(extIdx)) {
|
|
963
|
-
if (--extIdx === -1) {
|
|
964
|
-
// We matched the extension, so mark this as the end of our path
|
|
965
|
-
// component
|
|
966
|
-
end = i;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
else {
|
|
970
|
-
// Extension does not match, so our result is the entire path
|
|
971
|
-
// component
|
|
972
|
-
extIdx = -1;
|
|
973
|
-
end = firstNonSlashEnd;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
if (start === end) {
|
|
979
|
-
end = firstNonSlashEnd;
|
|
980
|
-
}
|
|
981
|
-
else if (end === -1) {
|
|
982
|
-
end = path.length;
|
|
983
|
-
}
|
|
984
|
-
return path.slice(start, end);
|
|
985
|
-
}
|
|
986
|
-
else {
|
|
987
|
-
for (i = path.length - 1; i >= start; --i) {
|
|
988
|
-
if (isPathSeparator(path.charCodeAt(i))) {
|
|
989
|
-
// If we reached a path separator that was not part of a set of path
|
|
990
|
-
// separators at the end of the string, stop now
|
|
991
|
-
if (!matchedSlash) {
|
|
992
|
-
start = i + 1;
|
|
993
|
-
break;
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
else if (end === -1) {
|
|
997
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
998
|
-
// path component
|
|
999
|
-
matchedSlash = false;
|
|
1000
|
-
end = i + 1;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
if (end === -1) {
|
|
1004
|
-
return '';
|
|
1005
|
-
}
|
|
1006
|
-
return path.slice(start, end);
|
|
1007
|
-
}
|
|
1008
|
-
},
|
|
1009
|
-
extname(path) {
|
|
1010
|
-
validateString(path, 'path');
|
|
1011
|
-
let start = 0;
|
|
1012
|
-
let startDot = -1;
|
|
1013
|
-
let startPart = 0;
|
|
1014
|
-
let end = -1;
|
|
1015
|
-
let matchedSlash = true;
|
|
1016
|
-
// Track the state of characters (if any) we see before our first dot and
|
|
1017
|
-
// after any path separator we find
|
|
1018
|
-
let preDotState = 0;
|
|
1019
|
-
// Check for a drive letter prefix so as not to mistake the following
|
|
1020
|
-
// path separator as an extra separator at the end of the path that can be
|
|
1021
|
-
// disregarded
|
|
1022
|
-
if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) {
|
|
1023
|
-
start = startPart = 2;
|
|
1024
|
-
}
|
|
1025
|
-
for (let i = path.length - 1; i >= start; --i) {
|
|
1026
|
-
const code = path.charCodeAt(i);
|
|
1027
|
-
if (isPathSeparator(code)) {
|
|
1028
|
-
// If we reached a path separator that was not part of a set of path
|
|
1029
|
-
// separators at the end of the string, stop now
|
|
1030
|
-
if (!matchedSlash) {
|
|
1031
|
-
startPart = i + 1;
|
|
1032
|
-
break;
|
|
1033
|
-
}
|
|
1034
|
-
continue;
|
|
1035
|
-
}
|
|
1036
|
-
if (end === -1) {
|
|
1037
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
1038
|
-
// extension
|
|
1039
|
-
matchedSlash = false;
|
|
1040
|
-
end = i + 1;
|
|
1041
|
-
}
|
|
1042
|
-
if (code === CHAR_DOT) {
|
|
1043
|
-
// If this is our first dot, mark it as the start of our extension
|
|
1044
|
-
if (startDot === -1) {
|
|
1045
|
-
startDot = i;
|
|
1046
|
-
}
|
|
1047
|
-
else if (preDotState !== 1) {
|
|
1048
|
-
preDotState = 1;
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
else if (startDot !== -1) {
|
|
1052
|
-
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1053
|
-
// have a good chance at having a non-empty extension
|
|
1054
|
-
preDotState = -1;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
if (startDot === -1 ||
|
|
1058
|
-
end === -1 ||
|
|
1059
|
-
// We saw a non-dot character immediately before the dot
|
|
1060
|
-
preDotState === 0 ||
|
|
1061
|
-
// The (right-most) trimmed path component is exactly '..'
|
|
1062
|
-
(preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
|
|
1063
|
-
return '';
|
|
1064
|
-
}
|
|
1065
|
-
return path.slice(startDot, end);
|
|
1066
|
-
},
|
|
1067
|
-
format(pathObject) {
|
|
1068
|
-
if (pathObject === null || typeof pathObject !== 'object') {
|
|
1069
|
-
throw new ErrorInvalidArgType('pathObject', 'Object', pathObject);
|
|
1070
|
-
}
|
|
1071
|
-
return _format('\\', pathObject);
|
|
1072
|
-
},
|
|
1073
|
-
parse(path) {
|
|
1074
|
-
validateString(path, 'path');
|
|
1075
|
-
const ret = { root: '', dir: '', base: '', ext: '', name: '' };
|
|
1076
|
-
if (path.length === 0) {
|
|
1077
|
-
return ret;
|
|
1078
|
-
}
|
|
1079
|
-
const len = path.length;
|
|
1080
|
-
let rootEnd = 0;
|
|
1081
|
-
let code = path.charCodeAt(0);
|
|
1082
|
-
// Try to match a root
|
|
1083
|
-
if (len > 1) {
|
|
1084
|
-
if (isPathSeparator(code)) {
|
|
1085
|
-
// Possible UNC root
|
|
1086
|
-
rootEnd = 1;
|
|
1087
|
-
if (isPathSeparator(path.charCodeAt(1))) {
|
|
1088
|
-
// Matched double path separator at beginning
|
|
1089
|
-
let j = 2;
|
|
1090
|
-
let last = j;
|
|
1091
|
-
// Match 1 or more non-path separators
|
|
1092
|
-
for (; j < len; ++j) {
|
|
1093
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
1094
|
-
break;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
if (j < len && j !== last) {
|
|
1098
|
-
// Matched!
|
|
1099
|
-
last = j;
|
|
1100
|
-
// Match 1 or more path separators
|
|
1101
|
-
for (; j < len; ++j) {
|
|
1102
|
-
if (!isPathSeparator(path.charCodeAt(j))) {
|
|
1103
|
-
break;
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
if (j < len && j !== last) {
|
|
1107
|
-
// Matched!
|
|
1108
|
-
last = j;
|
|
1109
|
-
// Match 1 or more non-path separators
|
|
1110
|
-
for (; j < len; ++j) {
|
|
1111
|
-
if (isPathSeparator(path.charCodeAt(j))) {
|
|
1112
|
-
break;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
if (j === len) {
|
|
1116
|
-
// We matched a UNC root only
|
|
1117
|
-
rootEnd = j;
|
|
1118
|
-
}
|
|
1119
|
-
else if (j !== last) {
|
|
1120
|
-
// We matched a UNC root with leftovers
|
|
1121
|
-
rootEnd = j + 1;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
else if (isWindowsDeviceRoot(code)) {
|
|
1128
|
-
// Possible device root
|
|
1129
|
-
if (path.charCodeAt(1) === CHAR_COLON) {
|
|
1130
|
-
rootEnd = 2;
|
|
1131
|
-
if (len > 2) {
|
|
1132
|
-
if (isPathSeparator(path.charCodeAt(2))) {
|
|
1133
|
-
if (len === 3) {
|
|
1134
|
-
// `path` contains just a drive root, exit early to avoid
|
|
1135
|
-
// unnecessary work
|
|
1136
|
-
ret.root = ret.dir = path;
|
|
1137
|
-
return ret;
|
|
1138
|
-
}
|
|
1139
|
-
rootEnd = 3;
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
else {
|
|
1143
|
-
// `path` contains just a drive root, exit early to avoid
|
|
1144
|
-
// unnecessary work
|
|
1145
|
-
ret.root = ret.dir = path;
|
|
1146
|
-
return ret;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
else if (isPathSeparator(code)) {
|
|
1152
|
-
// `path` contains just a path separator, exit early to avoid
|
|
1153
|
-
// unnecessary work
|
|
1154
|
-
ret.root = ret.dir = path;
|
|
1155
|
-
return ret;
|
|
1156
|
-
}
|
|
1157
|
-
if (rootEnd > 0) {
|
|
1158
|
-
ret.root = path.slice(0, rootEnd);
|
|
1159
|
-
}
|
|
1160
|
-
let startDot = -1;
|
|
1161
|
-
let startPart = rootEnd;
|
|
1162
|
-
let end = -1;
|
|
1163
|
-
let matchedSlash = true;
|
|
1164
|
-
let i = path.length - 1;
|
|
1165
|
-
// Track the state of characters (if any) we see before our first dot and
|
|
1166
|
-
// after any path separator we find
|
|
1167
|
-
let preDotState = 0;
|
|
1168
|
-
// Get non-dir info
|
|
1169
|
-
for (; i >= rootEnd; --i) {
|
|
1170
|
-
code = path.charCodeAt(i);
|
|
1171
|
-
if (isPathSeparator(code)) {
|
|
1172
|
-
// If we reached a path separator that was not part of a set of path
|
|
1173
|
-
// separators at the end of the string, stop now
|
|
1174
|
-
if (!matchedSlash) {
|
|
1175
|
-
startPart = i + 1;
|
|
1176
|
-
break;
|
|
1177
|
-
}
|
|
1178
|
-
continue;
|
|
1179
|
-
}
|
|
1180
|
-
if (end === -1) {
|
|
1181
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
1182
|
-
// extension
|
|
1183
|
-
matchedSlash = false;
|
|
1184
|
-
end = i + 1;
|
|
1185
|
-
}
|
|
1186
|
-
if (code === CHAR_DOT) {
|
|
1187
|
-
// If this is our first dot, mark it as the start of our extension
|
|
1188
|
-
if (startDot === -1) {
|
|
1189
|
-
startDot = i;
|
|
1190
|
-
}
|
|
1191
|
-
else if (preDotState !== 1) {
|
|
1192
|
-
preDotState = 1;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
else if (startDot !== -1) {
|
|
1196
|
-
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1197
|
-
// have a good chance at having a non-empty extension
|
|
1198
|
-
preDotState = -1;
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
if (startDot === -1 ||
|
|
1202
|
-
end === -1 ||
|
|
1203
|
-
// We saw a non-dot character immediately before the dot
|
|
1204
|
-
preDotState === 0 ||
|
|
1205
|
-
// The (right-most) trimmed path component is exactly '..'
|
|
1206
|
-
(preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
|
|
1207
|
-
if (end !== -1) {
|
|
1208
|
-
ret.base = ret.name = path.slice(startPart, end);
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
else {
|
|
1212
|
-
ret.name = path.slice(startPart, startDot);
|
|
1213
|
-
ret.base = path.slice(startPart, end);
|
|
1214
|
-
ret.ext = path.slice(startDot, end);
|
|
1215
|
-
}
|
|
1216
|
-
// If the directory is the root, use the entire root as the `dir` including
|
|
1217
|
-
// the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
|
|
1218
|
-
// trailing slash (`C:\abc\def` -> `C:\abc`).
|
|
1219
|
-
if (startPart > 0 && startPart !== rootEnd) {
|
|
1220
|
-
ret.dir = path.slice(0, startPart - 1);
|
|
1221
|
-
}
|
|
1222
|
-
else {
|
|
1223
|
-
ret.dir = ret.root;
|
|
1224
|
-
}
|
|
1225
|
-
return ret;
|
|
1226
|
-
},
|
|
1227
|
-
sep: '\\',
|
|
1228
|
-
delimiter: ';',
|
|
1229
|
-
win32: null,
|
|
1230
|
-
posix: null,
|
|
1231
|
-
};
|
|
1232
|
-
exports.posix = {
|
|
1233
|
-
// path.resolve([from ...], to)
|
|
1234
|
-
resolve(...pathSegments) {
|
|
1235
|
-
let resolvedPath = '';
|
|
1236
|
-
let resolvedAbsolute = false;
|
|
1237
|
-
for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
1238
|
-
let path;
|
|
1239
|
-
if (i >= 0) {
|
|
1240
|
-
path = pathSegments[i];
|
|
1241
|
-
}
|
|
1242
|
-
else {
|
|
1243
|
-
path = process.cwd();
|
|
1244
|
-
}
|
|
1245
|
-
validateString(path, 'path');
|
|
1246
|
-
// Skip empty entries
|
|
1247
|
-
if (path.length === 0) {
|
|
1248
|
-
continue;
|
|
1249
|
-
}
|
|
1250
|
-
resolvedPath = path + '/' + resolvedPath;
|
|
1251
|
-
resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
1252
|
-
}
|
|
1253
|
-
// At this point the path should be resolved to a full absolute path, but
|
|
1254
|
-
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
1255
|
-
// Normalize the path
|
|
1256
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
|
|
1257
|
-
if (resolvedAbsolute) {
|
|
1258
|
-
if (resolvedPath.length > 0) {
|
|
1259
|
-
return '/' + resolvedPath;
|
|
1260
|
-
}
|
|
1261
|
-
else {
|
|
1262
|
-
return '/';
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
else if (resolvedPath.length > 0) {
|
|
1266
|
-
return resolvedPath;
|
|
1267
|
-
}
|
|
1268
|
-
else {
|
|
1269
|
-
return '.';
|
|
1270
|
-
}
|
|
1271
|
-
},
|
|
1272
|
-
normalize(path) {
|
|
1273
|
-
validateString(path, 'path');
|
|
1274
|
-
if (path.length === 0) {
|
|
1275
|
-
return '.';
|
|
1276
|
-
}
|
|
1277
|
-
const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
1278
|
-
const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
|
|
1279
|
-
// Normalize the path
|
|
1280
|
-
path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
|
|
1281
|
-
if (path.length === 0 && !isAbsolute) {
|
|
1282
|
-
path = '.';
|
|
1283
|
-
}
|
|
1284
|
-
if (path.length > 0 && trailingSeparator) {
|
|
1285
|
-
path += '/';
|
|
1286
|
-
}
|
|
1287
|
-
if (isAbsolute) {
|
|
1288
|
-
return '/' + path;
|
|
1289
|
-
}
|
|
1290
|
-
return path;
|
|
1291
|
-
},
|
|
1292
|
-
isAbsolute(path) {
|
|
1293
|
-
validateString(path, 'path');
|
|
1294
|
-
return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
1295
|
-
},
|
|
1296
|
-
join(...paths) {
|
|
1297
|
-
if (paths.length === 0) {
|
|
1298
|
-
return '.';
|
|
1299
|
-
}
|
|
1300
|
-
let joined;
|
|
1301
|
-
for (let i = 0; i < paths.length; ++i) {
|
|
1302
|
-
const arg = arguments[i];
|
|
1303
|
-
validateString(arg, 'path');
|
|
1304
|
-
if (arg.length > 0) {
|
|
1305
|
-
if (joined === undefined) {
|
|
1306
|
-
joined = arg;
|
|
1307
|
-
}
|
|
1308
|
-
else {
|
|
1309
|
-
joined += '/' + arg;
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
if (joined === undefined) {
|
|
1314
|
-
return '.';
|
|
1315
|
-
}
|
|
1316
|
-
return exports.posix.normalize(joined);
|
|
1317
|
-
},
|
|
1318
|
-
relative(from, to) {
|
|
1319
|
-
validateString(from, 'from');
|
|
1320
|
-
validateString(to, 'to');
|
|
1321
|
-
if (from === to) {
|
|
1322
|
-
return '';
|
|
1323
|
-
}
|
|
1324
|
-
from = exports.posix.resolve(from);
|
|
1325
|
-
to = exports.posix.resolve(to);
|
|
1326
|
-
if (from === to) {
|
|
1327
|
-
return '';
|
|
1328
|
-
}
|
|
1329
|
-
// Trim any leading backslashes
|
|
1330
|
-
let fromStart = 1;
|
|
1331
|
-
for (; fromStart < from.length; ++fromStart) {
|
|
1332
|
-
if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) {
|
|
1333
|
-
break;
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
const fromEnd = from.length;
|
|
1337
|
-
const fromLen = fromEnd - fromStart;
|
|
1338
|
-
// Trim any leading backslashes
|
|
1339
|
-
let toStart = 1;
|
|
1340
|
-
for (; toStart < to.length; ++toStart) {
|
|
1341
|
-
if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) {
|
|
1342
|
-
break;
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
const toEnd = to.length;
|
|
1346
|
-
const toLen = toEnd - toStart;
|
|
1347
|
-
// Compare paths to find the longest common path from root
|
|
1348
|
-
const length = fromLen < toLen ? fromLen : toLen;
|
|
1349
|
-
let lastCommonSep = -1;
|
|
1350
|
-
let i = 0;
|
|
1351
|
-
for (; i <= length; ++i) {
|
|
1352
|
-
if (i === length) {
|
|
1353
|
-
if (toLen > length) {
|
|
1354
|
-
if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
|
|
1355
|
-
// We get here if `from` is the exact base path for `to`.
|
|
1356
|
-
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
|
1357
|
-
return to.slice(toStart + i + 1);
|
|
1358
|
-
}
|
|
1359
|
-
else if (i === 0) {
|
|
1360
|
-
// We get here if `from` is the root
|
|
1361
|
-
// For example: from='/'; to='/foo'
|
|
1362
|
-
return to.slice(toStart + i);
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
else if (fromLen > length) {
|
|
1366
|
-
if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
|
|
1367
|
-
// We get here if `to` is the exact base path for `from`.
|
|
1368
|
-
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
|
1369
|
-
lastCommonSep = i;
|
|
1370
|
-
}
|
|
1371
|
-
else if (i === 0) {
|
|
1372
|
-
// We get here if `to` is the root.
|
|
1373
|
-
// For example: from='/foo'; to='/'
|
|
1374
|
-
lastCommonSep = 0;
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
break;
|
|
1378
|
-
}
|
|
1379
|
-
const fromCode = from.charCodeAt(fromStart + i);
|
|
1380
|
-
const toCode = to.charCodeAt(toStart + i);
|
|
1381
|
-
if (fromCode !== toCode) {
|
|
1382
|
-
break;
|
|
1383
|
-
}
|
|
1384
|
-
else if (fromCode === CHAR_FORWARD_SLASH) {
|
|
1385
|
-
lastCommonSep = i;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
let out = '';
|
|
1389
|
-
// Generate the relative path based on the path difference between `to`
|
|
1390
|
-
// and `from`
|
|
1391
|
-
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
1392
|
-
if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
1393
|
-
if (out.length === 0) {
|
|
1394
|
-
out += '..';
|
|
1395
|
-
}
|
|
1396
|
-
else {
|
|
1397
|
-
out += '/..';
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
1402
|
-
// the common path parts
|
|
1403
|
-
if (out.length > 0) {
|
|
1404
|
-
return out + to.slice(toStart + lastCommonSep);
|
|
1405
|
-
}
|
|
1406
|
-
else {
|
|
1407
|
-
toStart += lastCommonSep;
|
|
1408
|
-
if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) {
|
|
1409
|
-
++toStart;
|
|
1410
|
-
}
|
|
1411
|
-
return to.slice(toStart);
|
|
1412
|
-
}
|
|
1413
|
-
},
|
|
1414
|
-
toNamespacedPath(path) {
|
|
1415
|
-
// Non-op on posix systems
|
|
1416
|
-
return path;
|
|
1417
|
-
},
|
|
1418
|
-
dirname(path) {
|
|
1419
|
-
validateString(path, 'path');
|
|
1420
|
-
if (path.length === 0) {
|
|
1421
|
-
return '.';
|
|
1422
|
-
}
|
|
1423
|
-
const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
1424
|
-
let end = -1;
|
|
1425
|
-
let matchedSlash = true;
|
|
1426
|
-
for (let i = path.length - 1; i >= 1; --i) {
|
|
1427
|
-
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
1428
|
-
if (!matchedSlash) {
|
|
1429
|
-
end = i;
|
|
1430
|
-
break;
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
else {
|
|
1434
|
-
// We saw the first non-path separator
|
|
1435
|
-
matchedSlash = false;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
if (end === -1) {
|
|
1439
|
-
return hasRoot ? '/' : '.';
|
|
1440
|
-
}
|
|
1441
|
-
if (hasRoot && end === 1) {
|
|
1442
|
-
return '//';
|
|
1443
|
-
}
|
|
1444
|
-
return path.slice(0, end);
|
|
1445
|
-
},
|
|
1446
|
-
basename(path, ext) {
|
|
1447
|
-
if (ext !== undefined) {
|
|
1448
|
-
validateString(ext, 'ext');
|
|
1449
|
-
}
|
|
1450
|
-
validateString(path, 'path');
|
|
1451
|
-
let start = 0;
|
|
1452
|
-
let end = -1;
|
|
1453
|
-
let matchedSlash = true;
|
|
1454
|
-
let i;
|
|
1455
|
-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
1456
|
-
if (ext.length === path.length && ext === path) {
|
|
1457
|
-
return '';
|
|
1458
|
-
}
|
|
1459
|
-
let extIdx = ext.length - 1;
|
|
1460
|
-
let firstNonSlashEnd = -1;
|
|
1461
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
1462
|
-
const code = path.charCodeAt(i);
|
|
1463
|
-
if (code === CHAR_FORWARD_SLASH) {
|
|
1464
|
-
// If we reached a path separator that was not part of a set of path
|
|
1465
|
-
// separators at the end of the string, stop now
|
|
1466
|
-
if (!matchedSlash) {
|
|
1467
|
-
start = i + 1;
|
|
1468
|
-
break;
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
else {
|
|
1472
|
-
if (firstNonSlashEnd === -1) {
|
|
1473
|
-
// We saw the first non-path separator, remember this index in case
|
|
1474
|
-
// we need it if the extension ends up not matching
|
|
1475
|
-
matchedSlash = false;
|
|
1476
|
-
firstNonSlashEnd = i + 1;
|
|
1477
|
-
}
|
|
1478
|
-
if (extIdx >= 0) {
|
|
1479
|
-
// Try to match the explicit extension
|
|
1480
|
-
if (code === ext.charCodeAt(extIdx)) {
|
|
1481
|
-
if (--extIdx === -1) {
|
|
1482
|
-
// We matched the extension, so mark this as the end of our path
|
|
1483
|
-
// component
|
|
1484
|
-
end = i;
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
else {
|
|
1488
|
-
// Extension does not match, so our result is the entire path
|
|
1489
|
-
// component
|
|
1490
|
-
extIdx = -1;
|
|
1491
|
-
end = firstNonSlashEnd;
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
if (start === end) {
|
|
1497
|
-
end = firstNonSlashEnd;
|
|
1498
|
-
}
|
|
1499
|
-
else if (end === -1) {
|
|
1500
|
-
end = path.length;
|
|
1501
|
-
}
|
|
1502
|
-
return path.slice(start, end);
|
|
1503
|
-
}
|
|
1504
|
-
else {
|
|
1505
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
1506
|
-
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
1507
|
-
// If we reached a path separator that was not part of a set of path
|
|
1508
|
-
// separators at the end of the string, stop now
|
|
1509
|
-
if (!matchedSlash) {
|
|
1510
|
-
start = i + 1;
|
|
1511
|
-
break;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
else if (end === -1) {
|
|
1515
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
1516
|
-
// path component
|
|
1517
|
-
matchedSlash = false;
|
|
1518
|
-
end = i + 1;
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
if (end === -1) {
|
|
1522
|
-
return '';
|
|
1523
|
-
}
|
|
1524
|
-
return path.slice(start, end);
|
|
1525
|
-
}
|
|
1526
|
-
},
|
|
1527
|
-
extname(path) {
|
|
1528
|
-
validateString(path, 'path');
|
|
1529
|
-
let startDot = -1;
|
|
1530
|
-
let startPart = 0;
|
|
1531
|
-
let end = -1;
|
|
1532
|
-
let matchedSlash = true;
|
|
1533
|
-
// Track the state of characters (if any) we see before our first dot and
|
|
1534
|
-
// after any path separator we find
|
|
1535
|
-
let preDotState = 0;
|
|
1536
|
-
for (let i = path.length - 1; i >= 0; --i) {
|
|
1537
|
-
const code = path.charCodeAt(i);
|
|
1538
|
-
if (code === CHAR_FORWARD_SLASH) {
|
|
1539
|
-
// If we reached a path separator that was not part of a set of path
|
|
1540
|
-
// separators at the end of the string, stop now
|
|
1541
|
-
if (!matchedSlash) {
|
|
1542
|
-
startPart = i + 1;
|
|
1543
|
-
break;
|
|
1544
|
-
}
|
|
1545
|
-
continue;
|
|
1546
|
-
}
|
|
1547
|
-
if (end === -1) {
|
|
1548
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
1549
|
-
// extension
|
|
1550
|
-
matchedSlash = false;
|
|
1551
|
-
end = i + 1;
|
|
1552
|
-
}
|
|
1553
|
-
if (code === CHAR_DOT) {
|
|
1554
|
-
// If this is our first dot, mark it as the start of our extension
|
|
1555
|
-
if (startDot === -1) {
|
|
1556
|
-
startDot = i;
|
|
1557
|
-
}
|
|
1558
|
-
else if (preDotState !== 1) {
|
|
1559
|
-
preDotState = 1;
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
else if (startDot !== -1) {
|
|
1563
|
-
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1564
|
-
// have a good chance at having a non-empty extension
|
|
1565
|
-
preDotState = -1;
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
if (startDot === -1 ||
|
|
1569
|
-
end === -1 ||
|
|
1570
|
-
// We saw a non-dot character immediately before the dot
|
|
1571
|
-
preDotState === 0 ||
|
|
1572
|
-
// The (right-most) trimmed path component is exactly '..'
|
|
1573
|
-
(preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
|
|
1574
|
-
return '';
|
|
1575
|
-
}
|
|
1576
|
-
return path.slice(startDot, end);
|
|
1577
|
-
},
|
|
1578
|
-
format(pathObject) {
|
|
1579
|
-
if (pathObject === null || typeof pathObject !== 'object') {
|
|
1580
|
-
throw new ErrorInvalidArgType('pathObject', 'Object', pathObject);
|
|
1581
|
-
}
|
|
1582
|
-
return _format('/', pathObject);
|
|
1583
|
-
},
|
|
1584
|
-
parse(path) {
|
|
1585
|
-
validateString(path, 'path');
|
|
1586
|
-
const ret = { root: '', dir: '', base: '', ext: '', name: '' };
|
|
1587
|
-
if (path.length === 0) {
|
|
1588
|
-
return ret;
|
|
1589
|
-
}
|
|
1590
|
-
const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
1591
|
-
let start;
|
|
1592
|
-
if (isAbsolute) {
|
|
1593
|
-
ret.root = '/';
|
|
1594
|
-
start = 1;
|
|
1595
|
-
}
|
|
1596
|
-
else {
|
|
1597
|
-
start = 0;
|
|
1598
|
-
}
|
|
1599
|
-
let startDot = -1;
|
|
1600
|
-
let startPart = 0;
|
|
1601
|
-
let end = -1;
|
|
1602
|
-
let matchedSlash = true;
|
|
1603
|
-
let i = path.length - 1;
|
|
1604
|
-
// Track the state of characters (if any) we see before our first dot and
|
|
1605
|
-
// after any path separator we find
|
|
1606
|
-
let preDotState = 0;
|
|
1607
|
-
// Get non-dir info
|
|
1608
|
-
for (; i >= start; --i) {
|
|
1609
|
-
const code = path.charCodeAt(i);
|
|
1610
|
-
if (code === CHAR_FORWARD_SLASH) {
|
|
1611
|
-
// If we reached a path separator that was not part of a set of path
|
|
1612
|
-
// separators at the end of the string, stop now
|
|
1613
|
-
if (!matchedSlash) {
|
|
1614
|
-
startPart = i + 1;
|
|
1615
|
-
break;
|
|
1616
|
-
}
|
|
1617
|
-
continue;
|
|
1618
|
-
}
|
|
1619
|
-
if (end === -1) {
|
|
1620
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
1621
|
-
// extension
|
|
1622
|
-
matchedSlash = false;
|
|
1623
|
-
end = i + 1;
|
|
1624
|
-
}
|
|
1625
|
-
if (code === CHAR_DOT) {
|
|
1626
|
-
// If this is our first dot, mark it as the start of our extension
|
|
1627
|
-
if (startDot === -1) {
|
|
1628
|
-
startDot = i;
|
|
1629
|
-
}
|
|
1630
|
-
else if (preDotState !== 1) {
|
|
1631
|
-
preDotState = 1;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
else if (startDot !== -1) {
|
|
1635
|
-
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1636
|
-
// have a good chance at having a non-empty extension
|
|
1637
|
-
preDotState = -1;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
if (startDot === -1 ||
|
|
1641
|
-
end === -1 ||
|
|
1642
|
-
// We saw a non-dot character immediately before the dot
|
|
1643
|
-
preDotState === 0 ||
|
|
1644
|
-
// The (right-most) trimmed path component is exactly '..'
|
|
1645
|
-
(preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
|
|
1646
|
-
if (end !== -1) {
|
|
1647
|
-
if (startPart === 0 && isAbsolute) {
|
|
1648
|
-
ret.base = ret.name = path.slice(1, end);
|
|
1649
|
-
}
|
|
1650
|
-
else {
|
|
1651
|
-
ret.base = ret.name = path.slice(startPart, end);
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
else {
|
|
1656
|
-
if (startPart === 0 && isAbsolute) {
|
|
1657
|
-
ret.name = path.slice(1, startDot);
|
|
1658
|
-
ret.base = path.slice(1, end);
|
|
1659
|
-
}
|
|
1660
|
-
else {
|
|
1661
|
-
ret.name = path.slice(startPart, startDot);
|
|
1662
|
-
ret.base = path.slice(startPart, end);
|
|
1663
|
-
}
|
|
1664
|
-
ret.ext = path.slice(startDot, end);
|
|
1665
|
-
}
|
|
1666
|
-
if (startPart > 0) {
|
|
1667
|
-
ret.dir = path.slice(0, startPart - 1);
|
|
1668
|
-
}
|
|
1669
|
-
else if (isAbsolute) {
|
|
1670
|
-
ret.dir = '/';
|
|
1671
|
-
}
|
|
1672
|
-
return ret;
|
|
1673
|
-
},
|
|
1674
|
-
sep: '/',
|
|
1675
|
-
delimiter: ':',
|
|
1676
|
-
win32: null,
|
|
1677
|
-
posix: null,
|
|
1678
|
-
};
|
|
1679
|
-
exports.posix.win32 = exports.win32.win32 = exports.win32;
|
|
1680
|
-
exports.posix.posix = exports.win32.posix = exports.posix;
|
|
1681
|
-
exports.normalize = process.platform === 'win32' ? exports.win32.normalize : exports.posix.normalize;
|
|
1682
|
-
exports.isAbsolute = process.platform === 'win32' ? exports.win32.isAbsolute : exports.posix.isAbsolute;
|
|
1683
|
-
exports.join = process.platform === 'win32' ? exports.win32.join : exports.posix.join;
|
|
1684
|
-
exports.resolve = process.platform === 'win32' ? exports.win32.resolve : exports.posix.resolve;
|
|
1685
|
-
exports.relative = process.platform === 'win32' ? exports.win32.relative : exports.posix.relative;
|
|
1686
|
-
exports.dirname = process.platform === 'win32' ? exports.win32.dirname : exports.posix.dirname;
|
|
1687
|
-
exports.basename = process.platform === 'win32' ? exports.win32.basename : exports.posix.basename;
|
|
1688
|
-
exports.extname = process.platform === 'win32' ? exports.win32.extname : exports.posix.extname;
|
|
1689
|
-
exports.format = process.platform === 'win32' ? exports.win32.format : exports.posix.format;
|
|
1690
|
-
exports.parse = process.platform === 'win32' ? exports.win32.parse : exports.posix.parse;
|
|
1691
|
-
exports.toNamespacedPath = process.platform === 'win32' ? exports.win32.toNamespacedPath : exports.posix.toNamespacedPath;
|
|
1692
|
-
exports.sep = process.platform === 'win32' ? exports.win32.sep : exports.posix.sep;
|
|
1693
|
-
exports.delimiter = process.platform === 'win32' ? exports.win32.delimiter : exports.posix.delimiter;
|
|
1694
|
-
//# sourceMappingURL=path.js.map
|