@reliverse/pathkit 1.0.6 → 1.1.0
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/README.md +19 -23
- package/bin/mod.d.ts +157 -31
- package/bin/mod.js +721 -43
- package/package.json +23 -4
- package/bin/delete-me.d.ts +0 -1
- package/bin/delete-me.js +0 -1
- package/bin/pathkit-impl/impl.d.ts +0 -9
- package/bin/pathkit-impl/impl.js +0 -16
- package/bin/pathkit-impl/internal/path.d.ts +0 -26
- package/bin/pathkit-impl/internal/path.js +0 -208
- package/bin/pathkit-impl/internal/win.d.ts +0 -1
- package/bin/pathkit-impl/internal/win.js +0 -7
- package/bin/pathkit-impl/utils.d.ts +0 -30
- package/bin/pathkit-impl/utils.js +0 -75
package/README.md
CHANGED
|
@@ -1,45 +1,41 @@
|
|
|
1
1
|
# pathkit • cross‑platform path manipulation
|
|
2
2
|
|
|
3
|
-
> @reliverse/pathkit is a slash‑consistent, cross‑platform path manipulation
|
|
3
|
+
> @reliverse/pathkit is a slash‑consistent, cross‑platform path manipulation, with POSIX forward slash, drop‑in for node:path and unjs/pathe. This library extends the node:path module with a set of functions for manipulating file paths.
|
|
4
4
|
|
|
5
5
|
[sponsor](https://github.com/sponsors/blefnk) • [discord](https://discord.gg/Pb8uKbwpsJ) • [npm](https://npmjs.com/package/@reliverse/pathkit) • [repo](https://github.com/reliverse/pathkit)
|
|
6
6
|
|
|
7
7
|
## Key Features
|
|
8
8
|
|
|
9
|
-
- 🔹
|
|
10
|
-
- ➕ **`unjs/pathe` on
|
|
11
|
-
- 🌀 **
|
|
12
|
-
- ⚙️ **
|
|
13
|
-
- 🚀 **
|
|
14
|
-
- 🧠 **
|
|
9
|
+
- 🔹 **drop in** and replace `node:path` and `unjs/pathe` instantly.
|
|
10
|
+
- ➕ **`unjs/pathe` on steroids** – alias resolution, import parsing, and more.
|
|
11
|
+
- 🌀 **always `/`** – posix separators 100% of the time (buh‑bye `\\`).
|
|
12
|
+
- ⚙️ **node.js api compatible** – familiar methods, no learning curve.
|
|
13
|
+
- 🚀 **modern & fast** – typescript, pure esm, bun & node‑ready.
|
|
14
|
+
- 🧠 **predictable & testable** – deterministic output across windows / macos / linux.
|
|
15
|
+
- 🧼 **no dependencies** – just the path api + a couple of cool utilities.
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
17
18
|
|
|
18
19
|
```bash
|
|
19
20
|
# bun • pnpm • yarn • npm
|
|
20
21
|
bun add @reliverse/pathkit
|
|
21
|
-
bun add -D @reliverse/pathkit-plus
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
_In most cases_ you may need to install `@reliverse/pathkit` as **regular dependency**.
|
|
25
|
-
_In most cases_ you may need to install `@reliverse/pathkit-plus` as **dev dependency**.
|
|
26
|
-
|
|
27
24
|
**Migrate**:
|
|
28
25
|
|
|
29
26
|
```bash
|
|
30
27
|
bun rm pathe
|
|
31
28
|
# soon:
|
|
32
29
|
# bun add -D @reliverse/dler
|
|
33
|
-
# bun dler
|
|
34
|
-
# bun dler pathkit pathe-to-pathkit
|
|
30
|
+
# bun dler migrate --lib pathe-to-pathkit
|
|
35
31
|
```
|
|
36
32
|
|
|
37
|
-
### `
|
|
33
|
+
### `pathe` vs `pathkit`
|
|
38
34
|
|
|
39
35
|
| Package | What you get | When to use |
|
|
40
36
|
|---------|--------------|-------------|
|
|
41
|
-
| **`@reliverse/
|
|
42
|
-
| **`@reliverse/pathkit
|
|
37
|
+
| **`@reliverse/pathe`** | Core path API (POSIX everywhere) | You only need a drop‑in for `node:path` |
|
|
38
|
+
| **`@reliverse/pathkit`** | Everything in `pathe` **+** advanced utilities | You need alias resolution, import transforms, etc. |
|
|
43
39
|
|
|
44
40
|
## Why Pathkit? — The Problem with Native Paths
|
|
45
41
|
|
|
@@ -92,16 +88,16 @@ console.log(join("users", "blefnk")); // → "users/blefnk"
|
|
|
92
88
|
|
|
93
89
|
Say goodbye to `process.platform` conditionals 👋.
|
|
94
90
|
|
|
95
|
-
## pathkit
|
|
91
|
+
## pathkit advanced features
|
|
96
92
|
|
|
97
|
-
`@reliverse/pathkit
|
|
93
|
+
`@reliverse/pathkit` extends the core functionality of `node:path` with powerful utilities for working with imports, aliases, and more.
|
|
98
94
|
|
|
99
95
|
### Import/Export Analysis
|
|
100
96
|
|
|
101
97
|
The `getFileImportsExports` function provides detailed analysis of ES module imports and exports:
|
|
102
98
|
|
|
103
99
|
```ts
|
|
104
|
-
import { getFileImportsExports } from "@reliverse/pathkit
|
|
100
|
+
import { getFileImportsExports } from "@reliverse/pathkit";
|
|
105
101
|
|
|
106
102
|
const code = `
|
|
107
103
|
import { ref } from "vue";
|
|
@@ -152,7 +148,7 @@ Features:
|
|
|
152
148
|
Convert between different path formats:
|
|
153
149
|
|
|
154
150
|
```ts
|
|
155
|
-
import { convertImportPaths } from "@reliverse/pathkit
|
|
151
|
+
import { convertImportPaths } from "@reliverse/pathkit";
|
|
156
152
|
|
|
157
153
|
await convertImportPaths({
|
|
158
154
|
baseDir: "./src",
|
|
@@ -166,7 +162,7 @@ await convertImportPaths({
|
|
|
166
162
|
### Extension Conversion
|
|
167
163
|
|
|
168
164
|
```ts
|
|
169
|
-
import { convertImportExtensionsJsToTs } from "@reliverse/pathkit
|
|
165
|
+
import { convertImportExtensionsJsToTs } from "@reliverse/pathkit";
|
|
170
166
|
|
|
171
167
|
await convertImportExtensionsJsToTs({
|
|
172
168
|
dirPath: "./src",
|
|
@@ -181,7 +177,7 @@ import {
|
|
|
181
177
|
normalizeAliases,
|
|
182
178
|
resolveAlias,
|
|
183
179
|
reverseResolveAlias
|
|
184
|
-
} from "@reliverse/pathkit
|
|
180
|
+
} from "@reliverse/pathkit";
|
|
185
181
|
|
|
186
182
|
const aliases = { "@/": "/src/", "~/": "/home/user/" };
|
|
187
183
|
|
|
@@ -203,7 +199,7 @@ import {
|
|
|
203
199
|
extractPackageName, // Get package name from import
|
|
204
200
|
normalizeQuotes, // Standardize quote style
|
|
205
201
|
matchesGlob // Test glob patterns
|
|
206
|
-
} from "@reliverse/pathkit
|
|
202
|
+
} from "@reliverse/pathkit";
|
|
207
203
|
|
|
208
204
|
console.log(filename("/path/component.vue")); // "component"
|
|
209
205
|
console.log(extractPackageName("@scope/pkg")); // "@scope/pkg"
|
package/bin/mod.d.ts
CHANGED
|
@@ -1,44 +1,170 @@
|
|
|
1
1
|
import type { PlatformPath } from "node:path";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
declare const normalizedAliasSymbol: unique symbol;
|
|
3
|
+
interface NormalizedRecord extends Record<string, string> {
|
|
4
|
+
[normalizedAliasSymbol]?: true;
|
|
5
|
+
}
|
|
6
|
+
export interface ParsedPath {
|
|
7
7
|
root: string;
|
|
8
8
|
dir: string;
|
|
9
9
|
base: string;
|
|
10
10
|
ext: string;
|
|
11
11
|
name: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
export interface FormatInputPathObject {
|
|
14
14
|
root?: string;
|
|
15
15
|
dir?: string;
|
|
16
16
|
base?: string;
|
|
17
17
|
ext?: string;
|
|
18
18
|
name?: string;
|
|
19
|
+
}
|
|
20
|
+
type PathExtFilter = "js" | "ts" | "none" | "js-ts-none";
|
|
21
|
+
type ImportExtType = "js" | "ts" | "none";
|
|
22
|
+
/**
|
|
23
|
+
* removes directories with recursive force option
|
|
24
|
+
*/
|
|
25
|
+
declare function cleanDirs(dirs: string[]): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* recursively copies a directory and its contents
|
|
28
|
+
*/
|
|
29
|
+
declare function copyDir(src: string, dest: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* normalizes windows paths to use forward slashes
|
|
32
|
+
*/
|
|
33
|
+
declare function normalizeWindowsPath(input?: string): string;
|
|
34
|
+
declare const sep = "/";
|
|
35
|
+
/**
|
|
36
|
+
* normalizes a path, resolving . and .. segments
|
|
37
|
+
*/
|
|
38
|
+
declare const normalize: (path: string) => string;
|
|
39
|
+
/**
|
|
40
|
+
* joins path segments with proper normalization
|
|
41
|
+
*/
|
|
42
|
+
declare const join: (...segments: string[]) => string;
|
|
43
|
+
/**
|
|
44
|
+
* resolves path to an absolute path
|
|
45
|
+
*/
|
|
46
|
+
declare const resolve: (...args: string[]) => string;
|
|
47
|
+
/**
|
|
48
|
+
* checks if path is absolute
|
|
49
|
+
*/
|
|
50
|
+
declare const isAbsolute: (p: string) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* converts path to namespaced path for windows
|
|
53
|
+
*/
|
|
54
|
+
declare const toNamespacedPath: (p: string) => string;
|
|
55
|
+
/**
|
|
56
|
+
* gets file extension including the dot
|
|
57
|
+
*/
|
|
58
|
+
declare const extname: (p: string) => string;
|
|
59
|
+
/**
|
|
60
|
+
* gets relative path from one path to another
|
|
61
|
+
*/
|
|
62
|
+
declare const relative: (from: string, to: string) => string;
|
|
63
|
+
/**
|
|
64
|
+
* gets directory name from path
|
|
65
|
+
*/
|
|
66
|
+
declare const dirname: (p: string) => string;
|
|
67
|
+
/**
|
|
68
|
+
* formats object parts into a path string
|
|
69
|
+
*/
|
|
70
|
+
declare const format: (p: FormatInputPathObject) => string;
|
|
71
|
+
/**
|
|
72
|
+
* gets base filename from path
|
|
73
|
+
*/
|
|
74
|
+
declare const basename: (p: string, ext?: string) => string;
|
|
75
|
+
/**
|
|
76
|
+
* parses a path into its components
|
|
77
|
+
*/
|
|
78
|
+
declare const parse: (p: string) => ParsedPath;
|
|
79
|
+
/**
|
|
80
|
+
* gets filename without extension
|
|
81
|
+
*/
|
|
82
|
+
declare function filename(pathString: string): string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* normalizes alias records and optimizes nested aliases
|
|
85
|
+
*/
|
|
86
|
+
declare function normalizeAliases(aliases: Record<string, string>): NormalizedRecord;
|
|
87
|
+
/**
|
|
88
|
+
* resolves a path using aliases
|
|
89
|
+
*/
|
|
90
|
+
declare function resolveAlias(path: string, aliases: Record<string, string>): string;
|
|
91
|
+
/**
|
|
92
|
+
* finds all alias paths that could resolve to the given path
|
|
93
|
+
*/
|
|
94
|
+
declare function reverseResolveAlias(path: string, aliases: Record<string, string>): string[];
|
|
95
|
+
/**
|
|
96
|
+
* converts aliased path to relative path
|
|
97
|
+
*/
|
|
98
|
+
declare function convertStringAliasRelative({ importPath, importerFile, pathPattern, targetDir, }: {
|
|
99
|
+
importPath: string;
|
|
100
|
+
importerFile: string;
|
|
101
|
+
pathPattern: string;
|
|
102
|
+
targetDir: string;
|
|
103
|
+
}): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* main function to convert import paths from aliases to relative paths
|
|
106
|
+
*/
|
|
107
|
+
declare function convertImportsAliasToRelative({ targetDir, aliasToReplace, // e.g. @, ~, @/*, ~/*
|
|
108
|
+
pathExtFilter, }: {
|
|
109
|
+
targetDir: string;
|
|
110
|
+
aliasToReplace: string;
|
|
111
|
+
pathExtFilter: PathExtFilter;
|
|
112
|
+
}): Promise<{
|
|
113
|
+
file: string;
|
|
114
|
+
changes: {
|
|
115
|
+
from: string;
|
|
116
|
+
to: string;
|
|
117
|
+
}[];
|
|
118
|
+
}[]>;
|
|
119
|
+
/**
|
|
120
|
+
* converts extensions in import paths from one format to another
|
|
121
|
+
*/
|
|
122
|
+
declare function convertImportsExt({ targetDir, extFrom, extTo, }: {
|
|
123
|
+
targetDir: string;
|
|
124
|
+
extFrom: ImportExtType;
|
|
125
|
+
extTo: ImportExtType;
|
|
126
|
+
}): Promise<{
|
|
127
|
+
file: string;
|
|
128
|
+
changes: {
|
|
129
|
+
from: string;
|
|
130
|
+
to: string;
|
|
131
|
+
}[];
|
|
132
|
+
}[]>;
|
|
133
|
+
declare const _pathBase: {
|
|
134
|
+
sep: string;
|
|
135
|
+
normalize: (path: string) => string;
|
|
136
|
+
join: (...segments: string[]) => string;
|
|
137
|
+
resolve: (...args: string[]) => string;
|
|
138
|
+
isAbsolute: (p: string) => boolean;
|
|
139
|
+
dirname: (p: string) => string;
|
|
140
|
+
basename: (p: string, ext?: string) => string;
|
|
141
|
+
extname: (p: string) => string;
|
|
142
|
+
format: (p: FormatInputPathObject) => string;
|
|
143
|
+
parse: (p: string) => ParsedPath;
|
|
144
|
+
toNamespacedPath: (p: string) => string;
|
|
145
|
+
relative: (from: string, to: string) => string;
|
|
146
|
+
filename: typeof filename;
|
|
19
147
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
readonly resolve: (...paths: string[]) => string;
|
|
38
|
-
readonly resolveAlias: typeof resolveAlias;
|
|
39
|
-
readonly reverseResolveAlias: typeof reverseResolveAlias;
|
|
40
|
-
readonly sep: "/";
|
|
41
|
-
readonly toNamespacedPath: (path: string) => string;
|
|
42
|
-
readonly win32: PlatformPath;
|
|
148
|
+
declare const path: PlatformPath & {
|
|
149
|
+
sep: string;
|
|
150
|
+
normalize: (path: string) => string;
|
|
151
|
+
join: (...segments: string[]) => string;
|
|
152
|
+
resolve: (...args: string[]) => string;
|
|
153
|
+
isAbsolute: (p: string) => boolean;
|
|
154
|
+
dirname: (p: string) => string;
|
|
155
|
+
basename: (p: string, ext?: string) => string;
|
|
156
|
+
extname: (p: string) => string;
|
|
157
|
+
format: (p: FormatInputPathObject) => string;
|
|
158
|
+
parse: (p: string) => ParsedPath;
|
|
159
|
+
toNamespacedPath: (p: string) => string;
|
|
160
|
+
relative: (from: string, to: string) => string;
|
|
161
|
+
filename: typeof filename;
|
|
162
|
+
} & {
|
|
163
|
+
posix: PlatformPath;
|
|
164
|
+
win32: PlatformPath;
|
|
43
165
|
};
|
|
44
|
-
|
|
166
|
+
declare const win32: PlatformPath;
|
|
167
|
+
declare const delimiter: string;
|
|
168
|
+
export type { PlatformPath, PathExtFilter, ImportExtType };
|
|
169
|
+
export { _pathBase as posix, win32, basename, delimiter, dirname, extname, filename, format, isAbsolute, join, normalize, parse, relative, resolve, sep, toNamespacedPath, normalizeAliases, resolveAlias, reverseResolveAlias, normalizeWindowsPath, cleanDirs, copyDir, convertStringAliasRelative, convertImportsAliasToRelative, convertImportsExt, };
|
|
170
|
+
export default path;
|