@gesslar/toolkit 2.6.0 → 2.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gesslar/toolkit",
3
- "version": "2.6.0",
3
+ "version": "2.7.1",
4
4
  "description": "A collection of utilities for Node.js and browser environments.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -289,10 +289,9 @@ export default class CappedDirectoryObject extends DirectoryObject {
289
289
  throw Sass.new("Path traversal (..) is not allowed in capped directories")
290
290
  }
291
291
 
292
- // Create the file path by joining this directory with the filename
293
- const filePath = path.join(this.path, filename)
294
-
295
- return new FileObject(filePath)
292
+ // Pass the filename and this directory as parent
293
+ // This ensures the FileObject maintains the correct parent reference
294
+ return new FileObject(filename, this)
296
295
  }
297
296
 
298
297
  /**
@@ -393,7 +393,7 @@ export default class DirectoryObject extends FS {
393
393
 
394
394
  const files = found
395
395
  .filter(dirent => dirent.isFile())
396
- .map(dirent => new FileObject(path.join(this.path, dirent.name)))
396
+ .map(dirent => new FileObject(dirent.name, this))
397
397
 
398
398
  const directories = found
399
399
  .filter(dirent => dirent.isDirectory())
@@ -588,9 +588,8 @@ export default class DirectoryObject extends FS {
588
588
  getFile(filename) {
589
589
  Valid.type(filename, "String")
590
590
 
591
- const thisPath = this.path
592
- const merged = FS.mergeOverlappingPaths(thisPath, filename)
593
-
594
- return new FileObject(merged)
591
+ // Pass the filename and this directory as parent
592
+ // This ensures the FileObject maintains the correct parent reference
593
+ return new FileObject(filename, this)
595
594
  }
596
595
  }
package/src/lib/FS.js CHANGED
@@ -30,6 +30,26 @@ export default class FS {
30
30
  static upperFdTypes = upperFdTypes
31
31
  static fdType = fdType
32
32
 
33
+ /**
34
+ * Compute the relative path from another file or directory to this instance.
35
+ *
36
+ * If the target is outside the source (i.e., the relative path starts with ".."),
37
+ * returns the absolute path to this instance instead.
38
+ *
39
+ * @param {FileObject|DirectoryObject} fileOrDirectoryObject - The source file or directory object
40
+ * @returns {string} The relative path from the source to this instance, or the absolute path if not reachable
41
+ * @throws {Sass} If the parameter is not a FileObject or DirectoryObject
42
+ */
43
+ relativeTo(fileOrDirectoryObject) {
44
+ Valid.assert(
45
+ typeof fileOrDirectoryObject?.path === "string",
46
+ "fileOrDirectoryObject must be a FileObject or DirectoryObject with a path property",
47
+ 1
48
+ )
49
+
50
+ return FS.relativeOrAbsolutePath(fileOrDirectoryObject, this)
51
+ }
52
+
33
53
  /**
34
54
  * Fix slashes in a path
35
55
  *
@@ -110,13 +110,22 @@ export default class FileObject extends FS {
110
110
  const resolved = final
111
111
  const url = new URL(FS.pathToUri(resolved))
112
112
 
113
+ // Compute the actual parent directory from the resolved path
114
+ const actualParentPath = path.dirname(resolved)
115
+
116
+ // If the file is directly in the provided parent directory, reuse that object
117
+ // Otherwise, create a DirectoryObject for the actual parent directory
118
+ const actualParent = parentObject && actualParentPath === parentObject.path
119
+ ? parentObject
120
+ : new DirectoryObject(actualParentPath)
121
+
113
122
  this.#meta.supplied = fixedFile
114
123
  this.#meta.path = resolved
115
124
  this.#meta.url = url
116
125
  this.#meta.name = base
117
126
  this.#meta.extension = ext
118
127
  this.#meta.module = path.basename(this.supplied, this.extension)
119
- this.#meta.parent = parentObject
128
+ this.#meta.parent = actualParent
120
129
 
121
130
  Object.freeze(this.#meta)
122
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CappedDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/CappedDirectoryObject.js"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AACH;IAGE;;;;;;;;;;;;;;;;OAgBG;IACH,kBAXW,MAAM,OAAC,OACP,MAAM,WACN,qBAAqB,OAAC,cACtB,OAAO,EAkFjB;IAqBD;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IA8DD;;;;OAIG;IACH,cAFa,SAAS,CAAC,eAAe,CAAC,CAItC;IAED;;;;;;;;;;;;;;OAcG;IACH,sBAVW,MAAM,GACJ,qBAAqB,CA0BjC;;CA6CF;4BApS2B,sBAAsB"}
1
+ {"version":3,"file":"CappedDirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/CappedDirectoryObject.js"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AACH;IAGE;;;;;;;;;;;;;;;;OAgBG;IACH,kBAXW,MAAM,OAAC,OACP,MAAM,WACN,qBAAqB,OAAC,cACtB,OAAO,EAkFjB;IAqBD;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IA8DD;;;;OAIG;IACH,cAFa,SAAS,CAAC,eAAe,CAAC,CAItC;IAED;;;;;;;;;;;;;;OAcG;IACH,sBAVW,MAAM,GACJ,qBAAqB,CA0BjC;;CA4CF;4BAnS2B,sBAAsB"}
@@ -1 +1 @@
1
- {"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/DirectoryObject.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH;uBAqGe,MAAM;IAlEnB;;;;;OAKG;IACH,yCAFW,OAAO,EA6BjB;IAWD;;;;OAIG;IACH,UAFa,MAAM,CAclB;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,i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W,MAAM,GACJ,UAAU,CAkBtB;;CACF;eAtkBc,SAAS;uBACD,iBAAiB"}
@@ -71,6 +71,17 @@ export default class FS {
71
71
  * @returns {string} The resolved path
72
72
  */
