@veryfront/ext-content-mdx 0.1.1183 → 0.1.1186

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.
Files changed (68) hide show
  1. package/esm/deno.d.ts +20 -1
  2. package/esm/deno.js +31 -6
  3. package/esm/src/errors/error-registry.d.ts +2 -2
  4. package/esm/src/extensions/websocket/index.d.ts +3 -0
  5. package/esm/src/extensions/websocket/index.d.ts.map +1 -0
  6. package/esm/src/extensions/websocket/index.js +2 -0
  7. package/esm/src/extensions/websocket/node-websocket-server-provider.d.ts +51 -0
  8. package/esm/src/extensions/websocket/node-websocket-server-provider.d.ts.map +1 -0
  9. package/esm/src/extensions/websocket/node-websocket-server-provider.js +146 -0
  10. package/esm/src/platform/adapters/base.d.ts +35 -0
  11. package/esm/src/platform/adapters/base.d.ts.map +1 -1
  12. package/esm/src/platform/adapters/base.js +54 -5
  13. package/esm/src/platform/adapters/bounded-file-read.d.ts +34 -0
  14. package/esm/src/platform/adapters/bounded-file-read.d.ts.map +1 -0
  15. package/esm/src/platform/adapters/bounded-file-read.js +179 -0
  16. package/esm/src/platform/adapters/file-snapshot-error.d.ts +6 -0
  17. package/esm/src/platform/adapters/file-snapshot-error.d.ts.map +1 -0
  18. package/esm/src/platform/adapters/file-snapshot-error.js +11 -0
  19. package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.d.ts +33 -0
  20. package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.d.ts.map +1 -0
  21. package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.js +205 -0
  22. package/esm/src/platform/compat/fs.d.ts +6 -2
  23. package/esm/src/platform/compat/fs.d.ts.map +1 -1
  24. package/esm/src/platform/compat/fs.js +55 -19
  25. package/esm/src/platform/compat/not-found-error.d.ts +7 -0
  26. package/esm/src/platform/compat/not-found-error.d.ts.map +1 -0
  27. package/esm/src/platform/compat/not-found-error.js +41 -0
  28. package/esm/src/platform/compat/path/basic-operations.d.ts +1 -1
  29. package/esm/src/platform/compat/path/basic-operations.d.ts.map +1 -1
  30. package/esm/src/platform/compat/path/basic-operations.js +24 -44
  31. package/esm/src/platform/compat/path/index.d.ts +1 -0
  32. package/esm/src/platform/compat/path/index.d.ts.map +1 -1
  33. package/esm/src/platform/compat/path/index.js +1 -0
  34. package/esm/src/platform/compat/path/parse-format.d.ts.map +1 -1
  35. package/esm/src/platform/compat/path/parse-format.js +26 -20
  36. package/esm/src/platform/compat/path/portable.d.ts +16 -0
  37. package/esm/src/platform/compat/path/portable.d.ts.map +1 -0
  38. package/esm/src/platform/compat/path/portable.js +307 -0
  39. package/esm/src/platform/compat/path/posix.d.ts +14 -0
  40. package/esm/src/platform/compat/path/posix.d.ts.map +1 -0
  41. package/esm/src/platform/compat/path/posix.js +206 -0
  42. package/esm/src/platform/compat/path/resolution.d.ts +1 -1
  43. package/esm/src/platform/compat/path/resolution.d.ts.map +1 -1
  44. package/esm/src/platform/compat/path/resolution.js +28 -112
  45. package/esm/src/platform/compat/path/runtime.d.ts +2 -1
  46. package/esm/src/platform/compat/path/runtime.d.ts.map +1 -1
  47. package/esm/src/platform/compat/path/runtime.js +5 -0
  48. package/esm/src/platform/compat/path/types.d.ts +5 -1
  49. package/esm/src/platform/compat/path/types.d.ts.map +1 -1
  50. package/esm/src/platform/compat/path/url-conversion.d.ts +10 -0
  51. package/esm/src/platform/compat/path/url-conversion.d.ts.map +1 -1
  52. package/esm/src/platform/compat/path/url-conversion.js +63 -41
  53. package/esm/src/platform/compat/process.d.ts +1 -1
  54. package/esm/src/utils/constants/build.d.ts +9 -0
  55. package/esm/src/utils/constants/build.d.ts.map +1 -1
  56. package/esm/src/utils/constants/build.js +9 -0
  57. package/esm/src/utils/constants/index.d.ts +1 -1
  58. package/esm/src/utils/constants/index.d.ts.map +1 -1
  59. package/esm/src/utils/constants/index.js +1 -1
  60. package/esm/src/utils/css-artifact-identity.d.ts +23 -0
  61. package/esm/src/utils/css-artifact-identity.d.ts.map +1 -0
  62. package/esm/src/utils/css-artifact-identity.js +77 -0
  63. package/esm/src/utils/index.d.ts +1 -0
  64. package/esm/src/utils/index.d.ts.map +1 -1
  65. package/esm/src/utils/index.js +1 -0
  66. package/esm/src/utils/version-constant.d.ts +1 -1
  67. package/esm/src/utils/version-constant.js +1 -1
  68. package/package.json +2 -2
