@guanghechen/path 1.0.0-alpha.13 → 1.0.0-alpha.15
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 +19 -0
- package/lib/cjs/index.cjs +8 -2
- package/lib/esm/index.mjs +8 -2
- package/lib/types/index.d.ts +5 -3
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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.15](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.14...@guanghechen/path@1.0.0-alpha.15) (2024-01-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Performance Improvements
|
|
10
|
+
|
|
11
|
+
* 🎨 support preferSlash option ([cf67725](https://github.com/guanghechen/sora/commit/cf67725983902912d31033bdd652ea8dbb36dd3b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [1.0.0-alpha.14](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.13...@guanghechen/path@1.0.0-alpha.14) (2023-12-04)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @guanghechen/path
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# [1.0.0-alpha.13](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.12...@guanghechen/path@1.0.0-alpha.13) (2023-12-02)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @guanghechen/path
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -11,6 +11,10 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
11
11
|
|
|
12
12
|
const clazz$1 = 'PathResolver';
|
|
13
13
|
class PathResolver {
|
|
14
|
+
defaultPreferSlash;
|
|
15
|
+
constructor(params = {}) {
|
|
16
|
+
this.defaultPreferSlash = params.preferSlash ?? false;
|
|
17
|
+
}
|
|
14
18
|
basename(filepath) {
|
|
15
19
|
this.ensureAbsolute(filepath);
|
|
16
20
|
const p = this.normalize(filepath);
|
|
@@ -54,13 +58,15 @@ class PathResolver {
|
|
|
54
58
|
this.ensureAbsolute(filepath);
|
|
55
59
|
return this._internalNormalize(filepath);
|
|
56
60
|
}
|
|
57
|
-
relative(from, to,
|
|
61
|
+
relative(from, to, preferSlash_) {
|
|
62
|
+
const preferSlash = preferSlash_ ?? this.defaultPreferSlash;
|
|
58
63
|
this.ensureAbsolute(from, `[${clazz$1}.relative] from is not an absolute path: ${from}`);
|
|
59
64
|
this.ensureAbsolute(to, `[${clazz$1}.relative] to is not an absolute path: ${to}`);
|
|
60
65
|
const relativePath = this._internalRelative(from, to);
|
|
61
66
|
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
|
62
67
|
}
|
|
63
|
-
safeRelative(root, filepath,
|
|
68
|
+
safeRelative(root, filepath, preferSlash_) {
|
|
69
|
+
const preferSlash = preferSlash_ ?? this.defaultPreferSlash;
|
|
64
70
|
this.ensureSafeRelative(root, filepath);
|
|
65
71
|
const relativePath = this._internalSafeRelative(root, filepath);
|
|
66
72
|
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
package/lib/esm/index.mjs
CHANGED
|
@@ -5,6 +5,10 @@ export * from '@guanghechen/path.types';
|
|
|
5
5
|
|
|
6
6
|
const clazz$1 = 'PathResolver';
|
|
7
7
|
class PathResolver {
|
|
8
|
+
defaultPreferSlash;
|
|
9
|
+
constructor(params = {}) {
|
|
10
|
+
this.defaultPreferSlash = params.preferSlash ?? false;
|
|
11
|
+
}
|
|
8
12
|
basename(filepath) {
|
|
9
13
|
this.ensureAbsolute(filepath);
|
|
10
14
|
const p = this.normalize(filepath);
|
|
@@ -48,13 +52,15 @@ class PathResolver {
|
|
|
48
52
|
this.ensureAbsolute(filepath);
|
|
49
53
|
return this._internalNormalize(filepath);
|
|
50
54
|
}
|
|
51
|
-
relative(from, to,
|
|
55
|
+
relative(from, to, preferSlash_) {
|
|
56
|
+
const preferSlash = preferSlash_ ?? this.defaultPreferSlash;
|
|
52
57
|
this.ensureAbsolute(from, `[${clazz$1}.relative] from is not an absolute path: ${from}`);
|
|
53
58
|
this.ensureAbsolute(to, `[${clazz$1}.relative] to is not an absolute path: ${to}`);
|
|
54
59
|
const relativePath = this._internalRelative(from, to);
|
|
55
60
|
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
|
56
61
|
}
|
|
57
|
-
safeRelative(root, filepath,
|
|
62
|
+
safeRelative(root, filepath, preferSlash_) {
|
|
63
|
+
const preferSlash = preferSlash_ ?? this.defaultPreferSlash;
|
|
58
64
|
this.ensureSafeRelative(root, filepath);
|
|
59
65
|
const relativePath = this._internalSafeRelative(root, filepath);
|
|
60
66
|
return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IPathResolver, IWorkspacePathResolver } from '@guanghechen/path.types';
|
|
1
|
+
import { IPathResolver, IPathResolverParams, IWorkspacePathResolver } from '@guanghechen/path.types';
|
|
2
2
|
export * from '@guanghechen/path.types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -19,6 +19,8 @@ declare function locateNearestFilepath(currentDir: string, filenames: string | R
|
|
|
19
19
|
declare function findNearestFilepath(currentDir: string, predicate: (filepath: string) => boolean): string | null;
|
|
20
20
|
|
|
21
21
|
declare class PathResolver implements IPathResolver {
|
|
22
|
+
protected readonly defaultPreferSlash: boolean;
|
|
23
|
+
constructor(params?: IPathResolverParams);
|
|
22
24
|
basename(filepath: string): string;
|
|
23
25
|
ensureAbsolute(filepath: string, message?: string | undefined): void | never;
|
|
24
26
|
ensureSafeRelative(root: string, filepath: string, message?: string | undefined): void | never;
|
|
@@ -27,8 +29,8 @@ declare class PathResolver implements IPathResolver {
|
|
|
27
29
|
isSafeRelative(root: string, filepath: string): boolean;
|
|
28
30
|
join(filepath: string, ...pathPieces: string[]): string | never;
|
|
29
31
|
normalize(filepath: string): string | never;
|
|
30
|
-
relative(from: string, to: string,
|
|
31
|
-
safeRelative(root: string, filepath: string,
|
|
32
|
+
relative(from: string, to: string, preferSlash_?: boolean): string | never;
|
|
33
|
+
safeRelative(root: string, filepath: string, preferSlash_?: boolean): string;
|
|
32
34
|
safeResolve(root: string, filepath: string): string;
|
|
33
35
|
protected _internalNormalize(filepath: string): string;
|
|
34
36
|
protected _internalRelative(from_: string, to_: string): string;
|
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.15",
|
|
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.14",
|
|
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.14/packages/path#readme",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir ."
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@guanghechen/path.types": "^1.0.0-alpha.
|
|
43
|
+
"@guanghechen/path.types": "^1.0.0-alpha.12"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "655e50971a501392dd4d234953ea45b8e08e2f79"
|
|
46
46
|
}
|