@gesslar/toolkit 3.8.0 → 3.9.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/package.json +1 -1
- package/src/lib/CappedDirectoryObject.js +23 -4
- package/src/lib/DirectoryObject.js +18 -4
- package/src/lib/TempDirectoryObject.js +13 -0
- package/src/types/lib/CappedDirectoryObject.d.ts +20 -3
- package/src/types/lib/CappedDirectoryObject.d.ts.map +1 -1
- package/src/types/lib/DirectoryObject.d.ts +13 -2
- package/src/types/lib/DirectoryObject.d.ts.map +1 -1
- package/src/types/lib/TempDirectoryObject.d.ts +7 -0
- package/src/types/lib/TempDirectoryObject.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -35,13 +35,17 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
35
35
|
* (virtual root). With a parent, the path is resolved relative to the parent's
|
|
36
36
|
* cap using virtual path semantics (absolute paths treated as cap-relative).
|
|
37
37
|
*
|
|
38
|
-
* @param {string} dirPath - Directory path (becomes cap if no parent, else relative to parent's cap)
|
|
38
|
+
* @param {string} [dirPath="."] - Directory path (becomes cap if no parent, else relative to parent's cap, defaults to current directory)
|
|
39
39
|
* @param {CappedDirectoryObject?} [parent] - Optional parent capped directory
|
|
40
40
|
* @param {boolean} [temporary=false] - Whether this is a temporary directory
|
|
41
|
-
* @throws {Sass} If path is empty
|
|
42
41
|
* @throws {Sass} If parent is provided but not a CappedDirectoryObject
|
|
43
42
|
* @throws {Sass} If the resulting path would escape the cap
|
|
44
43
|
* @example
|
|
44
|
+
* // Create new capped directory at current directory
|
|
45
|
+
* const cwd = new CappedDirectoryObject()
|
|
46
|
+
* // path: process.cwd(), cap: process.cwd()
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
45
49
|
* // Create new capped directory
|
|
46
50
|
* const cache = new CappedDirectoryObject("/home/user/.cache")
|
|
47
51
|
* // path: /home/user/.cache, cap: /home/user/.cache
|
|
@@ -56,9 +60,8 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
56
60
|
* const config = new CappedDirectoryObject("/etc/config", cache)
|
|
57
61
|
* // path: /home/user/.cache/etc/config, cap: /home/user/.cache
|
|
58
62
|
*/
|
|
59
|
-
constructor(dirPath, parent=null, temporary=false) {
|
|
63
|
+
constructor(dirPath=".", parent=null, temporary=false) {
|
|
60
64
|
Valid.type(dirPath, "String")
|
|
61
|
-
Valid.assert(dirPath.length > 0, "Path must not be empty.")
|
|
62
65
|
|
|
63
66
|
// Validate parent using inheritance-aware type checking
|
|
64
67
|
if(parent !== null && !Data.isType(parent, "CappedDirectoryObject")) {
|
|
@@ -113,6 +116,22 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
113
116
|
this.#validateCapPath()
|
|
114
117
|
}
|
|
115
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Creates a CappedDirectoryObject from the current working directory.
|
|
121
|
+
* This is useful when working with pnpx or other tools where you need to
|
|
122
|
+
* cap at the project's root directory determined at runtime.
|
|
123
|
+
*
|
|
124
|
+
* @returns {CappedDirectoryObject} A CappedDirectoryObject capped at the current working directory
|
|
125
|
+
* @example
|
|
126
|
+
* // When using pnpx or similar tools
|
|
127
|
+
* const projectRoot = CappedDirectoryObject.fromCwd()
|
|
128
|
+
* const srcDir = projectRoot.getDirectory("src")
|
|
129
|
+
* // srcDir is capped at the project root
|
|
130
|
+
*/
|
|
131
|
+
static fromCwd() {
|
|
132
|
+
return new this(process.cwd())
|
|
133
|
+
}
|
|
134
|
+
|
|
116
135
|
/**
|
|
117
136
|
* Validates that the directory path is within the cap directory tree.
|
|
118
137
|
*
|
|
@@ -101,19 +101,19 @@ export default class DirectoryObject extends FS {
|
|
|
101
101
|
/**
|
|
102
102
|
* Constructs a DirectoryObject instance.
|
|
103
103
|
*
|
|
104
|
-
* @param {string? | DirectoryObject?} directory - The directory path or DirectoryObject
|
|
104
|
+
* @param {string? | DirectoryObject?} [directory="."] - The directory path or DirectoryObject (defaults to current directory)
|
|
105
105
|
* @param {boolean} [temporary] - Whether this is a temporary directory.
|
|
106
106
|
*/
|
|
107
|
-
constructor(directory=
|
|
107
|
+
constructor(directory=".", temporary=false) {
|
|
108
108
|
super()
|
|
109
109
|
|
|
110
|
-
Valid.type(directory, "String|TempDirectoryObject|DirectoryObject
|
|
110
|
+
Valid.type(directory, "String|TempDirectoryObject|DirectoryObject")
|
|
111
111
|
|
|
112
112
|
// If passed a DirectoryObject, extract its path
|
|
113
113
|
if(Data.isType(directory, "DirectoryObject") || Data.isType(directory, "TempDirectoryObject"))
|
|
114
114
|
directory = directory.path
|
|
115
115
|
|
|
116
|
-
const fixedDir = FS.fixSlashes(directory
|
|
116
|
+
const fixedDir = FS.fixSlashes(directory)
|
|
117
117
|
const resolved = path.resolve(fixedDir)
|
|
118
118
|
const url = new URL(FS.pathToUri(resolved))
|
|
119
119
|
const baseName = path.basename(resolved) || "."
|
|
@@ -133,6 +133,20 @@ export default class DirectoryObject extends FS {
|
|
|
133
133
|
Object.freeze(this.#meta)
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Creates a DirectoryObject from the current working directory.
|
|
138
|
+
* Useful when working with pnpx or other tools where the project root
|
|
139
|
+
* needs to be determined at runtime.
|
|
140
|
+
*
|
|
141
|
+
* @returns {DirectoryObject} A DirectoryObject representing the current working directory
|
|
142
|
+
* @example
|
|
143
|
+
* const projectRoot = DirectoryObject.fromCwd()
|
|
144
|
+
* console.log(projectRoot.path) // process.cwd()
|
|
145
|
+
*/
|
|
146
|
+
static fromCwd() {
|
|
147
|
+
return new this(process.cwd())
|
|
148
|
+
}
|
|
149
|
+
|
|
136
150
|
/**
|
|
137
151
|
* Returns a string representation of the DirectoryObject.
|
|
138
152
|
*
|
|
@@ -130,6 +130,19 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* TempDirectoryObject does not support fromCwd() since it is specifically
|
|
135
|
+
* designed to work within the OS temporary directory tree.
|
|
136
|
+
*
|
|
137
|
+
* @throws {Sass} Always throws an error
|
|
138
|
+
*/
|
|
139
|
+
static fromCwd() {
|
|
140
|
+
throw Sass.new(
|
|
141
|
+
"TempDirectoryObject.fromCwd() is not supported. " +
|
|
142
|
+
"Use CappedDirectoryObject.fromCwd() instead if you need to cap at the current working directory."
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
133
146
|
/**
|
|
134
147
|
* Creates the directory synchronously on the filesystem.
|
|
135
148
|
*
|
|
@@ -8,6 +8,19 @@
|
|
|
8
8
|
* @augments DirectoryObject
|
|
9
9
|
*/
|
|
10
10
|
export default class CappedDirectoryObject extends DirectoryObject {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a CappedDirectoryObject from the current working directory.
|
|
13
|
+
* This is useful when working with pnpx or other tools where you need to
|
|
14
|
+
* cap at the project's root directory determined at runtime.
|
|
15
|
+
*
|
|
16
|
+
* @returns {CappedDirectoryObject} A CappedDirectoryObject capped at the current working directory
|
|
17
|
+
* @example
|
|
18
|
+
* // When using pnpx or similar tools
|
|
19
|
+
* const projectRoot = CappedDirectoryObject.fromCwd()
|
|
20
|
+
* const srcDir = projectRoot.getDirectory("src")
|
|
21
|
+
* // srcDir is capped at the project root
|
|
22
|
+
*/
|
|
23
|
+
static fromCwd(): CappedDirectoryObject;
|
|
11
24
|
/**
|
|
12
25
|
* Constructs a CappedDirectoryObject instance.
|
|
13
26
|
*
|
|
@@ -15,13 +28,17 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
15
28
|
* (virtual root). With a parent, the path is resolved relative to the parent's
|
|
16
29
|
* cap using virtual path semantics (absolute paths treated as cap-relative).
|
|
17
30
|
*
|
|
18
|
-
* @param {string} dirPath - Directory path (becomes cap if no parent, else relative to parent's cap)
|
|
31
|
+
* @param {string} [dirPath="."] - Directory path (becomes cap if no parent, else relative to parent's cap, defaults to current directory)
|
|
19
32
|
* @param {CappedDirectoryObject?} [parent] - Optional parent capped directory
|
|
20
33
|
* @param {boolean} [temporary=false] - Whether this is a temporary directory
|
|
21
|
-
* @throws {Sass} If path is empty
|
|
22
34
|
* @throws {Sass} If parent is provided but not a CappedDirectoryObject
|
|
23
35
|
* @throws {Sass} If the resulting path would escape the cap
|
|
24
36
|
* @example
|
|
37
|
+
* // Create new capped directory at current directory
|
|
38
|
+
* const cwd = new CappedDirectoryObject()
|
|
39
|
+
* // path: process.cwd(), cap: process.cwd()
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
25
42
|
* // Create new capped directory
|
|
26
43
|
* const cache = new CappedDirectoryObject("/home/user/.cache")
|
|
27
44
|
* // path: /home/user/.cache, cap: /home/user/.cache
|
|
@@ -36,7 +53,7 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
36
53
|
* const config = new CappedDirectoryObject("/etc/config", cache)
|
|
37
54
|
* // path: /home/user/.cache/etc/config, cap: /home/user/.cache
|
|
38
55
|
*/
|
|
39
|
-
constructor(dirPath
|
|
56
|
+
constructor(dirPath?: string, parent?: CappedDirectoryObject | null, temporary?: boolean);
|
|
40
57
|
/**
|
|
41
58
|
* Re-caps this directory to itself, making it the new root of the capped tree.
|
|
42
59
|
* This is a protected method intended for use by subclasses like TempDirectoryObject.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CappedDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/CappedDirectoryObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH;
|
|
1
|
+
{"version":3,"file":"CappedDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/CappedDirectoryObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH;IA2FE;;;;;;;;;;;OAWG;IACH,kBAPa,qBAAqB,CASjC;IAtGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,sBAzBW,MAAM,WACN,qBAAqB,OAAC,cACtB,OAAO,EA6EjB;IAqCD;;;;;OAKG;IACH,+BAEC;IAED;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,0BAFa,MAAM,CAIlB;IAqCD;;;;;;;;;;;;;;;;;OAiBG;IACH,YAba,eAAe,CAe3B;IAED;;;;;;;;;;;;;OAaG;IACH,cAPa,qBAAqB,GAAC,IAAI,CA0BtC;IAED;;;;OAIG;IACH,WAFa,GAAG,CAIf;IAqFD;;;;OAIG;IACH,cAFa,SAAS,CAAC,eAAe,CAAC,CAItC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,sBAjBW,MAAM,GACJ,qBAAqB,CAiEjC;IAsID;;;;;OAKG;IACH,WAHW,MAAM,GACJ,OAAO,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAAC,WAAW,QAAO;KAAC,CAAC,CAgBnE;;CA8DF;4BArpB2B,sBAAsB;uBAC3B,iBAAiB"}
|
|
@@ -49,13 +49,24 @@
|
|
|
49
49
|
*/
|
|
50
50
|
export default class DirectoryObject extends FS {
|
|
51
51
|
[x: number]: () => object;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a DirectoryObject from the current working directory.
|
|
54
|
+
* Useful when working with pnpx or other tools where the project root
|
|
55
|
+
* needs to be determined at runtime.
|
|
56
|
+
*
|
|
57
|
+
* @returns {DirectoryObject} A DirectoryObject representing the current working directory
|
|
58
|
+
* @example
|
|
59
|
+
* const projectRoot = DirectoryObject.fromCwd()
|
|
60
|
+
* console.log(projectRoot.path) // process.cwd()
|
|
61
|
+
*/
|
|
62
|
+
static fromCwd(): DirectoryObject;
|
|
52
63
|
/**
|
|
53
64
|
* Constructs a DirectoryObject instance.
|
|
54
65
|
*
|
|
55
|
-
* @param {string? | DirectoryObject?} directory - The directory path or DirectoryObject
|
|
66
|
+
* @param {string? | DirectoryObject?} [directory="."] - The directory path or DirectoryObject (defaults to current directory)
|
|
56
67
|
* @param {boolean} [temporary] - Whether this is a temporary directory.
|
|
57
68
|
*/
|
|
58
|
-
constructor(directory?:
|
|
69
|
+
constructor(directory?: string, temporary?: boolean);
|
|
59
70
|
/**
|
|
60
71
|
* Returns a JSON representation of the DirectoryObject.
|
|
61
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/DirectoryObject.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH;
|
|
1
|
+
{"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/DirectoryObject.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH;uBAoHe,MAAM;IA9CnB;;;;;;;;;OASG;IACH,kBALa,eAAe,CAO3B;IA/CD;;;;;OAKG;IACH,4CAFW,OAAO,EA6BjB;IAyBD;;;;OAIG;IACH,UAFa,MAAM,CAelB;IAWD;;;;OAIG;IACH,cAFa,OAAO,CAAC,OAAO,CAAC,CAI5B;IAED;;;;OAIG;IACH,gBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,WAFa,GAAG,CAIf;IAED;;;;OAIG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,iBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;;;;OAOG;IACH,aALa,KAAK,CAAC,MAAM,CAAC,CAOzB;IAED;;;;OAIG;IACH,iBAFa,OAAO,CAInB;IAED;;;;;;;;;;;;OAYG;IACH,cARa,eAAe,GAAC,IAAI,CAwBhC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,YAXa,eAAe,CAoB3B;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,UATa,OAAO,CAAC,IAAI,CAAC,CA0BzB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,mBAFa,OAAO,CAInB;IAiBD;;;;;;;;;;;;;;;OAeG;IACH,WAZW,MAAM,GACJ,OAAO,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAAC,WAAW,EAAE,KAAK,CAAC,eAAe,CAAC,CAAA;KAAC,CAAC,CAoCpF;IAED;;;;;;;;;;;;OAYG;IACH,uBARW,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAqBzB;IA8BD;;;;;;;;;;;;;;;OAeG;IACH,cAZa,MAAM,CAclB;IAED;;;;;;;;;;;;;;OAcG;IACH,UARa,OAAO,CAAC,IAAI,CAAC,CAkBzB;IAED;;;;;OAKG;IACH,kBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAM5B;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAO5B;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sBAdW,MAAM,GACJ,eAAe,CAoB3B;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAbW,MAAM,GACJ,UAAU,CAkBtB;;CACF;eAjnBc,SAAS;uBACD,iBAAiB"}
|
|
@@ -9,6 +9,13 @@
|
|
|
9
9
|
* @augments CappedDirectoryObject
|
|
10
10
|
*/
|
|
11
11
|
export default class TempDirectoryObject extends CappedDirectoryObject {
|
|
12
|
+
/**
|
|
13
|
+
* TempDirectoryObject does not support fromCwd() since it is specifically
|
|
14
|
+
* designed to work within the OS temporary directory tree.
|
|
15
|
+
*
|
|
16
|
+
* @throws {Sass} Always throws an error
|
|
17
|
+
*/
|
|
18
|
+
static fromCwd(): void;
|
|
12
19
|
/**
|
|
13
20
|
* Constructs a TempDirectoryObject instance and creates the directory.
|
|
14
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TempDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/TempDirectoryObject.js"],"names":[],"mappings":"AAcA;;;;;;;;;GASG;AACH;
|
|
1
|
+
{"version":3,"file":"TempDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/TempDirectoryObject.js"],"names":[],"mappings":"AAcA;;;;;;;;;GASG;AACH;IA4GE;;;;;OAKG;IACH,uBAKC;IArHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,mBAxBW,MAAM,OAAC,WACP,mBAAmB,OAAC,EA6F9B;IAmCD;;;;;;;;;;;;;;OAcG;IACH,sBAVW,MAAM,GACJ,mBAAmB,CAY/B;IAED;;;;;;;;;;;;;;OAcG;IACH,kBAVW,MAAM,GACJ,UAAU,CAYtB;;CAUF;kCA3MiC,4BAA4B"}
|