@@ -1,6 +1,9 @@
1
1
  import * as dntShim from "../../../_dnt.shims.js";
2
2
  import { createError, toError } from "../../errors/veryfront-error.js";
3
3
  import { isBun, isDeno, isNode } from "./runtime.js";
4
+ import { readFileWithinLimit } from "../adapters/bounded-file-read.js";
5
+ import { readNodeFileSnapshotWithinLimit, supportsNativeFileSnapshots, } from "../adapters/runtime/shared/native-file-capabilities.js";
6
+ export { isNotFoundError } from "./not-found-error.js";
4
7
  /**
5
8
  * Typed accessor for the Deno global.
6
9
  *
@@ -13,6 +16,9 @@ function denoGlobal() {
13
16
  return dntShim.dntGlobalThis.Deno;
14
17
  }
15
18
  class NodeFileSystem {
19
+ readFileSnapshotWithinLimit = supportsNativeFileSnapshots()
20
+ ? (path, containmentRoot, byteLimit) => readNodeFileSnapshotWithinLimit(path, containmentRoot, byteLimit)
21
+ : undefined;
16
22
  fs;
17
23
  os;
18
24
  path;
@@ -60,6 +66,19 @@ class NodeFileSystem {
60
66
  await this.ensureInitialized();
61
67
  return this.getFs().readFile(path);
62
68
  }
69
+ async readFileBytesWithinLimit(path, byteLimit) {
70
+ await this.ensureInitialized();
71
+ return await readFileWithinLimit(async () => {
72
+ const handle = await this.getFs().open(path, "r");
73
+ return {
74
+ close: () => handle.close(),
75
+ read: async (buffer) => {
76
+ const { bytesRead } = await handle.read(buffer, 0, buffer.byteLength, null);
77
+ return bytesRead === 0 ? null : bytesRead;
78
+ },
79
+ };
80
+ }, byteLimit);
81
+ }
63
82
  async writeTextFile(path, data) {
64
83
  await this.ensureInitialized();
65
84
  await this.getFs().writeFile(path, data, { encoding: "utf8" });
@@ -68,6 +87,14 @@ class NodeFileSystem {
68
87
  await this.ensureInitialized();
69
88
  await this.getFs().writeFile(path, data);
70
89
  }
90
+ async createFileBytesExclusive(path, data) {
91
+ await this.ensureInitialized();
92
+ await this.getFs().writeFile(path, data, { flag: "wx" });
93
+ }
94
+ async rename(from, to) {
95
+ await this.ensureInitialized();
96
+ await this.getFs().rename(from, to);
97
+ }
71
98
  async exists(path) {
72
99
  await this.ensureInitialized();
73
100
  try {
@@ -142,18 +169,46 @@ class NodeFileSystem {
142
169
  }
143
170
  }
144
171
  class DenoFileSystem {
172
+ readFileSnapshotWithinLimit = supportsNativeFileSnapshots()
173
+ ? (path, containmentRoot, byteLimit) => readNodeFileSnapshotWithinLimit(path, containmentRoot, byteLimit)
174
+ : undefined;
145
175
  readTextFile(path) {
146
176
  return denoGlobal().readTextFile(path);
147
177
  }
148
178
  readFile(path) {
149
179
  return denoGlobal().readFile(path);
150
180
  }
181
+ async readFileBytesWithinLimit(path, byteLimit) {
182
+ return await readFileWithinLimit(async () => {
183
+ const file = await denoGlobal().open(path, { read: true });
184
+ return { close: () => file.close(), read: (buffer) => file.read(buffer) };
185
+ }, byteLimit);
186
+ }
151
187
  async writeTextFile(path, data) {
152
188
  await denoGlobal().writeTextFile(path, data);
153
189
  }
154
190
  async writeFile(path, data) {
155
191
  await denoGlobal().writeFile(path, data);
156
192
  }
193
+ async createFileBytesExclusive(path, data) {
194
+ const file = await denoGlobal().open(path, { write: true, createNew: true });
195
+ let offset = 0;
196
+ try {
197
+ while (offset < data.byteLength) {
198
+ const written = await file.write(data.subarray(offset));
199
+ if (!Number.isSafeInteger(written) || written <= 0 || written > data.byteLength - offset) {
200
+ throw new Error("Deno exclusive create write made no forward progress");
201
+ }
202
+ offset += written;
203
+ }
204
+ }
205
+ finally {
206
+ file.close();
207
+ }
208
+ }
209
+ async rename(from, to) {
210
+ await denoGlobal().rename(from, to);
211
+ }
157
212
  async exists(path) {
158
213
  try {
159
214
  await denoGlobal().stat(path);
@@ -308,25 +363,6 @@ export async function realPath(path) {
308
363
  const fs = await import("node:fs/promises");
309
364
  return await fs.realpath(path);
310
365
  }
311
- /** Error shape for is not found. */
312
- export function isNotFoundError(error, seen = new Set()) {
313
- if (seen.has(error))
314
- return false;
315
- seen.add(error);
316
- const NotFound = dntShim.dntGlobalThis.Deno?.errors?.NotFound;
317
- if (isDeno && NotFound && error instanceof NotFound)
318
- return true;
319
- if (error?.code === "ENOENT")
320
- return true;
321
- if (error instanceof Error && error.name === "VeryfrontError" &&
322
- error.slug === "file-not-found") {
323
- return true;
324
- }
325
- if (error instanceof Error && "cause" in error) {
326
- return isNotFoundError(error.cause, seen);
327
- }
328
- return false;
329
- }
330
366
  /** Error shape for is already exists. */
