@gesslar/toolkit 3.16.1 → 3.17.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/node/lib/DirectoryObject.js +56 -7
- package/src/node/lib/FileObject.js +6 -1
- package/types/node/lib/DirectoryObject.d.ts +24 -0
- package/types/node/lib/DirectoryObject.d.ts.map +1 -1
- package/types/node/lib/FileObject.d.ts +6 -1
- package/types/node/lib/FileObject.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -318,13 +318,6 @@ export default class DirectoryObject extends FS {
|
|
|
318
318
|
glob(pat, {
|
|
319
319
|
cwd: this.isVirtual ? this.real?.path : this.path,
|
|
320
320
|
withFileTypes,
|
|
321
|
-
// exclude: candidate => {
|
|
322
|
-
// // Only allow entries within this directory's URL
|
|
323
|
-
// const candidateHref = candidate.url.href
|
|
324
|
-
|
|
325
|
-
// // Must start with our URL + path separator, or be exactly our URL
|
|
326
|
-
// return !candidateHref.startsWith(href + "/") && candidateHref !== href
|
|
327
|
-
// }
|
|
328
321
|
})
|
|
329
322
|
)
|
|
330
323
|
|
|
@@ -343,6 +336,62 @@ export default class DirectoryObject extends FS {
|
|
|
343
336
|
return {files, directories}
|
|
344
337
|
}
|
|
345
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Recursively searches directory tree for files and directories matching a glob pattern.
|
|
341
|
+
* Unlike read(), this method searches recursively through subdirectories.
|
|
342
|
+
*
|
|
343
|
+
* Returns FileObject and DirectoryObject instances for regular directories.
|
|
344
|
+
* Returns VFileObject and VDirectoryObject instances when called on virtual directories.
|
|
345
|
+
*
|
|
346
|
+
* @async
|
|
347
|
+
* @param {string} [pat=""] - Glob pattern to filter results
|
|
348
|
+
* @returns {Promise<{files: Array<FileObject|VFileObject>, directories: Array<DirectoryObject|VDirectoryObject>}>} Object containing arrays of matching files and directories
|
|
349
|
+
* @throws {Sass} If an entry is neither a file nor directory
|
|
350
|
+
* @example
|
|
351
|
+
* const dir = new DirectoryObject("./src")
|
|
352
|
+
* const {files} = await dir.glob("**\/*.test.js")
|
|
353
|
+
* console.log(files) // All .test.js files in ./src and subdirectories
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* // Find all package.json files recursively
|
|
357
|
+
* const {files} = await dir.glob("**\/package.json")
|
|
358
|
+
*/
|
|
359
|
+
async glob(pat="") {
|
|
360
|
+
const withFileTypes = true
|
|
361
|
+
const found = await Array.fromAsync(
|
|
362
|
+
glob(pat, {
|
|
363
|
+
cwd: this.isVirtual ? this.real?.path : this.path,
|
|
364
|
+
withFileTypes,
|
|
365
|
+
})
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
const files = [], directories = []
|
|
369
|
+
const virtual = this.isVirtual
|
|
370
|
+
|
|
371
|
+
found.forEach(e => {
|
|
372
|
+
if(e.isFile()) {
|
|
373
|
+
const {name, parentPath} = e
|
|
374
|
+
const resolved = FS.resolvePath(parentPath, name)
|
|
375
|
+
|
|
376
|
+
const file = virtual
|
|
377
|
+
? new VFileObject(resolved, this)
|
|
378
|
+
: new FileObject(resolved, this)
|
|
379
|
+
|
|
380
|
+
files.push(file)
|
|
381
|
+
} else if(e.isDirectory()) {
|
|
382
|
+
const {name, parentPath} = e
|
|
383
|
+
const resolved = FS.resolvePath(parentPath, name)
|
|
384
|
+
const directory = new this.constructor(resolved, this)
|
|
385
|
+
|
|
386
|
+
directories.push(directory)
|
|
387
|
+
} else {
|
|
388
|
+
throw Sass.new(`wtf is this? ${e}`)
|
|
389
|
+
}
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
return {files, directories}
|
|
393
|
+
}
|
|
394
|
+
|
|
346
395
|
/**
|
|
347
396
|
* Ensures a directory exists, creating it if necessary.
|
|
348
397
|
* Gracefully handles the case where the directory already exists.
|
|
@@ -105,7 +105,7 @@ export default class FileObject extends FS {
|
|
|
105
105
|
return [
|
|
106
106
|
parent.path === dir
|
|
107
107
|
? parent
|
|
108
|
-
: new
|
|
108
|
+
: new parent.constructor(dir, parent),
|
|
109
109
|
joined,
|
|
110
110
|
]
|
|
111
111
|
}
|
|
@@ -236,6 +236,11 @@ export default class FileObject extends FS {
|
|
|
236
236
|
return this.#meta.parent
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Returns the absolute path of the parent directory.
|
|
241
|
+
*
|
|
242
|
+
* @returns {string} The parent directory path
|
|
243
|
+
*/
|
|
239
244
|
get parentPath() {
|
|
240
245
|
return this.#meta.parentPath
|
|
241
246
|
}
|
|
@@ -162,6 +162,30 @@ export default class DirectoryObject extends FS {
|
|
|
162
162
|
files: Array<FileObject | VFileObject>;
|
|
163
163
|
directories: Array<DirectoryObject | VDirectoryObject>;
|
|
164
164
|
}>;
|
|
165
|
+
/**
|
|
166
|
+
* Recursively searches directory tree for files and directories matching a glob pattern.
|
|
167
|
+
* Unlike read(), this method searches recursively through subdirectories.
|
|
168
|
+
*
|
|
169
|
+
* Returns FileObject and DirectoryObject instances for regular directories.
|
|
170
|
+
* Returns VFileObject and VDirectoryObject instances when called on virtual directories.
|
|
171
|
+
*
|
|
172
|
+
* @async
|
|
173
|
+
* @param {string} [pat=""] - Glob pattern to filter results
|
|
174
|
+
* @returns {Promise<{files: Array<FileObject|VFileObject>, directories: Array<DirectoryObject|VDirectoryObject>}>} Object containing arrays of matching files and directories
|
|
175
|
+
* @throws {Sass} If an entry is neither a file nor directory
|
|
176
|
+
* @example
|
|
177
|
+
* const dir = new DirectoryObject("./src")
|
|
178
|
+
* const {files} = await dir.glob("**\/*.test.js")
|
|
179
|
+
* console.log(files) // All .test.js files in ./src and subdirectories
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* // Find all package.json files recursively
|
|
183
|
+
* const {files} = await dir.glob("**\/package.json")
|
|
184
|
+
*/
|
|
185
|
+
glob(pat?: string): Promise<{
|
|
186
|
+
files: Array<FileObject | VFileObject>;
|
|
187
|
+
directories: Array<DirectoryObject | VDirectoryObject>;
|
|
188
|
+
}>;
|
|
165
189
|
/**
|
|
166
190
|
* Ensures a directory exists, creating it if necessary.
|
|
167
191
|
* Gracefully handles the case where the directory already exists.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/DirectoryObject.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH;IA2DE;;;;;;;;;OASG;IACH,kBALa,eAAe,CAO3B;IA3CD;;;;OAIG;IACH,uBAFW,MAAM,OAAC,EA0BjB;IA2BD;;;;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;;;;;;;;;;;;OAYG;IACH,cARa,eAAe,GAAC,IAAI,CAsBhC;IAED;;;;OAIG;IACH,mBAFa,OAAO,CAInB;IAmBD;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAZW,MAAM,GACJ,OAAO,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,UAAU,GAAC,WAAW,CAAC,CAAC;QAAC,WAAW,EAAE,KAAK,CAAC,eAAe,GAAC,gBAAgB,CAAC,CAAA;KAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/DirectoryObject.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;OAKG;IACH,kBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAQ5B;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAO5B;IAUD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,kBAdW,MAAM,GACJ,eAAe,CAqB3B;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,cAbW,MAAM,GACJ,UAAU,GAAC,WAAW,CAsBlC;;CACF;eAxkBc,iBAAiB;uBACT,iBAAiB;wBAGhB,kBAAkB"}
|
|
@@ -93,7 +93,12 @@ export default class FileObject extends FS {
|
|
|
93
93
|
* @returns {DirectoryObject} The parent directory object
|
|
94
94
|
*/
|
|
95
95
|
get parent(): DirectoryObject;
|
|
96
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Returns the absolute path of the parent directory.
|
|
98
|
+
*
|
|
99
|
+
* @returns {string} The parent directory path
|
|
100
|
+
*/
|
|
101
|
+
get parentPath(): string;
|
|
97
102
|
/**
|
|
98
103
|
* Check if a file can be read. Returns true if the file can be read, false
|
|
99
104
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;GAaG;AAEH;IACE;;;;;OAKG;IACH,yBAFU;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,CAAA;KAAC,CAO1D;IA0BF;;;;;OAKG;IACH,uBAHW,MAAM,WACN,eAAe,GAAC,MAAM,GAAC,IAAI,EA4DrC;IAaD;;;;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;IACD;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;;;;;;;;;;;OAcG;IACH,cAFa,eAAe,CAI3B;IAED,
|
|
1
|
+
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;GAaG;AAEH;IACE;;;;;OAKG;IACH,yBAFU;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,CAAA;KAAC,CAO1D;IA0BF;;;;;OAKG;IACH,uBAHW,MAAM,WACN,eAAe,GAAC,MAAM,GAAC,IAAI,EA4DrC;IAaD;;;;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;IACD;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;;;;;;;;;;;OAcG;IACH,cAFa,eAAe,CAI3B;IAED;;;;OAIG;IACH,kBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,WAFa,OAAO,CAAC,OAAO,CAAC,CAU5B;IAED;;;;OAIG;IACH,YAFa,OAAO,CAAC,OAAO,CAAC,CAU5B;IAiBD;;;;OAIG;IACH,QAFa,OAAO,CAAC,MAAM,OAAC,CAAC,CAU5B;IAED;;;;;OAKG;IACH,YAFa,OAAO,CAAC,IAAI,OAAC,CAAC,CAU1B;IAED;;;;;OAKG;IACH,gBAHW,MAAM,GACJ,OAAO,CA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