@guanghechen/path 1.0.0-alpha.5 → 1.0.0-alpha.7
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/CHANGELOG.md +22 -0
- package/lib/cjs/index.cjs +18 -32
- package/lib/esm/index.mjs +15 -27
- package/lib/types/index.d.ts +15 -23
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-alpha.7](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.6...@guanghechen/path@1.0.0-alpha.7) (2023-10-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Performance Improvements
|
|
10
|
+
|
|
11
|
+
* 🎨 support 'preferSlash' option for 'relativexx' funcs ([e59d415](https://github.com/guanghechen/sora/commit/e59d415df8272f6a5b8afed1f57152e4b44c89b8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [1.0.0-alpha.6](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.5...@guanghechen/path@1.0.0-alpha.6) (2023-10-16)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Performance Improvements
|
|
21
|
+
|
|
22
|
+
* :art: refactor @guanghechen/path ([8952da3](https://github.com/guanghechen/sora/commit/8952da3154a042a10e76b356da7461a1f8ad8582))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
# [1.0.0-alpha.5](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.4...@guanghechen/path@1.0.0-alpha.5) (2023-10-16)
|
|
7
29
|
|
|
8
30
|
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -9,8 +9,8 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
9
9
|
|
|
10
10
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
11
11
|
|
|
12
|
-
const clazz$1 = '
|
|
13
|
-
class
|
|
12
|
+
const clazz$1 = 'PathResolver';
|
|
13
|
+
class PathResolver {
|
|
14
14
|
basename(filepath) {
|
|
15
15
|
this.ensureAbsolute(filepath);
|
|
16
16
|
const p = this.normalize(filepath);
|
|
@@ -54,14 +54,16 @@ class PhysicalPathResolver {
|
|
|
54
54
|
this.ensureAbsolute(filepath);
|
|
55
55
|
return this._internalNormalize(filepath);
|
|
56
56
|
}
|
|
57
|
-
relative(from, to) {
|
|
57
|
+
relative(from, to, preferSlash = false) {
|
|
58
58
|
this.ensureAbsolute(from, `[${clazz$1}.relative] from is not an absolute path: ${from}`);
|
|
59
59
|
this.ensureAbsolute(to, `[${clazz$1}.relative] to is not an absolute path: ${to}`);
|
|
60
|
-
|
|
60
|
+
const relativePath = this._internalRelative(from, to);
|
|
61
|
+
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
|
61
62
|
}
|
|
62
|
-
safeRelative(root, filepath) {
|
|
63
|
+
safeRelative(root, filepath, preferSlash = false) {
|
|
63
64
|
this.ensureSafeRelative(root, filepath);
|
|
64
|
-
|
|
65
|
+
const relativePath = this._internalSafeRelative(root, filepath);
|
|
66
|
+
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
|
65
67
|
}
|
|
66
68
|
safeResolve(root, filepath) {
|
|
67
69
|
this.ensureSafeRelative(root, filepath);
|
|
@@ -92,8 +94,8 @@ class PhysicalPathResolver {
|
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
const clazz = '
|
|
96
|
-
class
|
|
97
|
+
const clazz = 'UrlPathResolver';
|
|
98
|
+
class UrlPathResolver {
|
|
97
99
|
basename(filepath) {
|
|
98
100
|
this.ensureAbsolute(filepath);
|
|
99
101
|
const p = this.normalize(filepath);
|
|
@@ -240,9 +242,9 @@ class WorkspacePathResolver {
|
|
|
240
242
|
const { root, pathResolver } = this;
|
|
241
243
|
return pathResolver.isSafeRelative(root, filepath);
|
|
242
244
|
}
|
|
243
|
-
relative(filepath) {
|
|
245
|
+
relative(filepath, preferSlash) {
|
|
244
246
|
const { root, pathResolver } = this;
|
|
245
|
-
return pathResolver.safeRelative(root, filepath);
|
|
247
|
+
return pathResolver.safeRelative(root, filepath, preferSlash);
|
|
246
248
|
}
|
|
247
249
|
resolve(filepath) {
|
|
248
250
|
const { root, pathResolver } = this;
|
|
@@ -250,32 +252,16 @@ class WorkspacePathResolver {
|
|
|
250
252
|
}
|
|
251
253
|
}
|
|
252
254
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const pathResolver = new PhysicalPathResolver();
|
|
256
|
-
super(root, pathResolver);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
class VirtualWorkspacePathResolver extends WorkspacePathResolver {
|
|
261
|
-
constructor(root) {
|
|
262
|
-
const pathResolver = new VirtualPathResolver();
|
|
263
|
-
super(root, pathResolver);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const physicalPathResolver = new PhysicalPathResolver();
|
|
268
|
-
const virtualPathResolver = new VirtualPathResolver();
|
|
255
|
+
const pathResolver = new PathResolver();
|
|
256
|
+
const urlPathResolver = new UrlPathResolver();
|
|
269
257
|
|
|
270
|
-
exports.
|
|
271
|
-
exports.
|
|
272
|
-
exports.VirtualPathResolver = VirtualPathResolver;
|
|
273
|
-
exports.VirtualWorkspacePathResolver = VirtualWorkspacePathResolver;
|
|
258
|
+
exports.PathResolver = PathResolver;
|
|
259
|
+
exports.UrlPathResolver = UrlPathResolver;
|
|
274
260
|
exports.WorkspacePathResolver = WorkspacePathResolver;
|
|
275
261
|
exports.findNearestFilepath = findNearestFilepath;
|
|
276
262
|
exports.locateNearestFilepath = locateNearestFilepath;
|
|
277
|
-
exports.
|
|
278
|
-
exports.
|
|
263
|
+
exports.pathResolver = pathResolver;
|
|
264
|
+
exports.urlPathResolver = urlPathResolver;
|
|
279
265
|
Object.keys(path_types).forEach(function (k) {
|
|
280
266
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
281
267
|
enumerable: true,
|
package/lib/esm/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { existsSync, readdirSync } from 'node:fs';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
export * from '@guanghechen/path.types';
|
|
5
5
|
|
|
6
|
-
const clazz$1 = '
|
|
7
|
-
class
|
|
6
|
+
const clazz$1 = 'PathResolver';
|
|
7
|
+
class PathResolver {
|
|
8
8
|
basename(filepath) {
|
|
9
9
|
this.ensureAbsolute(filepath);
|
|
10
10
|
const p = this.normalize(filepath);
|
|
@@ -48,14 +48,16 @@ class PhysicalPathResolver {
|
|
|
48
48
|
this.ensureAbsolute(filepath);
|
|
49
49
|
return this._internalNormalize(filepath);
|
|
50
50
|
}
|
|
51
|
-
relative(from, to) {
|
|
51
|
+
relative(from, to, preferSlash = false) {
|
|
52
52
|
this.ensureAbsolute(from, `[${clazz$1}.relative] from is not an absolute path: ${from}`);
|
|
53
53
|
this.ensureAbsolute(to, `[${clazz$1}.relative] to is not an absolute path: ${to}`);
|
|
54
|
-
|
|
54
|
+
const relativePath = this._internalRelative(from, to);
|
|
55
|
+
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
|
55
56
|
}
|
|
56
|
-
safeRelative(root, filepath) {
|
|
57
|
+
safeRelative(root, filepath, preferSlash = false) {
|
|
57
58
|
this.ensureSafeRelative(root, filepath);
|
|
58
|
-
|
|
59
|
+
const relativePath = this._internalSafeRelative(root, filepath);
|
|
60
|
+
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
|
59
61
|
}
|
|
60
62
|
safeResolve(root, filepath) {
|
|
61
63
|
this.ensureSafeRelative(root, filepath);
|
|
@@ -86,8 +88,8 @@ class PhysicalPathResolver {
|
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
const clazz = '
|
|
90
|
-
class
|
|
91
|
+
const clazz = 'UrlPathResolver';
|
|
92
|
+
class UrlPathResolver {
|
|
91
93
|
basename(filepath) {
|
|
92
94
|
this.ensureAbsolute(filepath);
|
|
93
95
|
const p = this.normalize(filepath);
|
|
@@ -234,9 +236,9 @@ class WorkspacePathResolver {
|
|
|
234
236
|
const { root, pathResolver } = this;
|
|
235
237
|
return pathResolver.isSafeRelative(root, filepath);
|
|
236
238
|
}
|
|
237
|
-
relative(filepath) {
|
|
239
|
+
relative(filepath, preferSlash) {
|
|
238
240
|
const { root, pathResolver } = this;
|
|
239
|
-
return pathResolver.safeRelative(root, filepath);
|
|
241
|
+
return pathResolver.safeRelative(root, filepath, preferSlash);
|
|
240
242
|
}
|
|
241
243
|
resolve(filepath) {
|
|
242
244
|
const { root, pathResolver } = this;
|
|
@@ -244,21 +246,7 @@ class WorkspacePathResolver {
|
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const pathResolver = new PhysicalPathResolver();
|
|
250
|
-
super(root, pathResolver);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
class VirtualWorkspacePathResolver extends WorkspacePathResolver {
|
|
255
|
-
constructor(root) {
|
|
256
|
-
const pathResolver = new VirtualPathResolver();
|
|
257
|
-
super(root, pathResolver);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const physicalPathResolver = new PhysicalPathResolver();
|
|
262
|
-
const virtualPathResolver = new VirtualPathResolver();
|
|
249
|
+
const pathResolver = new PathResolver();
|
|
250
|
+
const urlPathResolver = new UrlPathResolver();
|
|
263
251
|
|
|
264
|
-
export {
|
|
252
|
+
export { PathResolver, UrlPathResolver, WorkspacePathResolver, findNearestFilepath, locateNearestFilepath, pathResolver, urlPathResolver };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare function locateNearestFilepath(currentDir: string, filenames: string | R
|
|
|
18
18
|
*/
|
|
19
19
|
declare function findNearestFilepath(currentDir: string, predicate: (filepath: string) => boolean): string | null;
|
|
20
20
|
|
|
21
|
-
declare class
|
|
21
|
+
declare class PathResolver implements IPathResolver {
|
|
22
22
|
basename(filepath: string): string;
|
|
23
23
|
ensureAbsolute(filepath: string, message?: string | undefined): void | never;
|
|
24
24
|
ensureSafeRelative(root: string, filepath: string, message?: string | undefined): void | never;
|
|
@@ -27,8 +27,8 @@ declare class PhysicalPathResolver implements IPathResolver {
|
|
|
27
27
|
isSafeRelative(root: string, filepath: string): boolean;
|
|
28
28
|
join(filepath: string, ...pathPieces: string[]): string | never;
|
|
29
29
|
normalize(filepath: string): string | never;
|
|
30
|
-
relative(from: string, to: string): string | never;
|
|
31
|
-
safeRelative(root: string, filepath: string): string;
|
|
30
|
+
relative(from: string, to: string, preferSlash?: boolean): string | never;
|
|
31
|
+
safeRelative(root: string, filepath: string, preferSlash?: boolean): string;
|
|
32
32
|
safeResolve(root: string, filepath: string): string;
|
|
33
33
|
protected _internalNormalize(filepath: string): string;
|
|
34
34
|
protected _internalRelative(from_: string, to_: string): string;
|
|
@@ -36,21 +36,7 @@ declare class PhysicalPathResolver implements IPathResolver {
|
|
|
36
36
|
protected _internalSafeResolve(root: string, filepath_: string): string;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
declare class
|
|
40
|
-
readonly root: string;
|
|
41
|
-
readonly pathResolver: IPathResolver;
|
|
42
|
-
constructor(root: string, pathResolver: IPathResolver);
|
|
43
|
-
ensureSafePath(filepath: string, message?: string | undefined): void | never;
|
|
44
|
-
isSafePath(filepath: string): boolean;
|
|
45
|
-
relative(filepath: string): string | never;
|
|
46
|
-
resolve(filepath: string): string | never;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
declare class PhysicalWorkspacePathResolver extends WorkspacePathResolver implements IWorkspacePathResolver {
|
|
50
|
-
constructor(root: string);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
declare class VirtualPathResolver implements IPathResolver {
|
|
39
|
+
declare class UrlPathResolver implements IPathResolver {
|
|
54
40
|
basename(filepath: string): string;
|
|
55
41
|
ensureAbsolute(filepath: string, message?: string | undefined): void | never;
|
|
56
42
|
ensureSafeRelative(root: string, filepath: string, message?: string | undefined): void;
|
|
@@ -69,11 +55,17 @@ declare class VirtualPathResolver implements IPathResolver {
|
|
|
69
55
|
protected _internalSafeResolve(root: string, filepath_: string): string;
|
|
70
56
|
}
|
|
71
57
|
|
|
72
|
-
declare class
|
|
73
|
-
|
|
58
|
+
declare class WorkspacePathResolver implements IWorkspacePathResolver {
|
|
59
|
+
readonly root: string;
|
|
60
|
+
readonly pathResolver: IPathResolver;
|
|
61
|
+
constructor(root: string, pathResolver: IPathResolver);
|
|
62
|
+
ensureSafePath(filepath: string, message?: string | undefined): void | never;
|
|
63
|
+
isSafePath(filepath: string): boolean;
|
|
64
|
+
relative(filepath: string, preferSlash?: boolean): string | never;
|
|
65
|
+
resolve(filepath: string): string | never;
|
|
74
66
|
}
|
|
75
67
|
|
|
76
|
-
declare const
|
|
77
|
-
declare const
|
|
68
|
+
declare const pathResolver: IPathResolver;
|
|
69
|
+
declare const urlPathResolver: IPathResolver;
|
|
78
70
|
|
|
79
|
-
export {
|
|
71
|
+
export { PathResolver, UrlPathResolver, WorkspacePathResolver, findNearestFilepath, locateNearestFilepath, pathResolver, urlPathResolver };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guanghechen/path",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
4
|
"description": "Path utils.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.
|
|
11
|
+
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.6",
|
|
12
12
|
"directory": "packages/path"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.
|
|
14
|
+
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.6/packages/path#readme",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir ."
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@guanghechen/path.types": "^1.0.0-alpha.
|
|
46
|
+
"@guanghechen/path.types": "^1.0.0-alpha.5"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "38989b3735fe6981d74cadb63568657247b77e14"
|
|
49
49
|
}
|