331
367
  export function isAlreadyExistsError(error) {
332
368
  const AlreadyExists = dntShim.dntGlobalThis.Deno?.errors?.AlreadyExists;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Return whether an error or its cause chain represents a path that cannot be
3
+ * resolved. ENOTDIR is included because a missing candidate beneath a file is
4
+ * just as absent as an ENOENT candidate during filesystem lookup.
5
+ */
6
+ export declare function isNotFoundError(error: unknown, seen?: Set<unknown>): boolean;
7
+ //# sourceMappingURL=not-found-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-found-error.d.ts","sourceRoot":"","sources":["../../../../src/src/platform/compat/not-found-error.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,GAAG,CAAC,OAAO,CAAa,GAAG,OAAO,CAuCvF"}
@@ -0,0 +1,41 @@
1
+ import * as dntShim from "../../../_dnt.shims.js";
2
+ import { isDeno } from "./runtime.js";
3
+ /**
4
+ * Return whether an error or its cause chain represents a path that cannot be
5
+ * resolved. ENOTDIR is included because a missing candidate beneath a file is
6
+ * just as absent as an ENOENT candidate during filesystem lookup.
7
+ */
8
+ export function isNotFoundError(error, seen = new Set()) {
9
+ if (seen.has(error))
10
+ return false;
11
+ seen.add(error);
12
+ try {
13
+ const NotFound = dntShim.dntGlobalThis.Deno?.errors?.NotFound;
14
+ if (isDeno && NotFound && error instanceof NotFound)
15
+ return true;
16
+ const code = error?.code;
17
+ if (code === "ENOENT" || code === "ENOTDIR")
18
+ return true;
19
+ if (error instanceof Error) {
20
+ if (error.name === "VeryfrontError" &&
21
+ error.slug === "file-not-found") {
22
+ return true;
23
+ }
24
+ const legacyContext = error.context;
25
+ if (error.name === "VeryfrontError[file]" &&
26
+ typeof legacyContext === "object" &&
27
+ legacyContext !== null &&
28
+ legacyContext.type === "file" &&
29
+ typeof legacyContext.message === "string" &&
30
+ /^(?:File|Path) not found:/.test(legacyContext.message)) {
31
+ return true;
32
+ }
33
+ if ("cause" in error)
34
+ return isNotFoundError(error.cause, seen);
35
+ }
36
+ }
37
+ catch {
38
+ // Error classifiers must not replace the original filesystem failure.
39
+ }
40
+ return false;
41
+ }
@@ -1,4 +1,4 @@
1
- /** Join path segments. */
1
+ /** Join and normalize path segments using their detected path flavor. */
2
2
  export declare function join(...paths: string[]): string;
3
3
  /** Return the parent directory path. */
4
4
  export declare function dirname(path: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"basic-operations.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/basic-operations.ts"],"names":[],"mappings":"AAWA,0BAA0B;AAC1B,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAS/C;AAED,wCAAwC;AACxC,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ5C;AAED,oCAAoC;AACpC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAiB3D;AAED,4CAA4C;AAC5C,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5C"}
