@gesslar/toolkit 3.7.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 +68 -18
- package/src/lib/DirectoryObject.js +48 -5
- package/src/lib/TempDirectoryObject.js +26 -4
- package/src/types/lib/CappedDirectoryObject.d.ts +42 -3
- package/src/types/lib/CappedDirectoryObject.d.ts.map +1 -1
- package/src/types/lib/DirectoryObject.d.ts +31 -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
|
*
|
|
@@ -132,6 +151,16 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
132
151
|
}
|
|
133
152
|
}
|
|
134
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Re-caps this directory to itself, making it the new root of the capped tree.
|
|
156
|
+
* This is a protected method intended for use by subclasses like TempDirectoryObject.
|
|
157
|
+
*
|
|
158
|
+
* @protected
|
|
159
|
+
*/
|
|
160
|
+
_recapToSelf() {
|
|
161
|
+
this.#cap = this.#realPath
|
|
162
|
+
}
|
|
163
|
+
|
|
135
164
|
/**
|
|
136
165
|
* Returns the cap path for this directory.
|
|
137
166
|
*
|
|
@@ -221,14 +250,14 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
221
250
|
* Returns the parent directory of this capped directory.
|
|
222
251
|
* Returns null only if this directory is at the cap (the "root" of the capped tree).
|
|
223
252
|
*
|
|
224
|
-
* Note: The returned parent is a
|
|
225
|
-
*
|
|
253
|
+
* Note: The returned parent is a CappedDirectoryObject with the same cap.
|
|
254
|
+
* This maintains the capping behavior throughout the directory hierarchy.
|
|
226
255
|
*
|
|
227
|
-
* @returns {
|
|
256
|
+
* @returns {CappedDirectoryObject|null} Parent directory or null if at cap root
|
|
228
257
|
* @example
|
|
229
258
|
* const capped = new TempDirectoryObject("myapp")
|
|
230
259
|
* const subdir = capped.getDirectory("data")
|
|
231
|
-
* console.log(subdir.parent.path) // Returns parent
|
|
260
|
+
* console.log(subdir.parent.path) // Returns parent CappedDirectoryObject
|
|
232
261
|
* console.log(capped.parent) // null (at cap root)
|
|
233
262
|
*/
|
|
234
263
|
get parent() {
|
|
@@ -239,13 +268,17 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
239
268
|
return null
|
|
240
269
|
}
|
|
241
270
|
|
|
242
|
-
//
|
|
271
|
+
// Compute parent's real path
|
|
243
272
|
const parentPath = path.dirname(this.#realPath)
|
|
244
273
|
const isRoot = parentPath === this.#realPath
|
|
245
274
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
275
|
+
if(isRoot) {
|
|
276
|
+
return null
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Compute relative path from current to parent (just "..")
|
|
280
|
+
// Then use getDirectory to create the parent, which preserves the class type
|
|
281
|
+
return this.getDirectory("..")
|
|
249
282
|
}
|
|
250
283
|
|
|
251
284
|
/**
|
|
@@ -264,9 +297,24 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
264
297
|
*/
|
|
265
298
|
toJSON() {
|
|
266
299
|
const capResolved = path.resolve(this.#cap)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
300
|
+
let parentPath
|
|
301
|
+
|
|
302
|
+
if(this.#realPath === capResolved) {
|
|
303
|
+
// At cap root, no parent
|
|
304
|
+
parentPath = null
|
|
305
|
+
} else {
|
|
306
|
+
// Compute parent's virtual path
|
|
307
|
+
const parentReal = path.dirname(this.#realPath)
|
|
308
|
+
const relative = path.relative(capResolved, parentReal)
|
|
309
|
+
|
|
310
|
+
// If parent is cap root or empty, return "/"
|
|
311
|
+
if(!relative || relative === ".") {
|
|
312
|
+
parentPath = "/"
|
|
313
|
+
} else {
|
|
314
|
+
// Return parent's virtual path with leading slash
|
|
315
|
+
parentPath = "/" + relative.split(path.sep).join("/")
|
|
316
|
+
}
|
|
317
|
+
}
|
|
270
318
|
|
|
271
319
|
return {
|
|
272
320
|
supplied: this.supplied,
|
|
@@ -278,6 +326,7 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
278
326
|
isFile: this.isFile,
|
|
279
327
|
isDirectory: this.isDirectory,
|
|
280
328
|
parent: parentPath,
|
|
329
|
+
root: this.root.path,
|
|
281
330
|
real: this.real.toJSON()
|
|
282
331
|
}
|
|
283
332
|
}
|
|
@@ -436,10 +485,11 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
436
485
|
// Start at cap root
|
|
437
486
|
let current = this.#createCappedAtRoot()
|
|
438
487
|
|
|
439
|
-
// Traverse each segment,
|
|
440
|
-
// (not subclass instances, to avoid constructor signature issues)
|
|
488
|
+
// Traverse each segment, using constructor to preserve class type
|
|
441
489
|
for(const segment of segments) {
|
|
442
|
-
|
|
490
|
+
// Use simple name constructor to preserve subclass type
|
|
491
|
+
// Works for both CappedDirectoryObject and TempDirectoryObject
|
|
492
|
+
current = new this.constructor(segment, current, this.temporary)
|
|
443
493
|
}
|
|
444
494
|
|
|
445
495
|
return current
|
|
@@ -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
|
*
|
|
@@ -157,7 +171,8 @@ export default class DirectoryObject extends FS {
|
|
|
157
171
|
extension: this.extension,
|
|
158
172
|
isFile: this.isFile,
|
|
159
173
|
isDirectory: this.isDirectory,
|
|
160
|
-
parent: this.parent ? this.parent.path : null
|
|
174
|
+
parent: this.parent ? this.parent.path : null,
|
|
175
|
+
root: this.root.path
|
|
161
176
|
}
|
|
162
177
|
}
|
|
163
178
|
|
|
@@ -294,6 +309,34 @@ export default class DirectoryObject extends FS {
|
|
|
294
309
|
return this.#parent
|
|
295
310
|
}
|
|
296
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Returns the root directory of the filesystem.
|
|
314
|
+
*
|
|
315
|
+
* For DirectoryObject, this walks up to the filesystem root.
|
|
316
|
+
* For CappedDirectoryObject, this returns the cap root.
|
|
317
|
+
*
|
|
318
|
+
* @returns {DirectoryObject} The root directory
|
|
319
|
+
* @example
|
|
320
|
+
* const dir = new DirectoryObject("/usr/local/bin")
|
|
321
|
+
* console.log(dir.root.path) // "/"
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* const capped = new CappedDirectoryObject("/projects/myapp")
|
|
325
|
+
* const sub = capped.getDirectory("src/lib")
|
|
326
|
+
* console.log(sub.root.path) // "/" (virtual, cap root)
|
|
327
|
+
* console.log(sub.root.real.path) // "/projects/myapp"
|
|
328
|
+
*/
|
|
329
|
+
get root() {
|
|
330
|
+
// Walk up until we find a directory with no parent
|
|
331
|
+
let current = this
|
|
332
|
+
|
|
333
|
+
while(current.parent !== null) {
|
|
334
|
+
current = current.parent
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return current
|
|
338
|
+
}
|
|
339
|
+
|
|
297
340
|
/**
|
|
298
341
|
* Recursively removes a temporary directory and all its contents.
|
|
299
342
|
*
|
|
@@ -99,11 +99,13 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
|
|
|
99
99
|
)
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
// SECURITY: Ensure parent's cap is tmpdir (prevent escape to other caps)
|
|
103
|
-
const tmpdir = os.tmpdir()
|
|
104
|
-
|
|
102
|
+
// SECURITY: Ensure parent's cap is within tmpdir (prevent escape to other caps)
|
|
103
|
+
const tmpdir = path.resolve(os.tmpdir())
|
|
104
|
+
const parentCap = path.resolve(parent.cap)
|
|
105
|
+
|
|
106
|
+
if(!parentCap.startsWith(tmpdir)) {
|
|
105
107
|
throw Sass.new(
|
|
106
|
-
`Parent must be capped to OS temp directory (${tmpdir}), ` +
|
|
108
|
+
`Parent must be capped to OS temp directory (${tmpdir}) or a subdirectory thereof, ` +
|
|
107
109
|
`got cap: ${parent.cap}`
|
|
108
110
|
)
|
|
109
111
|
}
|
|
@@ -119,6 +121,26 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
|
|
|
119
121
|
|
|
120
122
|
// Temp-specific behavior: create directory immediately
|
|
121
123
|
this.#createDirectory()
|
|
124
|
+
|
|
125
|
+
// Re-cap to the temp directory itself for consistent behavior with CappedDirectoryObject
|
|
126
|
+
// This makes temp.cap === temp.real.path and temp.parent === null
|
|
127
|
+
if(!parent) {
|
|
128
|
+
// Only re-cap if this is a root temp directory (no TempDirectoryObject parent)
|
|
129
|
+
this._recapToSelf()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
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
|
+
)
|
|
122
144
|
}
|
|
123
145
|
|
|
124
146
|
/**
|
|
@@ -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,14 @@ 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);
|
|
57
|
+
/**
|
|
58
|
+
* Re-caps this directory to itself, making it the new root of the capped tree.
|
|
59
|
+
* This is a protected method intended for use by subclasses like TempDirectoryObject.
|
|
60
|
+
*
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
protected _recapToSelf(): void;
|
|
40
64
|
/**
|
|
41
65
|
* Returns the cap path for this directory.
|
|
42
66
|
*
|
|
@@ -75,6 +99,21 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
75
99
|
* subdir.real.parent // Can traverse outside the cap
|
|
76
100
|
*/
|
|
77
101
|
get real(): DirectoryObject;
|
|
102
|
+
/**
|
|
103
|
+
* Returns the parent directory of this capped directory.
|
|
104
|
+
* Returns null only if this directory is at the cap (the "root" of the capped tree).
|
|
105
|
+
*
|
|
106
|
+
* Note: The returned parent is a CappedDirectoryObject with the same cap.
|
|
107
|
+
* This maintains the capping behavior throughout the directory hierarchy.
|
|
108
|
+
*
|
|
109
|
+
* @returns {CappedDirectoryObject|null} Parent directory or null if at cap root
|
|
110
|
+
* @example
|
|
111
|
+
* const capped = new TempDirectoryObject("myapp")
|
|
112
|
+
* const subdir = capped.getDirectory("data")
|
|
113
|
+
* console.log(subdir.parent.path) // Returns parent CappedDirectoryObject
|
|
114
|
+
* console.log(capped.parent) // null (at cap root)
|
|
115
|
+
*/
|
|
116
|
+
get parent(): CappedDirectoryObject | null;
|
|
78
117
|
/**
|
|
79
118
|
* Returns the URL with virtual path (cap-relative).
|
|
80
119
|
*
|
|
@@ -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
|
*
|
|
@@ -139,6 +150,24 @@ export default class DirectoryObject extends FS {
|
|
|
139
150
|
* console.log(root.parent) // null
|
|
140
151
|
*/
|
|
141
152
|
get parent(): DirectoryObject | null;
|
|
153
|
+
/**
|
|
154
|
+
* Returns the root directory of the filesystem.
|
|
155
|
+
*
|
|
156
|
+
* For DirectoryObject, this walks up to the filesystem root.
|
|
157
|
+
* For CappedDirectoryObject, this returns the cap root.
|
|
158
|
+
*
|
|
159
|
+
* @returns {DirectoryObject} The root directory
|
|
160
|
+
* @example
|
|
161
|
+
* const dir = new DirectoryObject("/usr/local/bin")
|
|
162
|
+
* console.log(dir.root.path) // "/"
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const capped = new CappedDirectoryObject("/projects/myapp")
|
|
166
|
+
* const sub = capped.getDirectory("src/lib")
|
|
167
|
+
* console.log(sub.root.path) // "/" (virtual, cap root)
|
|
168
|
+
* console.log(sub.root.real.path) // "/projects/myapp"
|
|
169
|
+
*/
|
|
170
|
+
get root(): DirectoryObject;
|
|
142
171
|
/**
|
|
143
172
|
* Recursively removes a temporary directory and all its contents.
|
|
144
173
|
*
|
|
@@ -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"}
|