73
73
  static resolvePath(fromPath: string, toPath: string): string;
74
+ /**
75
+ * Compute the relative path from another file or directory to this instance.
76
+ *
77
+ * If the target is outside the source (i.e., the relative path starts with ".."),
78
+ * returns the absolute path to this instance instead.
79
+ *
80
+ * @param {FileObject|DirectoryObject} fileOrDirectoryObject - The source file or directory object
81
+ * @returns {string} The relative path from the source to this instance, or the absolute path if not reachable
82
+ * @throws {Sass} If the parameter is not a FileObject or DirectoryObject
83
+ */
84
+ relativeTo(fileOrDirectoryObject: FileObject | DirectoryObject): string;
74
85
  }
75
86
  export type FileObject = import("./FileObject.js").default;
76
87
  export type DirectoryObject = import("./DirectoryObject.js").default;
@@ -1 +1 @@
1
- {"version":3,"file":"FS.d.ts","sourceRoot":"","sources":["../../lib/FS.js"],"names":[],"mappings":"AAwBA;;GAEG;AACH;IACE,kCAAwB;IACxB,uCAAkC;IAClC,mBAAsB;IAEtB;;;;;;OAMG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAUlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;;OAQG;IACH,sBALW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAClB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAmCtC;IAED;;;;;;;;;;OAUG;IACH,oCAJW,UAAU,GAAC,eAAe,MAC1B,UAAU,GAAC,eAAe,GACxB,MAAM,CAYlB;IAED;;;;;;;;OAQG;IACH,oCALW,MAAM,SACN,MAAM,QACN,MAAM,GACJ,MAAM,CA0BlB;IAED;;;;;;;;OAQG;IACH,6BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAgClB;CACF;yBAxMa,OAAO,iBAAiB,EAAE,OAAO;8BACjC,OAAO,sBAAsB,EAAE,OAAO"}
1
+ {"version":3,"file":"FS.d.ts","sourceRoot":"","sources":["../../lib/FS.js"],"names":[],"mappings":"AAwBA;;GAEG;AACH;IACE,kCAAwB;IACxB,uCAAkC;IAClC,mBAAsB;IAsBtB;;;;;;OAMG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAUlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;;OAQG;IACH,sBALW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAClB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAmCtC;IAED;;;;;;;;;;OAUG;IACH,oCAJW,UAAU,GAAC,eAAe,MAC1B,UAAU,GAAC,eAAe,GACxB,MAAM,CAYlB;IAED;;;;;;;;OAQG;IACH,oCALW,MAAM,SACN,MAAM,QACN,MAAM,GACJ,MAAM,CA0BlB;IAED;;;;;;;;OAQG;IACH,6BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAgClB;IA1MD;;;;;;;;;OASG;IACH,kCAJW,UAAU,GAAC,eAAe,GACxB,MAAM,CAWlB;CAyLF;yBA5Na,OAAO,iBAAiB,EAAE,OAAO;8BACjC,OAAO,sBAAsB,EAAE,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../lib/FileObject.js"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;GAcG;AAEH;uBAuHe,MAAM;IAtHnB;;;;;OAKG;IACH,yBAFU;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,CAAA;KAAC,CAO1D;IA2BF;;;;;OAKG;IACH,sBAHW,MAAM,GAAG,UAAU,WACnB,eAAe,GAAC,MAAM,GAAC,IAAI,EA2CrC;IAWD;;;;OA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