@veryfront/ext-content-mdx 0.1.1183 → 0.1.1185
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/esm/deno.d.ts +4 -1
- package/esm/deno.js +11 -6
- package/esm/src/extensions/websocket/index.d.ts +3 -0
- package/esm/src/extensions/websocket/index.d.ts.map +1 -0
- package/esm/src/extensions/websocket/index.js +2 -0
- package/esm/src/extensions/websocket/node-websocket-server-provider.d.ts +51 -0
- package/esm/src/extensions/websocket/node-websocket-server-provider.d.ts.map +1 -0
- package/esm/src/extensions/websocket/node-websocket-server-provider.js +146 -0
- package/esm/src/platform/adapters/base.d.ts +17 -0
- package/esm/src/platform/adapters/base.d.ts.map +1 -1
- package/esm/src/platform/adapters/base.js +54 -5
- package/esm/src/platform/compat/path/basic-operations.d.ts +1 -1
- package/esm/src/platform/compat/path/basic-operations.d.ts.map +1 -1
- package/esm/src/platform/compat/path/basic-operations.js +24 -44
- package/esm/src/platform/compat/path/index.d.ts +1 -0
- package/esm/src/platform/compat/path/index.d.ts.map +1 -1
- package/esm/src/platform/compat/path/index.js +1 -0
- package/esm/src/platform/compat/path/parse-format.d.ts.map +1 -1
- package/esm/src/platform/compat/path/parse-format.js +26 -20
- package/esm/src/platform/compat/path/portable.d.ts +16 -0
- package/esm/src/platform/compat/path/portable.d.ts.map +1 -0
- package/esm/src/platform/compat/path/portable.js +307 -0
- package/esm/src/platform/compat/path/posix.d.ts +14 -0
- package/esm/src/platform/compat/path/posix.d.ts.map +1 -0
- package/esm/src/platform/compat/path/posix.js +206 -0
- package/esm/src/platform/compat/path/resolution.d.ts +1 -1
- package/esm/src/platform/compat/path/resolution.d.ts.map +1 -1
- package/esm/src/platform/compat/path/resolution.js +28 -112
- package/esm/src/platform/compat/path/runtime.d.ts +2 -1
- package/esm/src/platform/compat/path/runtime.d.ts.map +1 -1
- package/esm/src/platform/compat/path/runtime.js +5 -0
- package/esm/src/platform/compat/path/types.d.ts +5 -1
- package/esm/src/platform/compat/path/types.d.ts.map +1 -1
- package/esm/src/platform/compat/path/url-conversion.d.ts +10 -0
- package/esm/src/platform/compat/path/url-conversion.d.ts.map +1 -1
- package/esm/src/platform/compat/path/url-conversion.js +63 -41
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +2 -2
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isAbsolute } from "./resolution.js";
|
|
1
|
+
import { hasWindowsLikePath, portableFormat, portableParse, runtimeUsesWindowsPaths, toPortableSeparators, } from "./portable.js";
|
|
2
|
+
import { getNativePathImplementation } from "./runtime.js";
|
|
4
3
|
export function parse(path) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const ext = extname(path);
|
|
4
|
+
const windows = runtimeUsesWindowsPaths() || hasWindowsLikePath(path);
|
|
5
|
+
const pathApi = getNativePathImplementation(windows);
|
|
6
|
+
if (!pathApi)
|
|
7
|
+
return portableParse(path, windows);
|
|
8
|
+
const parsed = pathApi.parse(path);
|
|
11
9
|
return {
|
|
12
|
-
root:
|
|
13
|
-
dir,
|
|
14
|
-
base,
|
|
15
|
-
ext,
|
|
16
|
-
name:
|
|
10
|
+
root: toPortableSeparators(parsed.root ?? ""),
|
|
11
|
+
dir: toPortableSeparators(parsed.dir ?? ""),
|
|
12
|
+
base: parsed.base ?? "",
|
|
13
|
+
ext: parsed.ext ?? "",
|
|
14
|
+
name: parsed.name ?? "",
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
17
|
export function format(pathObject) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const windows = runtimeUsesWindowsPaths() ||
|
|
19
|
+
hasWindowsLikePath(pathObject.root ?? "") ||
|
|
20
|
+
hasWindowsLikePath(pathObject.dir ?? "");
|
|
21
|
+
const pathApi = getNativePathImplementation(windows);
|
|
22
|
+
if (!pathApi)
|
|
23
|
+
return portableFormat(pathObject, windows);
|
|
24
|
+
const formatted = pathApi.format({
|
|
25
|
+
root: pathObject.root ?? "",
|
|
26
|
+
dir: pathObject.dir ?? "",
|
|
27
|
+
base: pathObject.base ?? "",
|
|
28
|
+
ext: pathObject.ext ?? "",
|
|
29
|
+
name: pathObject.name ?? "",
|
|
30
|
+
});
|
|
31
|
+
return toPortableSeparators(formatted);
|
|
26
32
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PathObject } from "./types.js";
|
|
2
|
+
export declare function hasWindowsLikePath(path: string): boolean;
|
|
3
|
+
export declare function toPortableSeparators(path: string): string;
|
|
4
|
+
export declare function removeTrailingSeparatorsExceptRoot(path: string, windows: boolean): string;
|
|
5
|
+
export declare function runtimeUsesWindowsPaths(): boolean;
|
|
6
|
+
export declare function portableNormalize(path: string, windows: boolean): string;
|
|
7
|
+
export declare function portableJoin(paths: readonly string[], windows: boolean): string;
|
|
8
|
+
export declare function portableDirname(path: string, windows: boolean): string;
|
|
9
|
+
export declare function portableBasename(path: string, ext: string | undefined, windows: boolean): string;
|
|
10
|
+
export declare function portableExtname(path: string, windows: boolean): string;
|
|
11
|
+
export declare function portableIsAbsolute(path: string, windows: boolean): boolean;
|
|
12
|
+
export declare function portableResolve(paths: readonly string[], windows: boolean): string;
|
|
13
|
+
export declare function portableRelative(from: string, to: string, windows: boolean): string;
|
|
14
|
+
export declare function portableParse(path: string, windows: boolean): PathObject;
|
|
15
|
+
export declare function portableFormat(pathObject: PathObject, windows: boolean): string;
|
|
16
|
+
//# sourceMappingURL=portable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/portable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAS7C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAmFD,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACf,MAAM,CAUR;AAOD,wBAAgB,uBAAuB,IAAI,OAAO,CASjD;AAyBD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAkBxE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAI/E;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAqBtE;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,OAAO,EAAE,OAAO,GACf,MAAM,CAuCR;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAKtE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAE1E;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE,OAAO,GACf,MAAM,CAiCR;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,OAAO,GACf,MAAM,CA2BR;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,UAAU,CAiCxE;AAED,wBAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO,GACf,MAAM,CAeR"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
export function hasWindowsLikePath(path) {
|
|
3
|
+
return path.includes("\\") ||
|
|
4
|
+
/^[A-Za-z]:/.test(path);
|
|
5
|
+
}
|
|
6
|
+
export function toPortableSeparators(path) {
|
|
7
|
+
return path.replaceAll("\\", "/");
|
|
8
|
+
}
|
|
9
|
+
function analyzeRoot(path, windows) {
|
|
10
|
+
const portable = toPortableSeparators(path);
|
|
11
|
+
if (windows) {
|
|
12
|
+
const unc = portable.match(/^\/\/([^/]+)\/+([^/]+)(\/+(.*))?$/);
|
|
13
|
+
if (unc?.[1] && unc[2]) {
|
|
14
|
+
const device = `//${unc[1]}/${unc[2]}`;
|
|
15
|
+
return {
|
|
16
|
+
absolute: true,
|
|
17
|
+
device,
|
|
18
|
+
rest: unc[4] ?? "",
|
|
19
|
+
root: unc[3] === undefined ? device : `${device}/`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const drive = portable.match(/^([A-Za-z]:)(\/+)?(.*)$/);
|
|
23
|
+
if (drive?.[1] !== undefined) {
|
|
24
|
+
const absolute = drive[2] !== undefined;
|
|
25
|
+
return {
|
|
26
|
+
absolute,
|
|
27
|
+
device: drive[1],
|
|
28
|
+
rest: drive[3] ?? "",
|
|
29
|
+
root: absolute ? `${drive[1]}/` : drive[1],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (portable.startsWith("/")) {
|
|
34
|
+
return {
|
|
35
|
+
absolute: true,
|
|
36
|
+
device: "",
|
|
37
|
+
rest: portable.replace(/^\/+/, ""),
|
|
38
|
+
root: "/",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
absolute: false,
|
|
43
|
+
device: "",
|
|
44
|
+
rest: portable,
|
|
45
|
+
root: "",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function appendRoot(root, tail) {
|
|
49
|
+
if (root.root === "")
|
|
50
|
+
return tail || ".";
|
|
51
|
+
if (!root.absolute)
|
|
52
|
+
return `${root.root}${tail || "."}`;
|
|
53
|
+
if (!tail) {
|
|
54
|
+
return root.device.startsWith("//") ? `${root.device}/` : root.root;
|
|
55
|
+
}
|
|
56
|
+
return root.root.endsWith("/") ? `${root.root}${tail}` : `${root.root}/${tail}`;
|
|
57
|
+
}
|
|
58
|
+
function normalizeTail(rest, absolute) {
|
|
59
|
+
const normalized = [];
|
|
60
|
+
for (const segment of rest.split("/")) {
|
|
61
|
+
if (segment === "" || segment === ".")
|
|
62
|
+
continue;
|
|
63
|
+
if (segment !== "..") {
|
|
64
|
+
normalized.push(segment);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const previous = normalized.at(-1);
|
|
68
|
+
if (previous !== undefined && previous !== "..") {
|
|
69
|
+
normalized.pop();
|
|
70
|
+
}
|
|
71
|
+
else if (!absolute) {
|
|
72
|
+
normalized.push("..");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return normalized;
|
|
76
|
+
}
|
|
77
|
+
function canonicalPath(path, windows) {
|
|
78
|
+
return windows ? toPortableSeparators(path) : path;
|
|
79
|
+
}
|
|
80
|
+
export function removeTrailingSeparatorsExceptRoot(path, windows) {
|
|
81
|
+
const root = analyzeRoot(path, windows);
|
|
82
|
+
let canonical = canonicalPath(path, windows);
|
|
83
|
+
while (canonical.endsWith("/") &&
|
|
84
|
+
canonical.length > root.root.length) {
|
|
85
|
+
canonical = canonical.slice(0, -1);
|
|
86
|
+
}
|
|
87
|
+
return canonical;
|
|
88
|
+
}
|
|
89
|
+
function rootKey(root, windows) {
|
|
90
|
+
const value = root.device || root.root;
|
|
91
|
+
return windows ? value.toLowerCase() : value;
|
|
92
|
+
}
|
|
93
|
+
export function runtimeUsesWindowsPaths() {
|
|
94
|
+
const runtime = dntShim.dntGlobalThis;
|
|
95
|
+
if (typeof runtime.Deno?.build?.os === "string") {
|
|
96
|
+
return runtime.Deno.build.os === "windows";
|
|
97
|
+
}
|
|
98
|
+
return runtime.process?.platform === "win32";
|
|
99
|
+
}
|
|
100
|
+
function runtimeCwd() {
|
|
101
|
+
const deno = dntShim.dntGlobalThis.Deno;
|
|
102
|
+
try {
|
|
103
|
+
if (typeof deno?.cwd === "function")
|
|
104
|
+
return deno.cwd();
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Continue to the next runtime source.
|
|
108
|
+
}
|
|
109
|
+
const process = dntShim.dntGlobalThis.process;
|
|
110
|
+
try {
|
|
111
|
+
if (typeof process?.cwd === "function")
|
|
112
|
+
return process.cwd();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Browsers do not expose a process working directory.
|
|
116
|
+
}
|
|
117
|
+
// Browser builds use a virtual root because no host working directory exists.
|
|
118
|
+
return "/";
|
|
119
|
+
}
|
|
120
|
+
export function portableNormalize(path, windows) {
|
|
121
|
+
if (path === "")
|
|
122
|
+
return ".";
|
|
123
|
+
const root = analyzeRoot(path, windows);
|
|
124
|
+
const tail = normalizeTail(root.rest, root.absolute).join("/");
|
|
125
|
+
let result = appendRoot(root, tail);
|
|
126
|
+
const hadTrailingSeparator = /[\\/]$/.test(path);
|
|
127
|
+
if (hadTrailingSeparator && result === ".")
|
|
128
|
+
return "./";
|
|
129
|
+
if (hadTrailingSeparator &&
|
|
130
|
+
result !== root.root &&
|
|
131
|
+
!result.endsWith("/")) {
|
|
132
|
+
result += "/";
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
export function portableJoin(paths, windows) {
|
|
137
|
+
const nonempty = paths.filter((path) => path.length > 0);
|
|
138
|
+
if (nonempty.length === 0)
|
|
139
|
+
return "/";
|
|
140
|
+
return portableNormalize(nonempty.join("/"), windows);
|
|
141
|
+
}
|
|
142
|
+
export function portableDirname(path, windows) {
|
|
143
|
+
if (path.length === 0)
|
|
144
|
+
return ".";
|
|
145
|
+
const root = analyzeRoot(path, windows);
|
|
146
|
+
let canonical = canonicalPath(path, windows);
|
|
147
|
+
while (canonical.endsWith("/") &&
|
|
148
|
+
canonical.length > root.root.length) {
|
|
149
|
+
canonical = canonical.slice(0, -1);
|
|
150
|
+
}
|
|
151
|
+
if (canonical === root.root || canonical === root.device) {
|
|
152
|
+
return root.root || root.device || ".";
|
|
153
|
+
}
|
|
154
|
+
const lastSeparator = canonical.lastIndexOf("/");
|
|
155
|
+
if (lastSeparator === -1)
|
|
156
|
+
return root.device || ".";
|
|
157
|
+
if (lastSeparator < root.root.length)
|
|
158
|
+
return root.root || "/";
|
|
159
|
+
if (lastSeparator === 0)
|
|
160
|
+
return "/";
|
|
161
|
+
return canonical.slice(0, lastSeparator);
|
|
162
|
+
}
|
|
163
|
+
export function portableBasename(path, ext, windows) {
|
|
164
|
+
if (path.length === 0)
|
|
165
|
+
return "";
|
|
166
|
+
const root = analyzeRoot(path, windows);
|
|
167
|
+
let canonical = canonicalPath(path, windows);
|
|
168
|
+
const originalPath = canonical;
|
|
169
|
+
if (ext !== undefined && ext !== "" && ext === originalPath)
|
|
170
|
+
return "";
|
|
171
|
+
while (canonical.endsWith("/") &&
|
|
172
|
+
canonical.length > root.root.length) {
|
|
173
|
+
canonical = canonical.slice(0, -1);
|
|
174
|
+
}
|
|
175
|
+
if (windows &&
|
|
176
|
+
root.device.startsWith("//") &&
|
|
177
|
+
root.rest === "") {
|
|
178
|
+
return root.device.slice(root.device.lastIndexOf("/") + 1);
|
|
179
|
+
}
|
|
180
|
+
if (canonical === root.root || canonical === root.device)
|
|
181
|
+
return "";
|
|
182
|
+
const lastSeparator = canonical.lastIndexOf("/");
|
|
183
|
+
let base = canonical.slice(lastSeparator + 1);
|
|
184
|
+
if (!root.absolute &&
|
|
185
|
+
root.device &&
|
|
186
|
+
lastSeparator === -1 &&
|
|
187
|
+
base.startsWith(root.device)) {
|
|
188
|
+
base = base.slice(root.device.length);
|
|
189
|
+
}
|
|
190
|
+
if (ext !== undefined && ext !== "" && base.endsWith(ext)) {
|
|
191
|
+
if (ext.length < base.length)
|
|
192
|
+
return base.slice(0, -ext.length);
|
|
193
|
+
}
|
|
194
|
+
return base;
|
|
195
|
+
}
|
|
196
|
+
export function portableExtname(path, windows) {
|
|
197
|
+
const base = portableBasename(path, undefined, windows);
|
|
198
|
+
const lastDot = base.lastIndexOf(".");
|
|
199
|
+
if (lastDot <= 0 || base === "." || base === "..")
|
|
200
|
+
return "";
|
|
201
|
+
return base.slice(lastDot);
|
|
202
|
+
}
|
|
203
|
+
export function portableIsAbsolute(path, windows) {
|
|
204
|
+
return analyzeRoot(path, windows).absolute;
|
|
205
|
+
}
|
|
206
|
+
export function portableResolve(paths, windows) {
|
|
207
|
+
let resolved = runtimeCwd();
|
|
208
|
+
for (const rawPath of paths) {
|
|
209
|
+
if (rawPath.length === 0)
|
|
210
|
+
continue;
|
|
211
|
+
const path = toPortableSeparators(rawPath);
|
|
212
|
+
const incoming = analyzeRoot(path, windows);
|
|
213
|
+
const current = analyzeRoot(resolved, windows);
|
|
214
|
+
if (incoming.absolute && incoming.device) {
|
|
215
|
+
resolved = path;
|
|
216
|
+
}
|
|
217
|
+
else if (incoming.absolute) {
|
|
218
|
+
resolved = windows && current.device ? `${current.device}/${incoming.rest}` : path;
|
|
219
|
+
}
|
|
220
|
+
else if (incoming.device) {
|
|
221
|
+
resolved = rootKey(incoming, true) === rootKey(current, true)
|
|
222
|
+
? `${current.root}${current.rest}/${incoming.rest}`
|
|
223
|
+
: `${incoming.device}/${incoming.rest}`;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
resolved = `${resolved}/${path}`;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const normalized = portableNormalize(resolved, windows);
|
|
230
|
+
const root = analyzeRoot(normalized, windows);
|
|
231
|
+
if (normalized.endsWith("/") &&
|
|
232
|
+
normalized !== root.root &&
|
|
233
|
+
normalized !== `${root.device}/`) {
|
|
234
|
+
return normalized.slice(0, -1);
|
|
235
|
+
}
|
|
236
|
+
return normalized;
|
|
237
|
+
}
|
|
238
|
+
export function portableRelative(from, to, windows) {
|
|
239
|
+
const resolvedFrom = portableResolve([from], windows);
|
|
240
|
+
const resolvedTo = portableResolve([to], windows);
|
|
241
|
+
const fromRoot = analyzeRoot(resolvedFrom, windows);
|
|
242
|
+
const toRoot = analyzeRoot(resolvedTo, windows);
|
|
243
|
+
if (rootKey(fromRoot, windows) !== rootKey(toRoot, windows)) {
|
|
244
|
+
return resolvedTo;
|
|
245
|
+
}
|
|
246
|
+
const fromParts = normalizeTail(fromRoot.rest, true);
|
|
247
|
+
const toParts = normalizeTail(toRoot.rest, true);
|
|
248
|
+
let common = 0;
|
|
249
|
+
while (common < fromParts.length && common < toParts.length) {
|
|
250
|
+
const fromPart = fromParts[common];
|
|
251
|
+
const toPart = toParts[common];
|
|
252
|
+
const equal = windows ? fromPart.toLowerCase() === toPart.toLowerCase() : fromPart === toPart;
|
|
253
|
+
if (!equal)
|
|
254
|
+
break;
|
|
255
|
+
common++;
|
|
256
|
+
}
|
|
257
|
+
const result = [
|
|
258
|
+
...Array.from({ length: fromParts.length - common }, () => ".."),
|
|
259
|
+
...toParts.slice(common),
|
|
260
|
+
];
|
|
261
|
+
return result.join("/") || ".";
|
|
262
|
+
}
|
|
263
|
+
export function portableParse(path, windows) {
|
|
264
|
+
const root = analyzeRoot(path, windows);
|
|
265
|
+
let canonical = canonicalPath(path, windows);
|
|
266
|
+
while (canonical.endsWith("/") &&
|
|
267
|
+
canonical.length > root.root.length) {
|
|
268
|
+
canonical = canonical.slice(0, -1);
|
|
269
|
+
}
|
|
270
|
+
const base = windows && root.device.startsWith("//") && root.rest === ""
|
|
271
|
+
? ""
|
|
272
|
+
: portableBasename(canonical, undefined, windows);
|
|
273
|
+
const ext = portableExtname(base, windows);
|
|
274
|
+
const name = base.slice(0, base.length - ext.length);
|
|
275
|
+
let dir = "";
|
|
276
|
+
if (base === "") {
|
|
277
|
+
dir = root.root;
|
|
278
|
+
}
|
|
279
|
+
else if (canonical.includes("/") ||
|
|
280
|
+
(windows && root.device !== "")) {
|
|
281
|
+
dir = portableDirname(canonical, windows);
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
root: root.root,
|
|
285
|
+
dir,
|
|
286
|
+
base,
|
|
287
|
+
ext,
|
|
288
|
+
name,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
export function portableFormat(pathObject, windows) {
|
|
292
|
+
const root = toPortableSeparators(pathObject.root ?? "");
|
|
293
|
+
const dir = toPortableSeparators(pathObject.dir ?? "");
|
|
294
|
+
const rawExt = pathObject.ext ?? "";
|
|
295
|
+
const ext = rawExt && !rawExt.startsWith(".") ? `.${rawExt}` : rawExt;
|
|
296
|
+
const base = pathObject.base ||
|
|
297
|
+
`${pathObject.name ?? ""}${ext}`;
|
|
298
|
+
const directory = dir || root;
|
|
299
|
+
if (!directory)
|
|
300
|
+
return base;
|
|
301
|
+
if (!base)
|
|
302
|
+
return directory;
|
|
303
|
+
if (directory.endsWith("/") || (windows && /^[A-Za-z]:$/.test(directory))) {
|
|
304
|
+
return `${directory}${base}`;
|
|
305
|
+
}
|
|
306
|
+
return `${directory}/${base}`;
|
|
307
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PosixPath {
|
|
2
|
+
join(...paths: string[]): string;
|
|
3
|
+
resolve(...paths: string[]): string;
|
|
4
|
+
normalize(path: string): string;
|
|
5
|
+
relative(from: string, to: string): string;
|
|
6
|
+
dirname(path: string): string;
|
|
7
|
+
basename(path: string, suffix?: string): string;
|
|
8
|
+
extname(path: string): string;
|
|
9
|
+
isAbsolute(path: string): boolean;
|
|
10
|
+
readonly sep: "/";
|
|
11
|
+
readonly delimiter: ":";
|
|
12
|
+
}
|
|
13
|
+
export declare const posix: Readonly<PosixPath>;
|
|
14
|
+
//# sourceMappingURL=posix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posix.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/posix.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACpC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC;CACzB;AAkND,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,SAAS,CAWpC,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/** Dependency-free POSIX path operations for every supported runtime. */
|
|
2
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
3
|
+
function assertPath(value) {
|
|
4
|
+
if (typeof value !== "string") {
|
|
5
|
+
throw new TypeError(`Path must be a string. Received ${typeof value}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function normalizeSegments(path, allowAboveRoot) {
|
|
9
|
+
const segments = [];
|
|
10
|
+
for (const segment of path.split("/")) {
|
|
11
|
+
if (segment.length === 0 || segment === ".")
|
|
12
|
+
continue;
|
|
13
|
+
if (segment !== "..") {
|
|
14
|
+
segments.push(segment);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const previous = segments.at(-1);
|
|
18
|
+
if (previous !== undefined && previous !== "..") {
|
|
19
|
+
segments.pop();
|
|
20
|
+
}
|
|
21
|
+
else if (allowAboveRoot) {
|
|
22
|
+
segments.push("..");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return segments.join("/");
|
|
26
|
+
}
|
|
27
|
+
function runtimeWorkingDirectory() {
|
|
28
|
+
const runtime = dntShim.dntGlobalThis;
|
|
29
|
+
if (typeof runtime.Deno?.cwd === "function") {
|
|
30
|
+
const directory = runtime.Deno.cwd();
|
|
31
|
+
assertPath(directory);
|
|
32
|
+
return directory;
|
|
33
|
+
}
|
|
34
|
+
if (typeof runtime.process?.cwd === "function") {
|
|
35
|
+
const directory = runtime.process.cwd();
|
|
36
|
+
assertPath(directory);
|
|
37
|
+
return directory;
|
|
38
|
+
}
|
|
39
|
+
// Browser and worker runtimes resolve relative virtual paths from their root.
|
|
40
|
+
return "/";
|
|
41
|
+
}
|
|
42
|
+
function normalize(path) {
|
|
43
|
+
assertPath(path);
|
|
44
|
+
if (path.length === 0)
|
|
45
|
+
return ".";
|
|
46
|
+
const absolute = path.startsWith("/");
|
|
47
|
+
const trailingSeparator = path.endsWith("/");
|
|
48
|
+
let normalized = normalizeSegments(path, !absolute);
|
|
49
|
+
if (normalized.length > 0 && trailingSeparator)
|
|
50
|
+
normalized += "/";
|
|
51
|
+
if (absolute)
|
|
52
|
+
return normalized.length > 0 ? `/${normalized}` : "/";
|
|
53
|
+
if (normalized.length > 0)
|
|
54
|
+
return normalized;
|
|
55
|
+
return trailingSeparator ? "./" : ".";
|
|
56
|
+
}
|
|
57
|
+
function join(...paths) {
|
|
58
|
+
let joined = "";
|
|
59
|
+
for (const path of paths) {
|
|
60
|
+
assertPath(path);
|
|
61
|
+
if (path.length === 0)
|
|
62
|
+
continue;
|
|
63
|
+
joined = joined.length === 0 ? path : `${joined}/${path}`;
|
|
64
|
+
}
|
|
65
|
+
return joined.length === 0 ? "." : normalize(joined);
|
|
66
|
+
}
|
|
67
|
+
function resolve(...paths) {
|
|
68
|
+
let resolved = "";
|
|
69
|
+
let absolute = false;
|
|
70
|
+
for (let index = paths.length - 1; index >= -1 && !absolute; index--) {
|
|
71
|
+
const path = index >= 0 ? paths[index] : runtimeWorkingDirectory();
|
|
72
|
+
assertPath(path);
|
|
73
|
+
if (path.length === 0)
|
|
74
|
+
continue;
|
|
75
|
+
resolved = `${path}/${resolved}`;
|
|
76
|
+
absolute = path.startsWith("/");
|
|
77
|
+
}
|
|
78
|
+
const normalized = normalizeSegments(resolved, !absolute);
|
|
79
|
+
if (absolute)
|
|
80
|
+
return normalized.length > 0 ? `/${normalized}` : "/";
|
|
81
|
+
return normalized.length > 0 ? normalized : ".";
|
|
82
|
+
}
|
|
83
|
+
function relative(from, to) {
|
|
84
|
+
assertPath(from);
|
|
85
|
+
assertPath(to);
|
|
86
|
+
const resolvedFrom = resolve(from);
|
|
87
|
+
const resolvedTo = resolve(to);
|
|
88
|
+
if (resolvedFrom === resolvedTo)
|
|
89
|
+
return "";
|
|
90
|
+
const fromSegments = resolvedFrom.split("/").filter(Boolean);
|
|
91
|
+
const toSegments = resolvedTo.split("/").filter(Boolean);
|
|
92
|
+
let common = 0;
|
|
93
|
+
while (common < fromSegments.length &&
|
|
94
|
+
common < toSegments.length &&
|
|
95
|
+
fromSegments[common] === toSegments[common]) {
|
|
96
|
+
common++;
|
|
97
|
+
}
|
|
98
|
+
return [
|
|
99
|
+
...Array.from({ length: fromSegments.length - common }, () => ".."),
|
|
100
|
+
...toSegments.slice(common),
|
|
101
|
+
].join("/");
|
|
102
|
+
}
|
|
103
|
+
function dirname(path) {
|
|
104
|
+
assertPath(path);
|
|
105
|
+
if (path.length === 0)
|
|
106
|
+
return ".";
|
|
107
|
+
const hasRoot = path.startsWith("/");
|
|
108
|
+
let end = -1;
|
|
109
|
+
let matchedSeparator = true;
|
|
110
|
+
for (let index = path.length - 1; index >= 1; index--) {
|
|
111
|
+
if (path[index] === "/") {
|
|
112
|
+
if (!matchedSeparator) {
|
|
113
|
+
end = index;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
matchedSeparator = false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (end === -1)
|
|
122
|
+
return hasRoot ? "/" : ".";
|
|
123
|
+
if (hasRoot && end === 1)
|
|
124
|
+
return "//";
|
|
125
|
+
return path.slice(0, end);
|
|
126
|
+
}
|
|
127
|
+
function basename(path, suffix) {
|
|
128
|
+
assertPath(path);
|
|
129
|
+
if (suffix !== undefined)
|
|
130
|
+
assertPath(suffix);
|
|
131
|
+
let start = 0;
|
|
132
|
+
let end = -1;
|
|
133
|
+
let matchedSeparator = true;
|
|
134
|
+
if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
|
|
135
|
+
if (suffix === path)
|
|
136
|
+
return "";
|
|
137
|
+
let suffixIndex = suffix.length - 1;
|
|
138
|
+
let firstNonSeparatorEnd = -1;
|
|
139
|
+
for (let index = path.length - 1; index >= 0; index--) {
|
|
140
|
+
const character = path[index];
|
|
141
|
+
if (character === "/") {
|
|
142
|
+
if (!matchedSeparator) {
|
|
143
|
+
start = index + 1;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (firstNonSeparatorEnd === -1) {
|
|
149
|
+
matchedSeparator = false;
|
|
150
|
+
firstNonSeparatorEnd = index + 1;
|
|
151
|
+
}
|
|
152
|
+
if (suffixIndex < 0)
|
|
153
|
+
continue;
|
|
154
|
+
if (character === suffix[suffixIndex]) {
|
|
155
|
+
suffixIndex--;
|
|
156
|
+
if (suffixIndex === -1)
|
|
157
|
+
end = index;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
suffixIndex = -1;
|
|
161
|
+
end = firstNonSeparatorEnd;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (start === end)
|
|
165
|
+
end = firstNonSeparatorEnd;
|
|
166
|
+
else if (end === -1)
|
|
167
|
+
end = path.length;
|
|
168
|
+
return path.slice(start, end);
|
|
169
|
+
}
|
|
170
|
+
for (let index = path.length - 1; index >= 0; index--) {
|
|
171
|
+
if (path[index] === "/") {
|
|
172
|
+
if (!matchedSeparator) {
|
|
173
|
+
start = index + 1;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (end === -1) {
|
|
178
|
+
matchedSeparator = false;
|
|
179
|
+
end = index + 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return end === -1 ? "" : path.slice(start, end);
|
|
183
|
+
}
|
|
184
|
+
function extname(path) {
|
|
185
|
+
const base = basename(path);
|
|
186
|
+
if (base === "." || base === "..")
|
|
187
|
+
return "";
|
|
188
|
+
const lastDot = base.lastIndexOf(".");
|
|
189
|
+
return lastDot <= 0 ? "" : base.slice(lastDot);
|
|
190
|
+
}
|
|
191
|
+
function isAbsolute(path) {
|
|
192
|
+
assertPath(path);
|
|
193
|
+
return path.startsWith("/");
|
|
194
|
+
}
|
|
195
|
+
export const posix = Object.freeze({
|
|
196
|
+
join,
|
|
197
|
+
resolve,
|
|
198
|
+
normalize,
|
|
199
|
+
relative,
|
|
200
|
+
dirname,
|
|
201
|
+
basename,
|
|
202
|
+
extname,
|
|
203
|
+
isAbsolute,
|
|
204
|
+
sep: "/",
|
|
205
|
+
delimiter: ":",
|
|
206
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Resolve path segments to an absolute path. */
|
|
1
|
+
/** Resolve path segments to an absolute, normalized path. */
|
|
2
2
|
export declare function resolve(...paths: string[]): string;
|
|
3
3
|
export declare function isAbsolute(path: string): boolean;
|
|
4
4
|
export declare function relative(from: string, to: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/resolution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/resolution.ts"],"names":[],"mappings":"AAgBA,6DAA6D;AAC7D,wBAAgB,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAMlD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIhD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAOzD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW9C"}
|