@gesslar/toolkit 3.16.1 → 3.19.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 +2 -2
- package/src/node/index.js +1 -1
- package/src/node/lib/DirectoryObject.js +59 -7
- package/src/node/lib/FileObject.js +37 -13
- package/src/node/lib/FileSystem.js +21 -30
- package/src/node/lib/VFileObject.js +3 -4
- package/types/node/index.d.ts +1 -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 +16 -1
- package/types/node/lib/FileObject.d.ts.map +1 -1
- package/types/node/lib/FileSystem.d.ts +13 -16
- package/types/node/lib/FileSystem.d.ts.map +1 -1
- package/types/node/lib/VFileObject.d.ts.map +1 -1
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.19.0",
|
|
9
9
|
"license": "Unlicense",
|
|
10
10
|
"homepage": "https://github.com/gesslar/toolkit#readme",
|
|
11
11
|
"repository": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@gesslar/uglier": "^0.6.0",
|
|
62
62
|
"eslint": "^9.39.2",
|
|
63
|
-
"happy-dom": "^20.0
|
|
63
|
+
"happy-dom": "^20.1.0",
|
|
64
64
|
"typescript": "^5.9.3"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
package/src/node/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export {default as Util} from "./lib/Util.js"
|
|
|
17
17
|
export {default as Cache} from "./lib/Cache.js"
|
|
18
18
|
export {default as DirectoryObject} from "./lib/DirectoryObject.js"
|
|
19
19
|
export {default as FileObject} from "./lib/FileObject.js"
|
|
20
|
-
export {default as
|
|
20
|
+
export {default as FileSystem} from "./lib/FileSystem.js"
|
|
21
21
|
export {default as Glog} from "./lib/Glog.js"
|
|
22
22
|
export {default as Notify} from "./lib/Notify.js"
|
|
23
23
|
export {default as TempDirectoryObject} from "./lib/TempDirectoryObject.js"
|
|
@@ -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,65 @@ 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
|
+
for(const e of found) {
|
|
372
|
+
if(e.isFile()) {
|
|
373
|
+
const {name, parentPath} = e
|
|
374
|
+
const resolved = FS.resolvePath(parentPath, name)
|
|
375
|
+
|
|
376
|
+
const file = virtual
|
|
377
|
+
? new VFileObject(path.relative(this.real.path, 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 relativePath = virtual
|
|
385
|
+
? path.relative(this.real.path, resolved)
|
|
386
|
+
: resolved
|
|
387
|
+
const directory = new this.constructor(relativePath, this)
|
|
388
|
+
|
|
389
|
+
directories.push(directory)
|
|
390
|
+
} else {
|
|
391
|
+
throw Sass.new(`wtf is this? ${e}`)
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return {files, directories}
|
|
396
|
+
}
|
|
397
|
+
|
|
346
398
|
/**
|
|
347
399
|
* Ensures a directory exists, creating it if necessary.
|
|
348
400
|
* Gracefully handles the case where the directory already exists.
|
|
@@ -69,6 +69,24 @@ export default class FileObject extends FS {
|
|
|
69
69
|
parentPath: null,
|
|
70
70
|
})
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Strip root from absolute path to make it relative.
|
|
74
|
+
* Used for virtual filesystem path resolution.
|
|
75
|
+
*
|
|
76
|
+
* @private
|
|
77
|
+
* @static
|
|
78
|
+
* @param {string} pathName - The path to convert
|
|
79
|
+
* @returns {string} Path with root stripped, or original if already relative
|
|
80
|
+
*/
|
|
81
|
+
static #absoluteToRelative(pathName) {
|
|
82
|
+
if(!path.isAbsolute(pathName))
|
|
83
|
+
return pathName
|
|
84
|
+
|
|
85
|
+
const {root} = FS.pathParts(pathName)
|
|
86
|
+
|
|
87
|
+
return Data.chopLeft(pathName, root)
|
|
88
|
+
}
|
|
89
|
+
|
|
72
90
|
/**
|
|
73
91
|
* Constructs a FileObject instance.
|
|
74
92
|
*
|
|
@@ -82,40 +100,41 @@ export default class FileObject extends FS {
|
|
|
82
100
|
Valid.type(parent, "Null|String|DirectoryObject", {allowEmpty: false})
|
|
83
101
|
|
|
84
102
|
const normalizedFile = FS.fixSlashes(submitted)
|
|
85
|
-
const
|
|
86
|
-
?
|
|
103
|
+
const absOrRelPath = path.isAbsolute(normalizedFile) && parent
|
|
104
|
+
? FileObject.#absoluteToRelative(normalizedFile)
|
|
87
105
|
: normalizedFile
|
|
88
|
-
const {dir, base, ext, name} = FS.pathParts(
|
|
106
|
+
const {dir, base, ext, name} = FS.pathParts(absOrRelPath)
|
|
89
107
|
|
|
90
108
|
const [parentObject, fullPath] = (() => {
|
|
91
109
|
if(Data.isType(parent, "String")) {
|
|
92
|
-
const
|
|
93
|
-
const {dir} = FS.pathParts(
|
|
110
|
+
const resolved = FS.resolvePath(parent, absOrRelPath)
|
|
111
|
+
const {dir} = FS.pathParts(resolved)
|
|
94
112
|
|
|
95
113
|
return [
|
|
96
114
|
new DirectoryObject(dir),
|
|
97
|
-
|
|
115
|
+
resolved,
|
|
98
116
|
]
|
|
99
117
|
}
|
|
100
118
|
|
|
101
119
|
if(Data.isType(parent, "DirectoryObject")) {
|
|
102
|
-
const
|
|
103
|
-
const
|
|
120
|
+
const parentPath = parent.path
|
|
121
|
+
const resolved = FS.resolvePath(parentPath, absOrRelPath)
|
|
122
|
+
const parts = FS.pathParts(resolved)
|
|
104
123
|
|
|
105
124
|
return [
|
|
106
|
-
parent.path === dir
|
|
125
|
+
parent.path === parts.dir
|
|
107
126
|
? parent
|
|
108
|
-
: new
|
|
109
|
-
|
|
127
|
+
: new parent.constructor(parts.dir, parent),
|
|
128
|
+
resolved,
|
|
110
129
|
]
|
|
111
130
|
}
|
|
112
131
|
|
|
113
132
|
const directory = new DirectoryObject(dir)
|
|
114
|
-
const
|
|
133
|
+
const resolved = FS.resolvePath(directory.path, absOrRelPath)
|
|
115
134
|
|
|
116
135
|
return [
|
|
117
136
|
directory,
|
|
118
|
-
|
|
137
|
+
resolved,
|
|
119
138
|
]
|
|
120
139
|
})()
|
|
121
140
|
|
|
@@ -236,6 +255,11 @@ export default class FileObject extends FS {
|
|
|
236
255
|
return this.#meta.parent
|
|
237
256
|
}
|
|
238
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Returns the absolute path of the parent directory.
|
|
260
|
+
*
|
|
261
|
+
* @returns {string} The parent directory path
|
|
262
|
+
*/
|
|
239
263
|
get parentPath() {
|
|
240
264
|
return this.#meta.parentPath
|
|
241
265
|
}
|
|
@@ -49,7 +49,7 @@ export default class FileSystem {
|
|
|
49
49
|
1
|
|
50
50
|
)
|
|
51
51
|
|
|
52
|
-
return FileSystem.
|
|
52
|
+
return FileSystem.relativeOrAbsolute(fileOrDirectoryObject, this)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
@@ -104,7 +104,7 @@ export default class FileSystem {
|
|
|
104
104
|
* @param {FileObject|DirectoryObject} to - The target file or directory object
|
|
105
105
|
* @returns {string} The relative path from `from` to `to`, or the absolute path if not reachable
|
|
106
106
|
*/
|
|
107
|
-
static
|
|
107
|
+
static relativeOrAbsolute(from, to) {
|
|
108
108
|
const fromBasePath = from.isDirectory
|
|
109
109
|
? from.path
|
|
110
110
|
: from.parent?.path ?? path.dirname(from.path)
|
|
@@ -116,6 +116,25 @@ export default class FileSystem {
|
|
|
116
116
|
: relative
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Computes the relative path from one file or directory to another.
|
|
121
|
+
*
|
|
122
|
+
* If the target is outside the source (i.e., the relative path starts with
|
|
123
|
+
* ".."), returns the absolute path to the target instead.
|
|
124
|
+
*
|
|
125
|
+
* @static
|
|
126
|
+
* @param {string} from - The source file or directory object
|
|
127
|
+
* @param {string} to - The target file or directory object
|
|
128
|
+
* @returns {string} The relative path from `from` to `to`, or the absolute path if not reachable
|
|
129
|
+
*/
|
|
130
|
+
static relativeOrAbsolutePath(from, to) {
|
|
131
|
+
const relative = path.relative(from, to)
|
|
132
|
+
|
|
133
|
+
return relative.startsWith("..")
|
|
134
|
+
? to
|
|
135
|
+
: relative
|
|
136
|
+
}
|
|
137
|
+
|
|
119
138
|
/**
|
|
120
139
|
* Merge two paths by finding overlapping segments and combining them
|
|
121
140
|
* efficiently
|
|
@@ -356,32 +375,4 @@ export default class FileSystem {
|
|
|
356
375
|
|
|
357
376
|
return this.resolvePath(cap, target)
|
|
358
377
|
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Convert an absolute path to a relative format by removing the root component.
|
|
362
|
-
* By default, keeps a leading separator (making it "absolute-like relative").
|
|
363
|
-
* Use forceActuallyRelative to get a truly relative path without leading separator.
|
|
364
|
-
*
|
|
365
|
-
* @static
|
|
366
|
-
* @param {string} pathToCheck - The path to convert (returned unchanged if already relative)
|
|
367
|
-
* @param {boolean} [forceActuallyRelative=false] - If true, removes leading separator for truly relative path
|
|
368
|
-
* @returns {string} The relative path (with or without leading separator based on forceActuallyRelative)
|
|
369
|
-
* @example
|
|
370
|
-
* FS.absoluteToRelative("/home/user/docs") // "/home/user/docs" (with leading /)
|
|
371
|
-
* FS.absoluteToRelative("/home/user/docs", true) // "home/user/docs" (truly relative)
|
|
372
|
-
* FS.absoluteToRelative("relative/path") // "relative/path" (unchanged)
|
|
373
|
-
*/
|
|
374
|
-
static absoluteToRelative(pathToCheck, forceActuallyRelative=false) {
|
|
375
|
-
if(!path.isAbsolute(pathToCheck))
|
|
376
|
-
return pathToCheck
|
|
377
|
-
|
|
378
|
-
const {root} = this.pathParts(pathToCheck)
|
|
379
|
-
const sep = path.sep
|
|
380
|
-
const chopped = Data.chopLeft(pathToCheck, root)
|
|
381
|
-
const absolute = forceActuallyRelative
|
|
382
|
-
? chopped
|
|
383
|
-
: Data.prepend(chopped, sep)
|
|
384
|
-
|
|
385
|
-
return absolute
|
|
386
|
-
}
|
|
387
378
|
}
|
|
@@ -44,11 +44,10 @@ export default class VFileObject extends FileObject {
|
|
|
44
44
|
super(fileName, parent)
|
|
45
45
|
|
|
46
46
|
const parentRealPath = this.parent.real.path
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const {base, dir} = FS.pathParts(resolved)
|
|
47
|
+
const resolved = FS.resolvePath(this.parent.path, fileName)
|
|
48
|
+
const {base} = FS.pathParts(resolved)
|
|
50
49
|
|
|
51
|
-
this.#real = new FileObject(base,
|
|
50
|
+
this.#real = new FileObject(base, parentRealPath)
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
get isVirtual() {
|
package/types/node/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { default as Util } from "./lib/Util.js";
|
|
|
10
10
|
export { default as Cache } from "./lib/Cache.js";
|
|
11
11
|
export { default as DirectoryObject } from "./lib/DirectoryObject.js";
|
|
12
12
|
export { default as FileObject } from "./lib/FileObject.js";
|
|
13
|
-
export { default as
|
|
13
|
+
export { default as FileSystem } from "./lib/FileSystem.js";
|
|
14
14
|
export { default as Glog } from "./lib/Glog.js";
|
|
15
15
|
export { default as Notify } from "./lib/Notify.js";
|
|
16
16
|
export { default as TempDirectoryObject } from "./lib/TempDirectoryObject.js";
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CA0CjH;IAED;;;;;;;;;;;;;;;;;;;OAmBG;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,CAgDjH;IAED;;;;;;;;;;;;OAYG;IACH,uBARW,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAuBzB;IAyBD;;;;;;;;;;;;;;;OAeG;IACH,cAZa,eAAe,CAc3B;IAED;;;;;;;;;;;;;;OAcG;IACH,UARa,OAAO,CAAC,IAAI,CAAC,CAkBzB;IAED;;;;;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;eA3kBc,iBAAiB;uBACT,iBAAiB;wBAGhB,kBAAkB"}
|
|
@@ -22,6 +22,16 @@ export default class FileObject extends FS {
|
|
|
22
22
|
static dataLoaderConfig: {
|
|
23
23
|
[key: string]: Array<typeof JSON5 | typeof YAML>;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Strip root from absolute path to make it relative.
|
|
27
|
+
* Used for virtual filesystem path resolution.
|
|
28
|
+
*
|
|
29
|
+
* @private
|
|
30
|
+
* @static
|
|
31
|
+
* @param {string} pathName - The path to convert
|
|
32
|
+
* @returns {string} Path with root stripped, or original if already relative
|
|
33
|
+
*/
|
|
34
|
+
private static "__#private@#absoluteToRelative";
|
|
25
35
|
/**
|
|
26
36
|
* Constructs a FileObject instance.
|
|
27
37
|
*
|
|
@@ -93,7 +103,12 @@ export default class FileObject extends FS {
|
|
|
93
103
|
* @returns {DirectoryObject} The parent directory object
|
|
94
104
|
*/
|
|
95
105
|
get parent(): DirectoryObject;
|
|
96
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Returns the absolute path of the parent directory.
|
|
108
|
+
*
|
|
109
|
+
* @returns {string} The parent directory path
|
|
110
|
+
*/
|
|
111
|
+
get parentPath(): string;
|
|
97
112
|
/**
|
|
98
113
|
* Check if a file can be read. Returns true if the file can be read, false
|
|
99
114
|
*
|
|
@@ -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,
|
|
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;;;;;;;;OAQG;IACH,gDAOC;IAED;;;;;OAKG;IACH,uBAHW,MAAM,WACN,eAAe,GAAC,MAAM,GAAC,IAAI,EA6DrC;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,CAAC,MAAM,CAAC,CAS3B;IAED;;;;;;;;;;;OAWG;IACH,cARa,OAAO,CAAC,MAAM,CAAC,CAe3B;IAED;;;;;;;;;;;OAWG;IACH,eARW,MAAM,aACN,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAiBzB;IAED;;;;;;;;;;;;;;;OAeG;IACH,kBAXW,WAAW,GAAC,IAAI,GAAC,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CAwBzB;IAED;;;;;;;;;;;;;;OAcG;IACH,gBAXW,MAAM,aACN,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAkC5B;IAED;;;;OAIG;IACH,UAFa,OAAO,CAAC,MAAM,CAAC,CAS3B;IAED;;;;;;;;;OASG;IACH,UAPa,OAAO,CAAC,IAAI,CAAC,CAczB;;CACF;eA/ec,iBAAiB;4BADJ,sBAAsB"}
|
|
@@ -40,7 +40,19 @@ export default class FileSystem {
|
|
|
40
40
|
* @param {FileObject|DirectoryObject} to - The target file or directory object
|
|
41
41
|
* @returns {string} The relative path from `from` to `to`, or the absolute path if not reachable
|
|
42
42
|
*/
|
|
43
|
-
static
|
|
43
|
+
static relativeOrAbsolute(from: FileObject | DirectoryObject, to: FileObject | DirectoryObject): string;
|
|
44
|
+
/**
|
|
45
|
+
* Computes the relative path from one file or directory to another.
|
|
46
|
+
*
|
|
47
|
+
* If the target is outside the source (i.e., the relative path starts with
|
|
48
|
+
* ".."), returns the absolute path to the target instead.
|
|
49
|
+
*
|
|
50
|
+
* @static
|
|
51
|
+
* @param {string} from - The source file or directory object
|
|
52
|
+
* @param {string} to - The target file or directory object
|
|
53
|
+
* @returns {string} The relative path from `from` to `to`, or the absolute path if not reachable
|
|
54
|
+
*/
|
|
55
|
+
static relativeOrAbsolutePath(from: string, to: string): string;
|
|
44
56
|
/**
|
|
45
57
|
* Merge two paths by finding overlapping segments and combining them
|
|
46
58
|
* efficiently
|
|
@@ -156,21 +168,6 @@ export default class FileSystem {
|
|
|
156
168
|
* FS.virtualToRealPath(regular) // "/home/user/file.txt"
|
|
157
169
|
*/
|
|
158
170
|
static virtualToRealPath(fileOrDirectoryObject: FileObject | DirectoryObject): string;
|
|
159
|
-
/**
|
|
160
|
-
* Convert an absolute path to a relative format by removing the root component.
|
|
161
|
-
* By default, keeps a leading separator (making it "absolute-like relative").
|
|
162
|
-
* Use forceActuallyRelative to get a truly relative path without leading separator.
|
|
163
|
-
*
|
|
164
|
-
* @static
|
|
165
|
-
* @param {string} pathToCheck - The path to convert (returned unchanged if already relative)
|
|
166
|
-
* @param {boolean} [forceActuallyRelative=false] - If true, removes leading separator for truly relative path
|
|
167
|
-
* @returns {string} The relative path (with or without leading separator based on forceActuallyRelative)
|
|
168
|
-
* @example
|
|
169
|
-
* FS.absoluteToRelative("/home/user/docs") // "/home/user/docs" (with leading /)
|
|
170
|
-
* FS.absoluteToRelative("/home/user/docs", true) // "home/user/docs" (truly relative)
|
|
171
|
-
* FS.absoluteToRelative("relative/path") // "relative/path" (unchanged)
|
|
172
|
-
*/
|
|
173
|
-
static absoluteToRelative(pathToCheck: string, forceActuallyRelative?: boolean): string;
|
|
174
171
|
/**
|
|
175
172
|
* Compute the relative path from another file or directory to this instance.
|
|
176
173
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileSystem.js"],"names":[],"mappings":"AA0BA;;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;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;;;;OAUG;IACH,
|
|
1
|
+
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileSystem.js"],"names":[],"mappings":"AA0BA;;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;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;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;;;;;OAKG;IAEH;;;;;;;OAOG;IACH,2BAJW,MAAM;;;;cATH,MAAM;;;;aACN,MAAM;;;;aACN,MAAM;MAenB;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,gDAZW,UAAU,GAAC,eAAe,GACxB,MAAM,CAiClB;IAtVD;;;;;;;;;OASG;IACH,kCAJW,UAAU,GAAC,eAAe,GACxB,MAAM,CAWlB;CAqUF;yBAxWa,OAAO,iBAAiB,EAAE,OAAO;8BACjC,OAAO,sBAAsB,EAAE,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VFileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/VFileObject.js"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;IAGE;;;;;OAKG;IACH,sBAHW,MAAM,UACN,gBAAgB,
|
|
1
|
+
{"version":3,"file":"VFileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/VFileObject.js"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;IAGE;;;;;OAKG;IACH,sBAHW,MAAM,UACN,gBAAgB,EAa1B;IAED,yBAEC;IAED,uBAEC;;CACF;uBArDsB,iBAAiB"}
|