254
isAbsolute = true;
255
}
256
>
} else if (isPathSeparator(code)) {
path.ts
257
>
// Possible UNC root
258
>
259
>
// If we started with a separator, we know we at least have an
260
>
// absolute path of some kind (UNC or otherwise)
261
>
isAbsolute = true;
262
>
263
>
if (isPathSeparator(path.charCodeAt(1))) {
264
>
// Matched double path separator at beginning
265
>
let j = 2;
266
>
let last = j;
267
>
// Match 1 or more non-path separators
268
>
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
269
>
j++;
270
>
}
271
>
if (j < len && j !== last) {
272
>
const firstPart = path.slice(last, j);
273
>
// Matched!
274
>
last = j;
275
>
// Match 1 or more path separators
276
>
while (j < len && isPathSeparator(path.charCodeAt(j))) {
277
>
j++;
278
>
}
279
>
if (j < len && j !== last) {
280
>
// Matched!
281
>
last = j;
282
>
// Match 1 or more non-path separators
283
>
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
284
>
j++;
285
>
}
286
>
if (j === len || j !== last) {
287
>
// We matched a UNC root
288
>
device = `\\\\${firstPart}\\${path.slice(last, j)}`;
289
>
rootEnd = j;
290
>
}
291
>
}
292
>
}
293
>
} else {
294
rootEnd = 1;
295
}
296
>
} else if (isWindowsDeviceRoot(code) &&
path.ts
297
>
path.charCodeAt(1) === CHAR_COLON) {
298
>
// Possible device root
299
>
device = path.slice(0, 2);
300
>
rootEnd = 2;
301
>
if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
302
>
// Treat separator following drive name as an absolute path
303
>
// indicator
304
>
isAbsolute = true;
305
>
rootEnd = 3;
306
>
}
307
>
}
308
>
309
>
if (device.length > 0) {
310
>
if (resolvedDevice.length > 0) {
311
if (device.toLowerCase() !== resolvedDevice.toLowerCase()) {
312
// This path points to another device so it is not applicable
313
continue;
314
}
316
>
resolvedDevice = device;
317
>
}
318
>
}
319
>
320
>
if (resolvedAbsolute) {
321
if (resolvedDevice.length > 0) {
322
break;
323
}
325
>
resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
326
>
resolvedAbsolute = isAbsolute;
327
>
if (isAbsolute && resolvedDevice.length > 0) {
328
>
break;
329
>
}
330
>
}
331
>
}
332
>
333
>
// At this point the path should be resolved to a full absolute path,
334
>
// but handle relative paths to be safe (might happen when process.cwd()
335
>
// fails)
336
>
337
>
// Normalize the tail path
338
>
resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\',
339
>
isPathSeparator);
340
>
341
>
return resolvedAbsolute ?
342
>
`${resolvedDevice}\\${resolvedTail}` :
343
`${resolvedDevice}${resolvedTail}` || '.';
345
346
normalize(path: string): string {