@gesslar/toolkit 3.23.0 → 3.24.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
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"name": "gesslar",
|
|
6
6
|
"url": "https://gesslar.dev"
|
|
7
7
|
},
|
|
8
|
-
"version": "3.
|
|
8
|
+
"version": "3.24.0",
|
|
9
9
|
"license": "Unlicense",
|
|
10
10
|
"homepage": "https://github.com/gesslar/toolkit#readme",
|
|
11
11
|
"repository": {
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
"yaml": "^2.8.2"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@gesslar/uglier": "^1.
|
|
65
|
+
"@gesslar/uglier": "^1.2.0",
|
|
66
66
|
"eslint": "^9.39.2",
|
|
67
|
-
"eslint-plugin-jsdoc": "^62.
|
|
68
|
-
"happy-dom": "^20.3.
|
|
67
|
+
"eslint-plugin-jsdoc": "^62.3.0",
|
|
68
|
+
"happy-dom": "^20.3.4",
|
|
69
69
|
"typescript": "^5.9.3",
|
|
70
|
-
"typescript-eslint": "^8.53.
|
|
70
|
+
"typescript-eslint": "^8.53.1"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"types": "node -e \"require('fs').rmSync('types',{recursive:true,force:true});\" && tsc -p tsconfig.types.json",
|
|
@@ -488,4 +488,49 @@ export default class FileObject extends FS {
|
|
|
488
488
|
|
|
489
489
|
return await fs.unlink(filePath)
|
|
490
490
|
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Creates a FileObject representing the current working file (the file
|
|
494
|
+
* that called this method). Parses the stack trace to determine the
|
|
495
|
+
* caller's file path.
|
|
496
|
+
*
|
|
497
|
+
* @returns {FileObject} A new FileObject instance for the calling file
|
|
498
|
+
* @throws {Sass} If unable to determine caller file from stack trace
|
|
499
|
+
* @example
|
|
500
|
+
* // In /home/user/project/src/app.js:
|
|
501
|
+
* const thisFile = FileObject.fromCwf()
|
|
502
|
+
* console.log(thisFile.path) // /home/user/project/src/app.js
|
|
503
|
+
*/
|
|
504
|
+
static fromCwf() {
|
|
505
|
+
const originalPrepare = Error.prepareStackTrace
|
|
506
|
+
Error.prepareStackTrace = (_, stack) => stack
|
|
507
|
+
/** @type {Array<{getFileName: () => string|null}>} */
|
|
508
|
+
const stack = (new Error().stack)
|
|
509
|
+
Error.prepareStackTrace = originalPrepare
|
|
510
|
+
|
|
511
|
+
// Find the first call site that isn't this file
|
|
512
|
+
// Stack filenames may be file:// URLs, so compare both forms
|
|
513
|
+
const thisFileUrl = import.meta.url
|
|
514
|
+
const thisFilePath = FS.urlToPath(thisFileUrl)
|
|
515
|
+
const callerSite = stack.find(site => {
|
|
516
|
+
const fileName = site.getFileName()
|
|
517
|
+
|
|
518
|
+
if(!fileName)
|
|
519
|
+
return false
|
|
520
|
+
|
|
521
|
+
return fileName !== thisFileUrl && fileName !== thisFilePath
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
const callerFile = callerSite?.getFileName()
|
|
525
|
+
|
|
526
|
+
if(!callerFile)
|
|
527
|
+
throw Sass.new("Unable to determine caller file from stack trace")
|
|
528
|
+
|
|
529
|
+
// Handle file:// URLs
|
|
530
|
+
const filePath = callerFile.startsWith("file://")
|
|
531
|
+
? FS.urlToPath(callerFile)
|
|
532
|
+
: callerFile
|
|
533
|
+
|
|
534
|
+
return new this(filePath)
|
|
535
|
+
}
|
|
491
536
|
}
|
|
@@ -80,17 +80,19 @@ export default class FileSystem {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Convert a
|
|
83
|
+
* Convert a file URL to a path.
|
|
84
84
|
*
|
|
85
85
|
* @static
|
|
86
|
-
* @param {string}
|
|
87
|
-
* @returns {string} The path
|
|
86
|
+
* @param {string} fileUrl - The file URL to convert (e.g., import.meta.url)
|
|
87
|
+
* @returns {string} The file path
|
|
88
|
+
* @example
|
|
89
|
+
* const currentFile = FileSystem.urlToPath(import.meta.url)
|
|
88
90
|
*/
|
|
89
|
-
static urlToPath(
|
|
91
|
+
static urlToPath(fileUrl) {
|
|
90
92
|
try {
|
|
91
|
-
return url.fileURLToPath(
|
|
93
|
+
return url.fileURLToPath(fileUrl)
|
|
92
94
|
} catch {
|
|
93
|
-
return
|
|
95
|
+
return fileUrl
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -22,6 +22,19 @@ export default class FileObject extends FS {
|
|
|
22
22
|
static dataLoaderConfig: {
|
|
23
23
|
[key: string]: Array<typeof JSON5 | typeof YAML>;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates a FileObject representing the current working file (the file
|
|
27
|
+
* that called this method). Parses the stack trace to determine the
|
|
28
|
+
* caller's file path.
|
|
29
|
+
*
|
|
30
|
+
* @returns {FileObject} A new FileObject instance for the calling file
|
|
31
|
+
* @throws {Sass} If unable to determine caller file from stack trace
|
|
32
|
+
* @example
|
|
33
|
+
* // In /home/user/project/src/app.js:
|
|
34
|
+
* const thisFile = FileObject.fromCwf()
|
|
35
|
+
* console.log(thisFile.path) // /home/user/project/src/app.js
|
|
36
|
+
*/
|
|
37
|
+
static fromCwf(): FileObject;
|
|
25
38
|
/**
|
|
26
39
|
* Constructs a FileObject instance.
|
|
27
40
|
*
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;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GACrB,OAAO,CAAC,IAAI,CAAC,CAwBzB;IAED;;;;;;;;;;;;;;OAcG;IACH,gBAXW,MAAM,aACN,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAiC5B;IAED;;;;OAIG;IACH,UAFa,OAAO,CAAC,MAAM,CAAC,CAS3B;IAED;;;;;;;;;OASG;IACH,UAPa,OAAO,CAAC,IAAI,CAAC,CAczB;;CA8CF;eAzgBc,iBAAiB;4BADJ,sBAAsB;kBAPhC,OAAO;iBAER,MAAM"}
|
|
@@ -22,13 +22,15 @@ export default class FileSystem {
|
|
|
22
22
|
*/
|
|
23
23
|
static pathToUrl(pathName: string): string;
|
|
24
24
|
/**
|
|
25
|
-
* Convert a
|
|
25
|
+
* Convert a file URL to a path.
|
|
26
26
|
*
|
|
27
27
|
* @static
|
|
28
|
-
* @param {string}
|
|
29
|
-
* @returns {string} The path
|
|
28
|
+
* @param {string} fileUrl - The file URL to convert (e.g., import.meta.url)
|
|
29
|
+
* @returns {string} The file path
|
|
30
|
+
* @example
|
|
31
|
+
* const currentFile = FileSystem.urlToPath(import.meta.url)
|
|
30
32
|
*/
|
|
31
|
-
static urlToPath(
|
|
33
|
+
static urlToPath(fileUrl: string): string;
|
|
32
34
|
/**
|
|
33
35
|
* Computes the relative path from one file or directory to another.
|
|
34
36
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileSystem.js"],"names":[],"mappings":"AA2BA;;GAEG;AACH;IACE,kCAAwB;IACxB,uCAAkC;IAClC,mBAAsB;IAsBtB;;;;;;OAMG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED
|
|
1
|
+
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileSystem.js"],"names":[],"mappings":"AA2BA;;GAEG;AACH;IACE,kCAAwB;IACxB,uCAAkC;IAClC,mBAAsB;IAsBtB;;;;;;OAMG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;;OAQG;IACH,0BALW,MAAM,GACJ,MAAM,CAUlB;IAED;;;;;;;;;;OAUG;IACH,gCAJW,UAAU,GAAC,eAAe,MAC1B,UAAU,GAAC,eAAe,GACxB,MAAM,CAYlB;IAED;;;;;;;;;;OAUG;IACH,oCAJW,MAAM,MACN,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;;;OASG;IACH,oCALW,MAAM,SACN,MAAM,QACN,MAAM,GACJ,MAAM,CA0BlB;IAED;;;;;;;;OAQG;IACH,6BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAmClB;IAED;;;;;;;;;;;;OAYG;IACH,+BATW,MAAM,aACN,MAAM,GACJ,OAAO,CAcnB;IAED;;;;;;;;;;;;;;OAcG;IACH,4BATW,MAAM,MACN,MAAM,QACN,MAAM,GACJ,MAAM,GAAC,IAAI,CAwBvB;IAED;;;;;;;;;;;;;;;OAeG;IACH,+BAXW,MAAM,MACN,MAAM,QACN,MAAM,GACJ,MAAM,GAAC,IAAI,CA+BvB;IAED;;;;;;;OAOG;IAEH;;;;;;;OAOG;IACH,2BAJW,MAAM;;;;cAXH,MAAM;;;;aACN,MAAM;;;;aACN,MAAM;;;;cACN,MAAM;;;;cACN,MAAM;MAenB;IAED;;;;OAIG;IACH,kBAFa,MAAM,CAIlB;IAzTD;;;;;;;;;OASG;IACH,kCAJW,UAAU,GAAC,eAAe,GACxB,MAAM,CAWlB;CAwSF;yBA3Ua,OAAO,iBAAiB,EAAE,OAAO;8BACjC,OAAO,sBAAsB,EAAE,OAAO"}
|