-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
import type NodePath from "node:path"; | ||
import type { posix as Posix, win32 as Win32, PlatformPath } from "node:path"; | ||
|
||
import * as path from "./path"; | ||
import * as _path from "./_path"; | ||
|
||
export * from "./path"; | ||
export * from "./_path"; | ||
|
||
export type Pathe = Omit<typeof NodePath, "posix" | "win32">; | ||
/** | ||
* The platform-specific file delimiter. | ||
* | ||
* Equals to `";"` in windows and `":"` in all other platforms. | ||
*/ | ||
export const delimiter: ";" | ":" = /* @__PURE__ */ (() => | ||
globalThis.process?.platform === "win32" ? ";" : ":")(); | ||
|
||
export const posix = path satisfies Pathe; | ||
// Mix namespaces without side-effects of object to allow tree-shaking | ||
|
||
export const win32 = path satisfies Pathe; | ||
const _platforms = { posix: undefined, win32: undefined } as { | ||
posix: typeof Posix; | ||
win32: typeof Win32; | ||
}; | ||
|
||
export default path satisfies Pathe; | ||
const mix = (del: ";" | ":" = delimiter) => { | ||
return new Proxy(_path, { | ||
get(_, prop) { | ||
if (prop === "delimiter") return del; | ||
if (prop === "posix") return posix; | ||
if (prop === "win32") return win32; | ||
return _platforms[prop] || _path[prop]; | ||
}, | ||
}) as unknown as PlatformPath; | ||
}; | ||
|
||
export const posix = /* @__PURE__ */ mix(":") as typeof Posix; | ||
export const win32 = /* @__PURE__ */ mix(";") as typeof Win32; | ||
|
||
export default posix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters