Cars project 3 do dokończenia

This commit is contained in:
aplikacje committed 2026-11-05 10:50:57 +01:00
1 parent 3b96ac1be8
commit b3be59a011
159 files changed
+9794 -3786

No files matched your search

+42 -14
View File
@@ -29,14 +29,29 @@ const fsFromOption = (fsOption) => !fsOption || fsOption === defaultFS || fsOpti
...fsOption,
promises: {
...defaultFS.promises,
...(fsOption.promises || {}),
...(fsOption.promises),
},
};
// turn something like //?/c:/ into c:\
// turn something like //?/c:/ into c:\, and //?/UNC/host/share/ or
// //host/share into \\host\share\
const uncDriveRegexp = /^\\\\\?\\([a-z]:)\\?$/i;
const uncToDrive = (rootPath) => rootPath.replace(/\//g, '\\').replace(uncDriveRegexp, '$1\\');
const uncLongRegexp = /^\\\\\?\\UNC\\([^\\]+\\[^\\]+)\\?$/i;
const uncShareRegexp = /^\\\\[^\\?]+\\[^\\]+$/;
const uncToDrive = (rootPath) => rootPath
.replace(/\//g, '\\')
.replace(uncDriveRegexp, '$1\\')
.replace(uncLongRegexp, '\\\\$1\\')
.replace(uncShareRegexp, '$&\\');
// path.win32.parse() only finds the //?/UNC/ of a long UNC root
const longUncRoot = /^[\\/]{2}\?[\\/]unc[\\/][^\\/]+[\\/][^\\/]+(?:[\\/]|$)/i;
// //?/c:/x is the same path as c:/x
const longDrivePrefix = /^[\\/]{2}\?[\\/](?=[a-z]:)/i;
// //?/UNC/host/share/x is the same path as //host/share/x. This
// matches up to the / after UNC, which with a \ in front of it is
// the // in front of the host.
const longUncPrefix = /^[\\/]{2}\?[\\/]unc(?=[\\/][^\\/]+[\\/][^\\/])/i;
// windows paths are separated by either / or \
const eitherSep = /[\\\/]/;
const eitherSep = /[\\/]/;
const UNKNOWN = 0; // may not even exist, for all we know
const IFIFO = 0b0001;
const IFCHR = 0b0010;
@@ -307,6 +322,15 @@ export class PathBase {
this.#fs = fsFromOption(opts.fs);
}
}
/**
* The file system methods that this Path uses, for a new root on
* another drive or UNC share.
*
* @internal
*/
get fs() {
return this.#fs;
}
/**
* Returns the depth of the Path object from its root.
*
@@ -1095,7 +1119,7 @@ export class PathBase {
const rp = await this.#fs.promises.realpath(this.fullpath());
return (this.#realpath = this.resolve(rp));
}
catch (_) {
catch {
this.#markENOREALPATH();
}
}
@@ -1111,7 +1135,7 @@ export class PathBase {
const rp = this.#fs.realpathSync(this.fullpath());
return (this.#realpath = this.resolve(rp));
}
catch (_) {
catch {
this.#markENOREALPATH();
}
}
@@ -1179,14 +1203,15 @@ export class PathWin32 extends PathBase {
* @internal
*/
getRootString(path) {
return win32.parse(path).root;
return longUncRoot.exec(path)?.[0] ?? win32.parse(path).root;
}
/**
* @internal
*/
getRoot(rootPath) {
rootPath = uncToDrive(rootPath.toUpperCase());
if (rootPath === this.root.name) {
// a root with no drive or UNC host is the root of this path
if (rootPath === this.root.name || /^[\\/]$/.test(rootPath)) {
return this.root;
}
// ok, not that one, check if it matches another we know about
@@ -1196,7 +1221,10 @@ export class PathWin32 extends PathBase {
}
}
// otherwise, have to create a new one.
return (this.roots[rootPath] = new PathScurryWin32(rootPath, this).root);
return (this.roots[rootPath] = new PathScurryWin32(rootPath, {
nocase: this.nocase,
fs: this.fs,
}).root);
}
/**
* @internal
@@ -1205,11 +1233,7 @@ export class PathWin32 extends PathBase {
// windows can (rarely) have case-sensitive filesystem, but
// UNC and drive letters are always case-insensitive, and canonically
// represented uppercase.
rootPath = rootPath
.toUpperCase()
.replace(/\//g, '\\')
.replace(uncDriveRegexp, '$1\\');
return rootPath === compare;
return uncToDrive(rootPath.toUpperCase()) === compare;
}
}
/**
@@ -1887,6 +1911,10 @@ export class PathScurryWin32 extends PathScurryBase {
sep = '\\';
constructor(cwd = process.cwd(), opts = {}) {
const { nocase = true } = opts;
// use the same root as resolve() does for these paths
if (typeof cwd === 'string' && !cwd.startsWith('file://')) {
cwd = cwd.replace(longDrivePrefix, '').replace(longUncPrefix, '\\');
}
super(cwd, win32, '\\', { ...opts, nocase });
this.nocase = nocase;
for (let p = this.cwd; p; p = p.parent) {