Skip to content

Commit

Permalink
fix: use node:path export types (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jan 9, 2025
1 parent 4353c6a commit c740a24
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { posix as Posix, win32 as Win32, PlatformPath } from "node:path";

import * as _path from "./_path";

export * from "./_path";

type NodePath = typeof import("node:path");

/**
* The platform-specific file delimiter.
*
Expand All @@ -15,8 +15,8 @@ export const delimiter: ";" | ":" = /* @__PURE__ */ (() =>
// Mix namespaces without side-effects of object to allow tree-shaking

const _platforms = { posix: undefined, win32: undefined } as {
posix: typeof Posix;
win32: typeof Win32;
posix: NodePath["posix"];
win32: NodePath["win32"];
};

const mix = (del: ";" | ":" = delimiter) => {
Expand All @@ -27,10 +27,11 @@ const mix = (del: ";" | ":" = delimiter) => {
if (prop === "win32") return win32;
return _platforms[prop] || _path[prop];
},
}) as unknown as PlatformPath;
}) as unknown as NodePath;
};

export const posix = /* @__PURE__ */ mix(":") as typeof Posix;
export const win32 = /* @__PURE__ */ mix(";") as typeof Win32;
export const posix = /* @__PURE__ */ mix(":") as NodePath["posix"];

export const win32 = /* @__PURE__ */ mix(";") as NodePath["win32"];

export default posix;
export default posix as NodePath;

0 comments on commit c740a24

Please sign in to comment.