@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/package.json
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"dependencies": {},
|
|
3
|
+
"description": "@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
|
+
"homepage": "https://docs.reliverse.org",
|
|
3
5
|
"license": "MIT",
|
|
4
6
|
"name": "@reliverse/pathkit",
|
|
5
7
|
"type": "module",
|
|
6
|
-
"version": "1.0
|
|
7
|
-
"
|
|
8
|
-
|
|
8
|
+
"version": "1.1.0",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@biomejs/biome": "1.9.4",
|
|
11
|
+
"@eslint/js": "^9.27.0",
|
|
12
|
+
"@reliverse/dler": "^1.3.6",
|
|
13
|
+
"@reliverse/relifso": "^1.2.10",
|
|
14
|
+
"@reliverse/relinka": "^1.4.5",
|
|
15
|
+
"@reliverse/rematch": "^1.1.0",
|
|
16
|
+
"@stylistic/eslint-plugin": "^4.2.0",
|
|
17
|
+
"@types/bun": "^1.2.13",
|
|
18
|
+
"@types/node": "^22.15.21",
|
|
19
|
+
"eslint": "^9.27.0",
|
|
20
|
+
"eslint-plugin-no-relative-import-paths": "^1.6.1",
|
|
21
|
+
"eslint-plugin-perfectionist": "^4.13.0",
|
|
22
|
+
"knip": "^5.57.0",
|
|
23
|
+
"magic-string": "^0.30.17",
|
|
24
|
+
"p-map": "^7.0.3",
|
|
25
|
+
"typescript": "^5.8.3",
|
|
26
|
+
"typescript-eslint": "^8.32.1"
|
|
27
|
+
},
|
|
9
28
|
"exports": {
|
|
10
29
|
".": "./bin/mod.js"
|
|
11
30
|
},
|
package/bin/delete-me.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const deleteMe = "delete-me";
|
package/bin/delete-me.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const deleteMe = "delete-me";
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from "./internal/path.js";
|
|
2
|
-
/**
|
|
3
|
-
* The platform-specific file delimiter.
|
|
4
|
-
*
|
|
5
|
-
* Equals to `";"` in windows and `":"` in all other platforms.
|
|
6
|
-
*/
|
|
7
|
-
export declare const delimiter: ";" | ":";
|
|
8
|
-
export declare const posix: import("path").PlatformPath;
|
|
9
|
-
export declare const win32: import("path").PlatformPath;
|
package/bin/pathkit-impl/impl.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as _path from "./internal/path.js";
|
|
2
|
-
export * from "./internal/path.js";
|
|
3
|
-
export const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
|
|
4
|
-
const _platforms = { posix: void 0, win32: void 0 };
|
|
5
|
-
const mix = (del = delimiter) => {
|
|
6
|
-
return new Proxy(_path, {
|
|
7
|
-
get(_, prop) {
|
|
8
|
-
if (prop === "delimiter") return del;
|
|
9
|
-
if (prop === "posix") return posix;
|
|
10
|
-
if (prop === "win32") return win32;
|
|
11
|
-
return _platforms[prop] || _path[prop];
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
export const posix = /* @__PURE__ */ mix(":");
|
|
16
|
-
export const win32 = /* @__PURE__ */ mix(";");
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type path from "node:path";
|
|
2
|
-
/**
|
|
3
|
-
* Constant for path separator.
|
|
4
|
-
*
|
|
5
|
-
* Always equals to `"/"`.
|
|
6
|
-
*/
|
|
7
|
-
export declare const sep = "/";
|
|
8
|
-
export declare const normalize: typeof path.normalize;
|
|
9
|
-
export declare const join: typeof path.join;
|
|
10
|
-
export declare const resolve: typeof path.resolve;
|
|
11
|
-
/**
|
|
12
|
-
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
13
|
-
*
|
|
14
|
-
* @param path - The path to normalise.
|
|
15
|
-
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
16
|
-
* @returns the normalised path string.
|
|
17
|
-
*/
|
|
18
|
-
export declare function normalizeString(path: string, allowAboveRoot: boolean): string;
|
|
19
|
-
export declare const isAbsolute: typeof path.isAbsolute;
|
|
20
|
-
export declare const toNamespacedPath: typeof path.toNamespacedPath;
|
|
21
|
-
export declare const extname: typeof path.extname;
|
|
22
|
-
export declare const relative: typeof path.relative;
|
|
23
|
-
export declare const dirname: typeof path.dirname;
|
|
24
|
-
export declare const format: typeof path.format;
|
|
25
|
-
export declare const basename: typeof path.basename;
|
|
26
|
-
export declare const parse: typeof path.parse;
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { deleteMe } from "../../delete-me.js";
|
|
2
|
-
import { normalizeWindowsPath } from "./win.js";
|
|
3
|
-
const _UNC_REGEX = /^[/\\]{2}/;
|
|
4
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
5
|
-
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
6
|
-
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
7
|
-
const _EXTNAME_RE = /.(\.[^./]+|\.)$/;
|
|
8
|
-
const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
|
|
9
|
-
export const sep = "/";
|
|
10
|
-
export const normalize = (path) => {
|
|
11
|
-
if (path.length === 0) {
|
|
12
|
-
return ".";
|
|
13
|
-
}
|
|
14
|
-
path = normalizeWindowsPath(path);
|
|
15
|
-
const isUNCPath = _UNC_REGEX.exec(path);
|
|
16
|
-
const isPathAbsolute = isAbsolute(path);
|
|
17
|
-
const trailingSeparator = path.endsWith("/");
|
|
18
|
-
path = normalizeString(path, !isPathAbsolute);
|
|
19
|
-
if (path.length === 0) {
|
|
20
|
-
if (isPathAbsolute) {
|
|
21
|
-
return "/";
|
|
22
|
-
}
|
|
23
|
-
return trailingSeparator ? "./" : ".";
|
|
24
|
-
}
|
|
25
|
-
if (trailingSeparator) {
|
|
26
|
-
path += "/";
|
|
27
|
-
}
|
|
28
|
-
if (_DRIVE_LETTER_RE.test(path)) {
|
|
29
|
-
path += "/";
|
|
30
|
-
}
|
|
31
|
-
if (isUNCPath) {
|
|
32
|
-
if (!isPathAbsolute) {
|
|
33
|
-
return `//./${path}`;
|
|
34
|
-
}
|
|
35
|
-
return `//${path}`;
|
|
36
|
-
}
|
|
37
|
-
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
38
|
-
};
|
|
39
|
-
export const join = (...segments) => {
|
|
40
|
-
let path = "";
|
|
41
|
-
for (const seg of segments) {
|
|
42
|
-
if (!seg) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (path.length > 0) {
|
|
46
|
-
const pathTrailing = path.endsWith("/");
|
|
47
|
-
const segLeading = seg.startsWith("/");
|
|
48
|
-
const both = pathTrailing && segLeading;
|
|
49
|
-
if (both) {
|
|
50
|
-
path += seg.slice(1);
|
|
51
|
-
} else {
|
|
52
|
-
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
path += seg;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return normalize(path);
|
|
59
|
-
};
|
|
60
|
-
function cwd() {
|
|
61
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
62
|
-
return process.cwd().replace(/\\/g, "/");
|
|
63
|
-
}
|
|
64
|
-
return "/";
|
|
65
|
-
}
|
|
66
|
-
export const resolve = (...arguments_) => {
|
|
67
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
68
|
-
let resolvedPath = "";
|
|
69
|
-
let resolvedAbsolute = false;
|
|
70
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
71
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
72
|
-
if (!path || path.length === 0) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
76
|
-
resolvedAbsolute = isAbsolute(path);
|
|
77
|
-
}
|
|
78
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
79
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
80
|
-
return `/${resolvedPath}`;
|
|
81
|
-
}
|
|
82
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
83
|
-
};
|
|
84
|
-
export function normalizeString(path, allowAboveRoot) {
|
|
85
|
-
let res = "";
|
|
86
|
-
let lastSegmentLength = 0;
|
|
87
|
-
let lastSlash = -1;
|
|
88
|
-
let dots = 0;
|
|
89
|
-
let char = null;
|
|
90
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
91
|
-
if (index < path.length) {
|
|
92
|
-
char = path[index];
|
|
93
|
-
} else if (char === "/") {
|
|
94
|
-
break;
|
|
95
|
-
} else {
|
|
96
|
-
char = "/";
|
|
97
|
-
}
|
|
98
|
-
if (char === "/") {
|
|
99
|
-
if (lastSlash === index - 1 || dots === 1) {
|
|
100
|
-
} else if (dots === 2) {
|
|
101
|
-
if (res.length < 2 || lastSegmentLength !== 2 || !res.endsWith(".") || res[res.length - 2] !== ".") {
|
|
102
|
-
if (res.length > 2) {
|
|
103
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
104
|
-
if (lastSlashIndex === -1) {
|
|
105
|
-
res = "";
|
|
106
|
-
lastSegmentLength = 0;
|
|
107
|
-
} else {
|
|
108
|
-
res = res.slice(0, lastSlashIndex);
|
|
109
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
110
|
-
}
|
|
111
|
-
lastSlash = index;
|
|
112
|
-
dots = 0;
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (res.length > 0) {
|
|
116
|
-
res = "";
|
|
117
|
-
lastSegmentLength = 0;
|
|
118
|
-
lastSlash = index;
|
|
119
|
-
dots = 0;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (allowAboveRoot) {
|
|
124
|
-
res += res.length > 0 ? "/.." : "..";
|
|
125
|
-
lastSegmentLength = 2;
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
if (res.length > 0) {
|
|
129
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
130
|
-
} else {
|
|
131
|
-
res = path.slice(lastSlash + 1, index);
|
|
132
|
-
}
|
|
133
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
134
|
-
}
|
|
135
|
-
lastSlash = index;
|
|
136
|
-
dots = 0;
|
|
137
|
-
} else if (char === "." && dots !== -1) {
|
|
138
|
-
++dots;
|
|
139
|
-
} else {
|
|
140
|
-
dots = -1;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return res;
|
|
144
|
-
}
|
|
145
|
-
export const isAbsolute = (p) => _IS_ABSOLUTE_RE.test(p);
|
|
146
|
-
export const toNamespacedPath = (p) => normalizeWindowsPath(p);
|
|
147
|
-
export const extname = (p) => {
|
|
148
|
-
if (p === "..") return "";
|
|
149
|
-
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
150
|
-
return match?.[1] || "";
|
|
151
|
-
};
|
|
152
|
-
export const relative = (from, to) => {
|
|
153
|
-
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
154
|
-
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
155
|
-
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
|
|
156
|
-
return _to.join("/");
|
|
157
|
-
}
|
|
158
|
-
const _fromCopy = [..._from];
|
|
159
|
-
for (const segment of _fromCopy) {
|
|
160
|
-
if (_to[0] !== segment) {
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
_from.shift();
|
|
164
|
-
_to.shift();
|
|
165
|
-
}
|
|
166
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
167
|
-
};
|
|
168
|
-
export const dirname = (p) => {
|
|
169
|
-
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
170
|
-
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
|
|
171
|
-
segments[0] += "/";
|
|
172
|
-
}
|
|
173
|
-
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
174
|
-
};
|
|
175
|
-
export const format = (p) => {
|
|
176
|
-
const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
|
|
177
|
-
const segments = [p.root, p.dir, p.base ?? (p.name ?? "") + ext].filter(
|
|
178
|
-
Boolean
|
|
179
|
-
);
|
|
180
|
-
return normalizeWindowsPath(
|
|
181
|
-
segments.length > 0 ? resolve(...segments) : segments.join("/")
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
export const basename = (p, extension) => {
|
|
185
|
-
const segments = normalizeWindowsPath(p).split("/");
|
|
186
|
-
let lastSegment = "";
|
|
187
|
-
for (let i = segments.length - 1; i >= 0; i--) {
|
|
188
|
-
const val = segments[i];
|
|
189
|
-
if (val) {
|
|
190
|
-
lastSegment = val;
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
195
|
-
};
|
|
196
|
-
export const parse = (p) => {
|
|
197
|
-
const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
|
|
198
|
-
const base = basename(p);
|
|
199
|
-
const extension = extname(base);
|
|
200
|
-
return {
|
|
201
|
-
root,
|
|
202
|
-
dir: dirname(p),
|
|
203
|
-
base,
|
|
204
|
-
ext: extension,
|
|
205
|
-
name: base.slice(0, base.length - extension.length)
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
console.log("deleteMe", deleteMe);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function normalizeWindowsPath(input?: string): string;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalises alias mappings, ensuring that more specific aliases are resolved before less specific ones.
|
|
3
|
-
* This function also ensures that aliases do not resolve to themselves cyclically.
|
|
4
|
-
*
|
|
5
|
-
* @param _aliases - A set of alias mappings where each key is an alias and its value is the actual path it points to.
|
|
6
|
-
* @returns a set of normalised alias mappings.
|
|
7
|
-
*/
|
|
8
|
-
export declare function normalizeAliases(_aliases: Record<string, string>): Record<string, string>;
|
|
9
|
-
/**
|
|
10
|
-
* Resolves a path string to its alias if applicable, otherwise returns the original path.
|
|
11
|
-
* This function normalises the path, resolves the alias and then joins it to the alias target if necessary.
|
|
12
|
-
*
|
|
13
|
-
* @param path - The path string to resolve.
|
|
14
|
-
* @param aliases - A set of alias mappings to use for resolution.
|
|
15
|
-
* @returns the resolved path as a string.
|
|
16
|
-
*/
|
|
17
|
-
export declare function resolveAlias(path: string, aliases: Record<string, string>): any;
|
|
18
|
-
/**
|
|
19
|
-
* Resolves a path string to its possible alias.
|
|
20
|
-
*
|
|
21
|
-
* Returns an array of possible alias resolutions (could be empty), sorted by specificity (longest first).
|
|
22
|
-
*/
|
|
23
|
-
export declare function reverseResolveAlias(path: string, aliases: Record<string, string>): string[];
|
|
24
|
-
/**
|
|
25
|
-
* Extracts the filename from a given path, excluding any directory paths and the file extension.
|
|
26
|
-
*
|
|
27
|
-
* @param path - The full path of the file from which to extract the filename.
|
|
28
|
-
* @returns the filename without the extension, or `undefined` if the filename cannot be extracted.
|
|
29
|
-
*/
|
|
30
|
-
export declare function filename(path: string): string | undefined;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { join } from "./internal/path.js";
|
|
2
|
-
import { normalizeWindowsPath } from "./internal/win.js";
|
|
3
|
-
const pathSeparators = /* @__PURE__ */ new Set(["/", "\\", void 0]);
|
|
4
|
-
const normalizedAliasSymbol = Symbol.for("pathkit:normalizedAlias");
|
|
5
|
-
const SLASH_RE = /[/\\]/;
|
|
6
|
-
export function normalizeAliases(_aliases) {
|
|
7
|
-
if (_aliases[normalizedAliasSymbol]) {
|
|
8
|
-
return _aliases;
|
|
9
|
-
}
|
|
10
|
-
const aliases = Object.fromEntries(
|
|
11
|
-
Object.entries(_aliases).sort(([a], [b]) => _compareAliases(a, b))
|
|
12
|
-
);
|
|
13
|
-
for (const key in aliases) {
|
|
14
|
-
for (const alias in aliases) {
|
|
15
|
-
if (alias === key || key.startsWith(alias)) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (aliases[key]?.startsWith(alias) && pathSeparators.has(aliases[key][alias.length])) {
|
|
19
|
-
aliases[key] = aliases[alias] + aliases[key].slice(alias.length);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(aliases, normalizedAliasSymbol, {
|
|
24
|
-
value: true,
|
|
25
|
-
enumerable: false
|
|
26
|
-
});
|
|
27
|
-
return aliases;
|
|
28
|
-
}
|
|
29
|
-
export function resolveAlias(path, aliases) {
|
|
30
|
-
const _path = normalizeWindowsPath(path);
|
|
31
|
-
aliases = normalizeAliases(aliases);
|
|
32
|
-
for (const [alias, to] of Object.entries(aliases)) {
|
|
33
|
-
if (!_path.startsWith(alias)) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;
|
|
37
|
-
if (hasTrailingSlash(_path[_alias.length])) {
|
|
38
|
-
return join(to, _path.slice(alias.length));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return _path;
|
|
42
|
-
}
|
|
43
|
-
export function reverseResolveAlias(path, aliases) {
|
|
44
|
-
const _path = normalizeWindowsPath(path);
|
|
45
|
-
aliases = normalizeAliases(aliases);
|
|
46
|
-
const matches = [];
|
|
47
|
-
for (const [to, alias] of Object.entries(aliases)) {
|
|
48
|
-
if (!_path.startsWith(alias)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;
|
|
52
|
-
if (hasTrailingSlash(_path[_alias.length])) {
|
|
53
|
-
matches.push(join(to, _path.slice(alias.length)));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return matches.sort((a, b) => b.length - a.length);
|
|
57
|
-
}
|
|
58
|
-
export function filename(path) {
|
|
59
|
-
const base = path.split(SLASH_RE).pop();
|
|
60
|
-
if (!base) {
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
63
|
-
const separatorIndex = base.lastIndexOf(".");
|
|
64
|
-
if (separatorIndex <= 0) {
|
|
65
|
-
return base;
|
|
66
|
-
}
|
|
67
|
-
return base.slice(0, separatorIndex);
|
|
68
|
-
}
|
|
69
|
-
function _compareAliases(a, b) {
|
|
70
|
-
return b.split("/").length - a.split("/").length;
|
|
71
|
-
}
|
|
72
|
-
function hasTrailingSlash(path = "/") {
|
|
73
|
-
const lastChar = path[path.length - 1];
|
|
74
|
-
return lastChar === "/" || lastChar === "\\";
|
|
75
|
-
}
|