@gesslar/toolkit 2.10.0 → 2.10.1
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 +48 -1
- package/src/lib/FileObject.js +18 -10
- package/src/types/lib/CappedDirectoryObject.d.ts +6 -0
- package/src/types/lib/CappedDirectoryObject.d.ts.map +1 -1
- package/src/types/lib/FileObject.d.ts +3 -2
- package/src/types/lib/FileObject.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -248,6 +248,40 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
248
248
|
: new DirectoryObject(parentPath, this.temporary)
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Returns the URL with virtual path (cap-relative).
|
|
253
|
+
*
|
|
254
|
+
* @returns {URL} Virtual URL
|
|
255
|
+
*/
|
|
256
|
+
get url() {
|
|
257
|
+
return new URL(FS.pathToUri(this.path))
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Returns JSON representation with virtual paths and .real escape hatch.
|
|
262
|
+
*
|
|
263
|
+
* @returns {object} JSON representation
|
|
264
|
+
*/
|
|
265
|
+
toJSON() {
|
|
266
|
+
const capResolved = path.resolve(this.#cap)
|
|
267
|
+
const parentPath = this.#realPath === capResolved
|
|
268
|
+
? null
|
|
269
|
+
: "/"
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
supplied: this.supplied,
|
|
273
|
+
path: this.path,
|
|
274
|
+
url: this.url.toString(),
|
|
275
|
+
name: this.name,
|
|
276
|
+
module: this.module,
|
|
277
|
+
extension: this.extension,
|
|
278
|
+
isFile: this.isFile,
|
|
279
|
+
isDirectory: this.isDirectory,
|
|
280
|
+
parent: parentPath,
|
|
281
|
+
real: this.real.toJSON()
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
251
285
|
/**
|
|
252
286
|
* Generator that walks up the directory tree, stopping at the cap.
|
|
253
287
|
* Yields parent directories from current up to (and including) the cap root.
|
|
@@ -522,7 +556,20 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
522
556
|
return new this.constructor(name, this)
|
|
523
557
|
})
|
|
524
558
|
|
|
525
|
-
return
|
|
559
|
+
// Recreate FileObjects with capped parent so they return virtual paths
|
|
560
|
+
const cappedFiles = files.map(file => new FileObject(file.name, this))
|
|
561
|
+
|
|
562
|
+
return {files: cappedFiles, directories: cappedDirectories}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Override hasDirectory to use real filesystem path.
|
|
567
|
+
*
|
|
568
|
+
* @param {string} dirname - Directory name to check
|
|
569
|
+
* @returns {Promise<boolean>} True if directory exists
|
|
570
|
+
*/
|
|
571
|
+
async hasDirectory(dirname) {
|
|
572
|
+
return await this.real.hasDirectory(dirname)
|
|
526
573
|
}
|
|
527
574
|
|
|
528
575
|
/**
|
package/src/lib/FileObject.js
CHANGED
|
@@ -214,11 +214,19 @@ export default class FileObject extends FS {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
|
-
* Returns the URL of the current file.
|
|
217
|
+
* Returns the URL of the current file. If the parent is a capped directory,
|
|
218
|
+
* returns a virtual URL relative to the cap. Otherwise returns the real URL.
|
|
218
219
|
*
|
|
219
|
-
* @returns {URL} The file URL
|
|
220
|
+
* @returns {URL} The file URL (virtual if parent is capped, real otherwise)
|
|
220
221
|
*/
|
|
221
222
|
get url() {
|
|
223
|
+
const parent = this.#meta.parent
|
|
224
|
+
|
|
225
|
+
// If parent is capped, return virtual URL
|
|
226
|
+
if(parent?.capped) {
|
|
227
|
+
return new URL(FS.pathToUri(this.path))
|
|
228
|
+
}
|
|
229
|
+
|
|
222
230
|
return this.#meta.url
|
|
223
231
|
}
|
|
224
232
|
|
|
@@ -408,7 +416,7 @@ export default class FileObject extends FS {
|
|
|
408
416
|
* @returns {Promise<string>} The file contents
|
|
409
417
|
*/
|
|
410
418
|
async read(encoding="utf8") {
|
|
411
|
-
const url = this.url
|
|
419
|
+
const url = this.#meta.url
|
|
412
420
|
|
|
413
421
|
if(!url)
|
|
414
422
|
throw Sass.new("No URL in file map")
|
|
@@ -432,7 +440,7 @@ export default class FileObject extends FS {
|
|
|
432
440
|
* // Use the buffer (e.g., send in HTTP response, process image, etc.)
|
|
433
441
|
*/
|
|
434
442
|
async readBinary() {
|
|
435
|
-
const url = this.url
|
|
443
|
+
const url = this.#meta.url
|
|
436
444
|
|
|
437
445
|
if(!url)
|
|
438
446
|
throw Sass.new("No URL in file map")
|
|
@@ -456,11 +464,11 @@ export default class FileObject extends FS {
|
|
|
456
464
|
* await file.write(JSON.stringify({key: 'value'}))
|
|
457
465
|
*/
|
|
458
466
|
async write(content, encoding="utf8") {
|
|
459
|
-
if(!this.url)
|
|
467
|
+
if(!this.#meta.url)
|
|
460
468
|
throw Sass.new("No URL in file")
|
|
461
469
|
|
|
462
470
|
if(await this.parent.exists)
|
|
463
|
-
await fs.writeFile(this.url, content, encoding)
|
|
471
|
+
await fs.writeFile(this.#meta.url, content, encoding)
|
|
464
472
|
|
|
465
473
|
else
|
|
466
474
|
throw Sass.new(`Invalid directory, ${this.parent.url.href}`)
|
|
@@ -483,7 +491,7 @@ export default class FileObject extends FS {
|
|
|
483
491
|
* await file.writeBinary(buffer)
|
|
484
492
|
*/
|
|
485
493
|
async writeBinary(data) {
|
|
486
|
-
if(!this.url)
|
|
494
|
+
if(!this.#meta.url)
|
|
487
495
|
throw Sass.new("No URL in file")
|
|
488
496
|
|
|
489
497
|
const exists = await this.parent.exists
|
|
@@ -496,7 +504,7 @@ export default class FileObject extends FS {
|
|
|
496
504
|
|
|
497
505
|
// According to the internet, if it's already binary, I don't need
|
|
498
506
|
// an encoding. 🤷
|
|
499
|
-
return await fs.writeFile(this.url, bufferData)
|
|
507
|
+
return await fs.writeFile(this.#meta.url, bufferData)
|
|
500
508
|
}
|
|
501
509
|
|
|
502
510
|
/**
|
|
@@ -547,7 +555,7 @@ export default class FileObject extends FS {
|
|
|
547
555
|
* @returns {Promise<object>} The file contents as a module.
|
|
548
556
|
*/
|
|
549
557
|
async import() {
|
|
550
|
-
const url = this.url
|
|
558
|
+
const url = this.#meta.url
|
|
551
559
|
|
|
552
560
|
if(!url)
|
|
553
561
|
throw Sass.new("No URL in file map")
|
|
@@ -569,7 +577,7 @@ export default class FileObject extends FS {
|
|
|
569
577
|
* await file.delete()
|
|
570
578
|
*/
|
|
571
579
|
async delete() {
|
|
572
|
-
const url = this.url
|
|
580
|
+
const url = this.#meta.url
|
|
573
581
|
|
|
574
582
|
if(!url)
|
|
575
583
|
throw Sass.new("This object does not represent a valid resource.")
|
|
@@ -75,6 +75,12 @@ export default class CappedDirectoryObject extends DirectoryObject {
|
|
|
75
75
|
* subdir.real.parent // Can traverse outside the cap
|
|
76
76
|
*/
|
|
77
77
|
get real(): DirectoryObject;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the URL with virtual path (cap-relative).
|
|
80
|
+
*
|
|
81
|
+
* @returns {URL} Virtual URL
|
|
82
|
+
*/
|
|
83
|
+
get url(): URL;
|
|
78
84
|
/**
|
|
79
85
|
* Returns a generator that walks up to the cap.
|
|
80
86
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CappedDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/CappedDirectoryObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH;IAGE;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,qBArBW,MAAM,WACN,qBAAqB,OAAC,cACtB,OAAO,EA0EjB;IAqBD;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,0BAFa,MAAM,CAIlB;IAqCD;;;;;;;;;;;;;;;;;OAiBG;IACH,YAba,eAAe,CAe3B;
|
|
1
|
+
{"version":3,"file":"CappedDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/CappedDirectoryObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH;IAGE;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,qBArBW,MAAM,WACN,qBAAqB,OAAC,cACtB,OAAO,EA0EjB;IAqBD;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,0BAFa,MAAM,CAIlB;IAqCD;;;;;;;;;;;;;;;;;OAiBG;IACH,YAba,eAAe,CAe3B;IAiCD;;;;OAIG;IACH,WAFa,GAAG,CAIf;IAqED;;;;OAIG;IACH,cAFa,SAAS,CAAC,eAAe,CAAC,CAItC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,sBAjBW,MAAM,GACJ,qBAAqB,CAiEjC;IAqID;;;;;OAKG;IACH,WAHW,MAAM,GACJ,OAAO,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAAC,WAAW,QAAO;KAAC,CAAC,CAgBnE;;CA8DF;4BAnmB2B,sBAAsB;uBAC3B,iBAAiB"}
|
|
@@ -58,9 +58,10 @@ export default class FileObject extends FS {
|
|
|
58
58
|
*/
|
|
59
59
|
get path(): string;
|
|
60
60
|
/**
|
|
61
|
-
* Returns the URL of the current file.
|
|
61
|
+
* Returns the URL of the current file. If the parent is a capped directory,
|
|
62
|
+
* returns a virtual URL relative to the cap. Otherwise returns the real URL.
|
|
62
63
|
*
|
|
63
|
-
* @returns {URL} The file URL
|
|
64
|
+
* @returns {URL} The file URL (virtual if parent is capped, real otherwise)
|
|
64
65
|
*/
|
|
65
66
|
get url(): URL;
|
|
66
67
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../lib/FileObject.js"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;GAcG;AAEH;uBAmIe,MAAM;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