path.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. declare enum PathType {
  2. File = 0,
  3. Portable = 1,
  4. Native = 2
  5. }
  6. export type PortablePath = string & {
  7. __pathType: PathType.File | PathType.Portable;
  8. };
  9. export type NativePath = string & {
  10. __pathType?: PathType.File | PathType.Native;
  11. };
  12. export declare const PortablePath: {
  13. root: PortablePath;
  14. dot: PortablePath;
  15. parent: PortablePath;
  16. };
  17. export type Filename = string & {
  18. __pathType: PathType.File;
  19. };
  20. export type Path = PortablePath | NativePath;
  21. export declare const Filename: {
  22. nodeModules: Filename;
  23. manifest: Filename;
  24. lockfile: Filename;
  25. virtual: Filename;
  26. /**
  27. * @deprecated
  28. */
  29. pnpJs: Filename;
  30. pnpCjs: Filename;
  31. rc: Filename;
  32. };
  33. export type FSPath<T extends Path> = T | number;
  34. export declare const npath: PathUtils<NativePath> & ConvertUtils;
  35. export declare const ppath: PathUtils<PortablePath>;
  36. export interface ParsedPath<P extends Path> {
  37. root: P;
  38. dir: P;
  39. base: Filename;
  40. ext: string;
  41. name: Filename;
  42. }
  43. export interface FormatInputPathObject<P extends Path> {
  44. root?: P;
  45. dir?: P;
  46. base?: Filename;
  47. ext?: string;
  48. name?: Filename;
  49. }
  50. export interface PathUtils<P extends Path> {
  51. cwd(): P;
  52. normalize(p: P): P;
  53. join(...paths: Array<P | Filename>): P;
  54. resolve(...pathSegments: Array<P | Filename>): P;
  55. isAbsolute(path: P): boolean;
  56. relative(from: P, to: P): P;
  57. dirname(p: P): P;
  58. basename(p: P, ext?: string): Filename;
  59. extname(p: P): string;
  60. readonly sep: P;
  61. readonly delimiter: string;
  62. parse(pathString: P): ParsedPath<P>;
  63. format(pathObject: FormatInputPathObject<P>): P;
  64. contains(from: P, to: P): P | null;
  65. }
  66. export interface ConvertUtils {
  67. fromPortablePath: (p: Path) => NativePath;
  68. toPortablePath: (p: Path) => PortablePath;
  69. }
  70. export declare function convertPath<P extends Path>(targetPathUtils: PathUtils<P>, sourcePath: Path): P;
  71. export declare function toFilename(filename: string): Filename;
  72. export {};