1
+ {"version":3,"file":"basic-operations.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/basic-operations.ts"],"names":[],"mappings":"AAgBA,yEAAyE;AACzE,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAQ/C;AAED,wCAAwC;AACxC,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED,oCAAoC;AACpC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED,4CAA4C;AAC5C,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5C"}
@@ -1,56 +1,36 @@
1
- import { isDeno, nodePath } from "./runtime.js";
2
- function hasWindowsLikePath(path) {
3
- return path.includes("\\") || /^[A-Za-z]:/.test(path) || path.startsWith("\\\\");
1
+ import { hasWindowsLikePath, portableBasename, portableDirname, portableExtname, portableJoin, removeTrailingSeparatorsExceptRoot, runtimeUsesWindowsPaths, toPortableSeparators, } from "./portable.js";
2
+ import { getNativePathImplementation } from "./runtime.js";
3
+ function usesWindowsFlavor(paths) {
4
+ return runtimeUsesWindowsPaths() || paths.some(hasWindowsLikePath);
4
5
  }
5
- /** Normalize backslashes to forward slashes (for Deno on Windows). */
6
- function normSep(p) {
7
- return p.includes("\\") ? p.replace(/\\/g, "/") : p;
8
- }
9
- /** Join path segments. */
6
+ /** Join and normalize path segments using their detected path flavor. */
10
7
  export function join(...paths) {
11
- const joined = paths
12
- .map(normSep)
13
- .filter((p) => p.length > 0)
14
- .join("/")
15
- .replace(/\/+/g, "/")
16
- .replace(/\/$/, "");
17
- return joined || "/";
8
+ if (paths.every((path) => path.length === 0))
9
+ return "/";
10
+ const windows = usesWindowsFlavor(paths);
11
+ const pathApi = getNativePathImplementation(windows);
12
+ const joined = pathApi
13
+ ? toPortableSeparators(pathApi.join(...paths))
14
+ : portableJoin(paths, windows);
15
+ return removeTrailingSeparatorsExceptRoot(joined, windows);
18
16
  }
19
17
  /** Return the parent directory path. */
20
18
  export function dirname(path) {
21
- if (!isDeno && nodePath && !hasWindowsLikePath(path))
22
- return nodePath.dirname(path);
23
- const p = normSep(path);
24
- const lastSlash = p.lastIndexOf("/");
25
- if (lastSlash === -1)
26
- return ".";
27
- if (lastSlash === 0)
28
- return "/";
29
- return p.slice(0, lastSlash);
19
+ const windows = usesWindowsFlavor([path]);
20
+ const pathApi = getNativePathImplementation(windows);
21
+ return pathApi ? toPortableSeparators(pathApi.dirname(path)) : portableDirname(path, windows);
30
22
  }
31
23
  /** Return the last path segment. */
32
24
  export function basename(path, ext) {
33
- if (!isDeno && nodePath && !hasWindowsLikePath(path)) {
34
- // Only pass ext if defined - Bun is strict about this parameter
35
- return ext === undefined ? nodePath.basename(path) : nodePath.basename(path, ext);
36
- }
37
- let normalizedPath = normSep(path);
38
- while (normalizedPath.length > 1 && normalizedPath.endsWith("/")) {
39
- normalizedPath = normalizedPath.slice(0, -1);
40
- }
41
- const lastSlash = normalizedPath.lastIndexOf("/");
42
- let base = lastSlash === -1 ? normalizedPath : normalizedPath.slice(lastSlash + 1);
43
- if (ext && base.endsWith(ext))
44
- base = base.slice(0, -ext.length);
45
- return base;
25
+ const windows = usesWindowsFlavor([path]);
26
+ const pathApi = getNativePathImplementation(windows);
27
+ if (!pathApi)
28
+ return portableBasename(path, ext, windows);
29
+ return ext === undefined ? pathApi.basename(path) : pathApi.basename(path, ext);
46
30
  }
47
31
  /** Return the file extension for a path. */
48
32
  export function extname(path) {
49
- if (!isDeno && nodePath && !hasWindowsLikePath(path))
50
- return nodePath.extname(path);
51
- const base = basename(path);
52
- const lastDot = base.lastIndexOf(".");
53
- if (lastDot <= 0)
54
- return "";
55
- return base.slice(lastDot);
33
+ const windows = usesWindowsFlavor([path]);
34
+ const pathApi = getNativePathImplementation(windows);
35
+ return pathApi?.extname(path) ?? portableExtname(path, windows);
56
36
  }
@@ -8,6 +8,7 @@ export { delimiter, hasNodePath, isDeno, nodePath, sep, sep as SEPARATOR } from
8
8
  export { basename, dirname, extname, join } from "./basic-operations.js";
9
9
  export { isAbsolute, normalize, relative, resolve } from "./resolution.js";
10
10
  export { format, parse } from "./parse-format.js";
11
+ export { posix, type PosixPath } from "./posix.js";
11
12
  export { fromFileUrl, toFileUrl } from "./url-conversion.js";
12
13
  export { validatePathSecurity } from "./security.js";
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
@@ -7,5 +7,6 @@ export { delimiter, hasNodePath, isDeno, nodePath, sep, sep as SEPARATOR } from
7
7
  export { basename, dirname, extname, join } from "./basic-operations.js";
8
8
  export { isAbsolute, normalize, relative, resolve } from "./resolution.js";
9
9
  export { format, parse } from "./parse-format.js";
10
+ export { posix } from "./posix.js";
10
11
  export { fromFileUrl, toFileUrl } from "./url-conversion.js";
11
12
  export { validatePathSecurity } from "./security.js";
@@ -1 +1 @@
1
- {"version":3,"file":"parse-format.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/parse-format.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAgB9C;AAED,wBAAgB,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CASrD"}
1
+ {"version":3,"file":"parse-format.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/parse-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAU7C,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAa9C;AAED,wBAAgB,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAerD"}
@@ -1,26 +1,32 @@
1
- import { isDeno, nodePath } from "./runtime.js";
2
- import { basename, dirname, extname, join } from "./basic-operations.js";
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
- if (!isDeno && nodePath) {
6
- return nodePath.parse(path);
7
- }
8
- const dir = dirname(path);
9
- const base = basename(path);
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: isAbsolute(path) ? "/" : "",
13
- dir,
14
- base,
15
- ext,
16
- name: base.slice(0, base.length - ext.length),
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
- if (!isDeno && nodePath) {
21
- return nodePath.format(pathObject);
22
- }
23
- const { dir = "", base = "", name = "", ext = "" } = pathObject;
24
- const fileName = base || name + ext;
25
- return dir ? join(dir, fileName) : fileName;
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"}