@zthun/crumbtrail-fs 2.0.2 → 2.1.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.
@@ -9,6 +9,13 @@ export interface IZFileSystemSearchOptions {
9
9
  * If this is not set, then the cwd of the application is used.
10
10
  */
11
11
  cwd?: string;
12
+ /**
13
+ * A flag that determines whether or not to load the
14
+ * file system information.
15
+ *
16
+ * This is true by default.
17
+ */
18
+ stat?: boolean;
12
19
  }
13
20
  /**
14
21
  * Represents options for directory walking.
package/dist/index.cjs CHANGED
@@ -8,44 +8,6 @@ const promises = require('node:fs/promises');
8
8
  const node_path = require('node:path');
9
9
  const node_process = require('node:process');
10
10
 
11
- function _class_call_check$1(instance, Constructor) {
12
- if (!(instance instanceof Constructor)) {
13
- throw new TypeError("Cannot call a class as a function");
14
- }
15
- }
16
- function _defineProperties$1(target, props) {
17
- for(var i = 0; i < props.length; i++){
18
- var descriptor = props[i];
19
- descriptor.enumerable = descriptor.enumerable || false;
20
- descriptor.configurable = true;
21
- if ("value" in descriptor) descriptor.writable = true;
22
- Object.defineProperty(target, descriptor.key, descriptor);
23
- }
24
- }
25
- function _create_class$1(Constructor, protoProps, staticProps) {
26
- if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
27
- return Constructor;
28
- }
29
- function _define_property$1(obj, key, value) {
30
- if (key in obj) {
31
- Object.defineProperty(obj, key, {
32
- value: value,
33
- enumerable: true,
34
- configurable: true,
35
- writable: true
36
- });
37
- } else {
38
- obj[key] = value;
39
- }
40
- return obj;
41
- }
42
- function _instanceof(left, right) {
43
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
44
- return !!right[Symbol.hasInstance](left);
45
- } else {
46
- return left instanceof right;
47
- }
48
- }
49
11
  /**
50
12
  * Represents a type of a file system node.
51
13
  */ var ZFileSystemNodeType = /*#__PURE__*/ function(ZFileSystemNodeType) {
@@ -55,457 +17,90 @@ function _instanceof(left, right) {
55
17
  }({});
56
18
  /**
57
19
  * Represents a builder for a file system node.
58
- */ var ZFileSystemNodeBuilder = /*#__PURE__*/ function() {
59
- function ZFileSystemNodeBuilder() {
60
- _class_call_check$1(this, ZFileSystemNodeBuilder);
61
- _define_property$1(this, "_node", void 0);
62
- _define_property$1(this, "file", this.type.bind(this, "file"));
63
- _define_property$1(this, "folder", this.type.bind(this, "folder"));
20
+ */ class ZFileSystemNodeBuilder {
21
+ _node;
22
+ constructor(){
64
23
  this._node = {
65
24
  path: "/",
66
25
  type: "folder"
67
26
  };
68
27
  }
69
- _create_class$1(ZFileSystemNodeBuilder, [
70
- {
71
- key: "created",
72
- value: function created(at) {
73
- this._node.created = _instanceof(at, Date) ? at.toJSON() : at;
74
- return this;
75
- }
76
- },
77
- {
78
- key: "updated",
79
- value: function updated(at) {
80
- this._node.updated = _instanceof(at, Date) ? at.toJSON() : at;
81
- return this;
82
- }
83
- },
84
- {
85
- key: "size",
86
- value: function size(bytes) {
87
- this._node.size = typeof bytes == "number" ? BigInt(bytes) : bytes;
88
- return this;
89
- }
90
- },
91
- {
92
- key: "path",
93
- value: function path(path) {
94
- this._node.path = path;
95
- return this;
96
- }
97
- },
98
- {
99
- key: "type",
100
- value: function type(type) {
101
- this._node.type = type;
102
- return this;
103
- }
104
- },
105
- {
106
- key: "build",
107
- value: function build() {
108
- var clone = structuredClone(this._node);
109
- return lodashEs.omitBy(clone, lodashEs.isUndefined);
110
- }
111
- }
112
- ]);
113
- return ZFileSystemNodeBuilder;
114
- }();
115
-
116
- function _array_like_to_array(arr, len) {
117
- if (len == null || len > arr.length) len = arr.length;
118
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
119
- return arr2;
120
- }
121
- function _array_with_holes(arr) {
122
- if (Array.isArray(arr)) return arr;
123
- }
124
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
125
- try {
126
- var info = gen[key](arg);
127
- var value = info.value;
128
- } catch (error) {
129
- reject(error);
130
- return;
28
+ created(at) {
29
+ this._node.created = at instanceof Date ? at.toJSON() : at;
30
+ return this;
131
31
  }
132
- if (info.done) {
133
- resolve(value);
134
- } else {
135
- Promise.resolve(value).then(_next, _throw);
32
+ updated(at) {
33
+ this._node.updated = at instanceof Date ? at.toJSON() : at;
34
+ return this;
136
35
  }
137
- }
138
- function _async_to_generator(fn) {
139
- return function() {
140
- var self = this, args = arguments;
141
- return new Promise(function(resolve, reject) {
142
- var gen = fn.apply(self, args);
143
- function _next(value) {
144
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
145
- }
146
- function _throw(err) {
147
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
148
- }
149
- _next(undefined);
150
- });
151
- };
152
- }
153
- function _class_call_check(instance, Constructor) {
154
- if (!(instance instanceof Constructor)) {
155
- throw new TypeError("Cannot call a class as a function");
36
+ size(bytes) {
37
+ this._node.size = typeof bytes == "number" ? BigInt(bytes) : bytes;
38
+ return this;
156
39
  }
157
- }
158
- function _defineProperties(target, props) {
159
- for(var i = 0; i < props.length; i++){
160
- var descriptor = props[i];
161
- descriptor.enumerable = descriptor.enumerable || false;
162
- descriptor.configurable = true;
163
- if ("value" in descriptor) descriptor.writable = true;
164
- Object.defineProperty(target, descriptor.key, descriptor);
40
+ path(path) {
41
+ this._node.path = path;
42
+ return this;
165
43
  }
166
- }
167
- function _create_class(Constructor, protoProps, staticProps) {
168
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
169
- return Constructor;
170
- }
171
- function _define_property(obj, key, value) {
172
- if (key in obj) {
173
- Object.defineProperty(obj, key, {
174
- value: value,
175
- enumerable: true,
176
- configurable: true,
177
- writable: true
178
- });
179
- } else {
180
- obj[key] = value;
44
+ type(type) {
45
+ this._node.type = type;
46
+ return this;
181
47
  }
182
- return obj;
183
- }
184
- function _iterable_to_array_limit(arr, i) {
185
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
186
- if (_i == null) return;
187
- var _arr = [];
188
- var _n = true;
189
- var _d = false;
190
- var _s, _e;
191
- try {
192
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
193
- _arr.push(_s.value);
194
- if (i && _arr.length === i) break;
195
- }
196
- } catch (err) {
197
- _d = true;
198
- _e = err;
199
- } finally{
200
- try {
201
- if (!_n && _i["return"] != null) _i["return"]();
202
- } finally{
203
- if (_d) throw _e;
204
- }
48
+ file = this.type.bind(this, "file");
49
+ folder = this.type.bind(this, "folder");
50
+ build() {
51
+ const clone = structuredClone(this._node);
52
+ return lodashEs.omitBy(clone, lodashEs.isUndefined);
205
53
  }
206
- return _arr;
207
54
  }
208
- function _non_iterable_rest() {
209
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
210
- }
211
- function _object_spread(target) {
212
- for(var i = 1; i < arguments.length; i++){
213
- var source = arguments[i] != null ? arguments[i] : {};
214
- var ownKeys = Object.keys(source);
215
- if (typeof Object.getOwnPropertySymbols === "function") {
216
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
217
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
218
- }));
219
- }
220
- ownKeys.forEach(function(key) {
221
- _define_property(target, key, source[key]);
55
+
56
+ /**
57
+ * Represents a node implementation of a file system service.
58
+ */ class ZFileSystemService {
59
+ async info(path) {
60
+ const [file] = await this.search(path);
61
+ return file;
62
+ }
63
+ async search(pattern, options) {
64
+ const paths = await glob.glob(pattern, {
65
+ stat: true,
66
+ ...options,
67
+ withFileTypes: true
222
68
  });
223
- }
224
- return target;
225
- }
226
- function ownKeys(object, enumerableOnly) {
227
- var keys = Object.keys(object);
228
- if (Object.getOwnPropertySymbols) {
229
- var symbols = Object.getOwnPropertySymbols(object);
230
- keys.push.apply(keys, symbols);
231
- }
232
- return keys;
233
- }
234
- function _object_spread_props(target, source) {
235
- source = source != null ? source : {};
236
- if (Object.getOwnPropertyDescriptors) {
237
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
238
- } else {
239
- ownKeys(Object(source)).forEach(function(key) {
240
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
69
+ return paths.map((path)=>{
70
+ let info = new ZFileSystemNodeBuilder().path(path.fullpath()).created(path.birthtime).updated(path.atime).size(path.size);
71
+ // Note that for folders, node will return the size of the underlying OS metadata,
72
+ // hence, why we remove the size on the folder here.
73
+ info = path.isFile() ? info.file() : info.folder().size(undefined);
74
+ return info.build();
241
75
  });
242
76
  }
243
- return target;
244
- }
245
- function _sliced_to_array(arr, i) {
246
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
247
- }
248
- function _unsupported_iterable_to_array(o, minLen) {
249
- if (!o) return;
250
- if (typeof o === "string") return _array_like_to_array(o, minLen);
251
- var n = Object.prototype.toString.call(o).slice(8, -1);
252
- if (n === "Object" && o.constructor) n = o.constructor.name;
253
- if (n === "Map" || n === "Set") return Array.from(n);
254
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
255
- }
256
- function _ts_generator(thisArg, body) {
257
- var f, y, t, _ = {
258
- label: 0,
259
- sent: function() {
260
- if (t[0] & 1) throw t[1];
261
- return t[1];
262
- },
263
- trys: [],
264
- ops: []
265
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
266
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
267
- return this;
268
- }), g;
269
- function verb(n) {
270
- return function(v) {
271
- return step([
272
- n,
273
- v
274
- ]);
275
- };
276
- }
277
- function step(op) {
278
- if (f) throw new TypeError("Generator is already executing.");
279
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
280
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
281
- if (y = 0, t) op = [
282
- op[0] & 2,
283
- t.value
284
- ];
285
- switch(op[0]){
286
- case 0:
287
- case 1:
288
- t = op;
289
- break;
290
- case 4:
291
- _.label++;
292
- return {
293
- value: op[1],
294
- done: false
295
- };
296
- case 5:
297
- _.label++;
298
- y = op[1];
299
- op = [
300
- 0
301
- ];
302
- continue;
303
- case 7:
304
- op = _.ops.pop();
305
- _.trys.pop();
306
- continue;
307
- default:
308
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
309
- _ = 0;
310
- continue;
311
- }
312
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
313
- _.label = op[1];
314
- break;
315
- }
316
- if (op[0] === 6 && _.label < t[1]) {
317
- _.label = t[1];
318
- t = op;
319
- break;
320
- }
321
- if (t && _.label < t[2]) {
322
- _.label = t[2];
323
- _.ops.push(op);
324
- break;
325
- }
326
- if (t[2]) _.ops.pop();
327
- _.trys.pop();
328
- continue;
77
+ async walk(search, options) {
78
+ const start = options?.start || node_process.cwd();
79
+ const stop = options?.stop || "/";
80
+ const mode = options?.mode;
81
+ const _test = async (path)=>{
82
+ try {
83
+ await promises.access(path, mode);
84
+ return true;
85
+ } catch {
86
+ return false;
329
87
  }
330
- op = body.call(thisArg, _);
331
- } catch (e) {
332
- op = [
333
- 6,
334
- e
335
- ];
336
- y = 0;
337
- } finally{
338
- f = t = 0;
339
- }
340
- if (op[0] & 5) throw op[1];
341
- return {
342
- value: op[0] ? op[1] : void 0,
343
- done: true
344
88
  };
89
+ if (node_path.isAbsolute(search)) {
90
+ return await _test(search) ? search : null;
91
+ }
92
+ let dir = start;
93
+ do {
94
+ const path = node_path.resolve(dir, search);
95
+ const exists = await _test(path);
96
+ if (exists) {
97
+ return path;
98
+ }
99
+ dir = dir === stop ? "" : node_path.dirname(dir);
100
+ }while (dir.length)
101
+ return null;
345
102
  }
346
103
  }
347
- /**
348
- * Represents a node implementation of a file system service.
349
- */ var ZFileSystemService = /*#__PURE__*/ function() {
350
- function ZFileSystemService() {
351
- _class_call_check(this, ZFileSystemService);
352
- }
353
- _create_class(ZFileSystemService, [
354
- {
355
- key: "info",
356
- value: function info(path) {
357
- return _async_to_generator(function() {
358
- var _ref, file;
359
- return _ts_generator(this, function(_state) {
360
- switch(_state.label){
361
- case 0:
362
- return [
363
- 4,
364
- this.search(path)
365
- ];
366
- case 1:
367
- _ref = _sliced_to_array.apply(void 0, [
368
- _state.sent(),
369
- 1
370
- ]), file = _ref[0];
371
- return [
372
- 2,
373
- file
374
- ];
375
- }
376
- });
377
- }).call(this);
378
- }
379
- },
380
- {
381
- key: "search",
382
- value: function search(pattern, options) {
383
- return _async_to_generator(function() {
384
- var paths;
385
- return _ts_generator(this, function(_state) {
386
- switch(_state.label){
387
- case 0:
388
- return [
389
- 4,
390
- glob.glob(pattern, _object_spread_props(_object_spread({}, options), {
391
- stat: true,
392
- withFileTypes: true
393
- }))
394
- ];
395
- case 1:
396
- paths = _state.sent();
397
- return [
398
- 2,
399
- paths.map(function(path) {
400
- var info = new ZFileSystemNodeBuilder().path(path.fullpath()).created(path.birthtime).updated(path.atime).size(path.size);
401
- // Note that for folders, node will return the size of the underlying OS metadata,
402
- // hence, why we 0 out the size on a folder here.
403
- info = path.isFile() ? info.file() : info.folder().size(undefined);
404
- return info.build();
405
- })
406
- ];
407
- }
408
- });
409
- })();
410
- }
411
- },
412
- {
413
- key: "walk",
414
- value: function walk(search, options) {
415
- return _async_to_generator(function() {
416
- var start, stop, mode, _test, dir, path, exists;
417
- return _ts_generator(this, function(_state) {
418
- switch(_state.label){
419
- case 0:
420
- start = (options === null || options === void 0 ? void 0 : options.start) || node_process.cwd();
421
- stop = (options === null || options === void 0 ? void 0 : options.stop) || "/";
422
- mode = options === null || options === void 0 ? void 0 : options.mode;
423
- _test = function(path) {
424
- return _async_to_generator(function() {
425
- return _ts_generator(this, function(_state) {
426
- switch(_state.label){
427
- case 0:
428
- _state.trys.push([
429
- 0,
430
- 2,
431
- ,
432
- 3
433
- ]);
434
- return [
435
- 4,
436
- promises.access(path, mode)
437
- ];
438
- case 1:
439
- _state.sent();
440
- return [
441
- 2,
442
- true
443
- ];
444
- case 2:
445
- _state.sent();
446
- return [
447
- 2,
448
- false
449
- ];
450
- case 3:
451
- return [
452
- 2
453
- ];
454
- }
455
- });
456
- })();
457
- };
458
- if (!node_path.isAbsolute(search)) return [
459
- 3,
460
- 2
461
- ];
462
- return [
463
- 4,
464
- _test(search)
465
- ];
466
- case 1:
467
- return [
468
- 2,
469
- _state.sent() ? search : null
470
- ];
471
- case 2:
472
- dir = start;
473
- _state.label = 3;
474
- case 3:
475
- path = node_path.resolve(dir, search);
476
- return [
477
- 4,
478
- _test(path)
479
- ];
480
- case 4:
481
- exists = _state.sent();
482
- if (exists) {
483
- return [
484
- 2,
485
- path
486
- ];
487
- }
488
- dir = dir === stop ? "" : node_path.dirname(dir);
489
- _state.label = 5;
490
- case 5:
491
- if (dir.length) return [
492
- 3,
493
- 3
494
- ];
495
- _state.label = 6;
496
- case 6:
497
- return [
498
- 2,
499
- null
500
- ];
501
- }
502
- });
503
- })();
504
- }
505
- }
506
- ]);
507
- return ZFileSystemService;
508
- }();
509
104
 
510
105
  exports.ZFileSystemNodeBuilder = ZFileSystemNodeBuilder;
511
106
  exports.ZFileSystemNodeType = ZFileSystemNodeType;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts"],"sourcesContent":["import { isUndefined, omitBy } from \"lodash-es\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: IZFileSystemNode;\n\n public constructor() {\n this._node = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n };\n }\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n return this;\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n return this;\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public build() {\n const clone = structuredClone(this._node);\n return omitBy<IZFileSystemNode>(clone, isUndefined) as IZFileSystemNode;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string,\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n ...options,\n stat: true,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we 0 out the size on a folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","_define_property","_node","file","type","bind","folder","path","created","at","Date","toJSON","updated","size","bytes","BigInt","build","clone","structuredClone","omitBy","isUndefined","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","birthtime","atime","isFile","undefined","walk","start","stop","mode","_test","dir","exists","cwd","access","isAbsolute","resolve","dirname","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;IAGO,IAAKA,mBAAAA,iBAAAA,SAAAA,mBAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,mBAAAA;AAGX,CAAA,CAAA,EAAA;AA6BD;;IAGO,IAAMC,sBAAAA,iBAAN,WAAA;AAAMA,IAAAA,SAAAA,sBAAAA,GAAAA;AAAAA,QAAAA,mBAAAA,CAAAA,IAAAA,EAAAA,sBAAAA,CAAAA;AACX,QAAAC,kBAAA,CAAA,IAAA,EAAQC,SAAR,MAAA,CAAA;AAkCA,QAAAD,kBAAA,CAAA,IAAA,EAAOE,QAAO,IAAI,CAACC,IAAI,CAACC,IAAI,CAAC,IAAI,EAAA,MAAA,CAAA,CAAA;AACjC,QAAAJ,kBAAA,CAAA,IAAA,EAAOK,UAAS,IAAI,CAACF,IAAI,CAACC,IAAI,CAAC,IAAI,EAAA,QAAA,CAAA,CAAA;QAhCjC,IAA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../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts"],"sourcesContent":["import { isUndefined, omitBy } from \"lodash-es\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: IZFileSystemNode;\n\n public constructor() {\n this._node = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n };\n }\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n return this;\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n return this;\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public build() {\n const clone = structuredClone(this._node);\n return omitBy(clone, isUndefined) as IZFileSystemNode;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n\n /**\n * A flag that determines whether or not to load the\n * file system information.\n *\n * This is true by default.\n */\n stat?: boolean;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string,\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n stat: true,\n ...options,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we remove the size on the folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","_node","path","type","created","at","Date","toJSON","updated","size","bytes","BigInt","file","bind","folder","build","clone","structuredClone","omitBy","isUndefined","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","birthtime","atime","isFile","undefined","walk","start","cwd","stop","mode","_test","access","isAbsolute","dir","resolve","exists","dirname","length"],"mappings":";;;;;;;;;;AAEA;;IAGO,IAAKA,mBAAAA,iBAAAA,SAAAA,mBAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,mBAAAA;AAGX,CAAA,CAAA,EAAA;AA6BD;;AAEC,IACM,MAAMC,sBAAAA,CAAAA;IACHC,KAAAA;IAER,WAAA,EAAqB;QACnB,IAAI,CAACA,KAAK,GAAG;YACXC,IAAAA,EAAM,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AACF,gBAAA,MAAMuC,gBAAOvC,IAAAA,EAAMqC,IAAAA,CAAAA;gBACnB,OAAO,IAAA;AACT,YAAA,CAAA,CAAE,OAAM;gBACN,OAAO,KAAA;AACT,YAAA;AACF,QAAA,CAAA;AAEA,QAAA,IAAIG,qBAAWpB,MAAAA,CAAAA,EAAS;AACtB,YAAA,OAAO,MAAOkB,KAAAA,CAAMlB,MAAAA,CAAAA,GAAWA,MAAAA,GAAS,IAAA;AAC1C,QAAA;AAEA,QAAA,IAAIqB,GAAAA,GAAMP,KAAAA;QACV,GAAG;YACD,MAAMlC,IAAAA,GAAO0C,kBAAQD,GAAAA,EAAKrB,MAAAA,CAAAA;YAC1B,MAAMuB,MAAAA,GAAS,MAAML,KAAAA,CAAMtC,IAAAA,CAAAA;AAE3B,YAAA,IAAI2C,MAAAA,EAAQ;gBACV,OAAO3C,IAAAA;AACT,YAAA;YAEAyC,GAAAA,GAAMA,GAAAA,KAAQL,IAAAA,GAAO,EAAA,GAAKQ,iBAAAA,CAAQH,GAAAA,CAAAA;QACpC,CAAA,OAASA,GAAAA,CAAII,MAAM;QAEnB,OAAO,IAAA;AACT,IAAA;AACF;;;;;;"}
package/dist/index.js CHANGED
@@ -1,47 +1,9 @@
1
1
  import { omitBy, isUndefined } from 'lodash-es';
2
2
  import { glob } from 'glob';
3
3
  import { access } from 'node:fs/promises';
4
- import { dirname, resolve, isAbsolute } from 'node:path';
4
+ import { isAbsolute, resolve, dirname } from 'node:path';
5
5
  import { cwd } from 'node:process';
6
6
 
7
- function _class_call_check$1(instance, Constructor) {
8
- if (!(instance instanceof Constructor)) {
9
- throw new TypeError("Cannot call a class as a function");
10
- }
11
- }
12
- function _defineProperties$1(target, props) {
13
- for(var i = 0; i < props.length; i++){
14
- var descriptor = props[i];
15
- descriptor.enumerable = descriptor.enumerable || false;
16
- descriptor.configurable = true;
17
- if ("value" in descriptor) descriptor.writable = true;
18
- Object.defineProperty(target, descriptor.key, descriptor);
19
- }
20
- }
21
- function _create_class$1(Constructor, protoProps, staticProps) {
22
- if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
23
- return Constructor;
24
- }
25
- function _define_property$1(obj, key, value) {
26
- if (key in obj) {
27
- Object.defineProperty(obj, key, {
28
- value: value,
29
- enumerable: true,
30
- configurable: true,
31
- writable: true
32
- });
33
- } else {
34
- obj[key] = value;
35
- }
36
- return obj;
37
- }
38
- function _instanceof(left, right) {
39
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
40
- return !!right[Symbol.hasInstance](left);
41
- } else {
42
- return left instanceof right;
43
- }
44
- }
45
7
  /**
46
8
  * Represents a type of a file system node.
47
9
  */ var ZFileSystemNodeType = /*#__PURE__*/ function(ZFileSystemNodeType) {
@@ -51,457 +13,90 @@ function _instanceof(left, right) {
51
13
  }({});
52
14
  /**
53
15
  * Represents a builder for a file system node.
54
- */ var ZFileSystemNodeBuilder = /*#__PURE__*/ function() {
55
- function ZFileSystemNodeBuilder() {
56
- _class_call_check$1(this, ZFileSystemNodeBuilder);
57
- _define_property$1(this, "_node", void 0);
58
- _define_property$1(this, "file", this.type.bind(this, "file"));
59
- _define_property$1(this, "folder", this.type.bind(this, "folder"));
16
+ */ class ZFileSystemNodeBuilder {
17
+ _node;
18
+ constructor(){
60
19
  this._node = {
61
20
  path: "/",
62
21
  type: "folder"
63
22
  };
64
23
  }
65
- _create_class$1(ZFileSystemNodeBuilder, [
66
- {
67
- key: "created",
68
- value: function created(at) {
69
- this._node.created = _instanceof(at, Date) ? at.toJSON() : at;
70
- return this;
71
- }
72
- },
73
- {
74
- key: "updated",
75
- value: function updated(at) {
76
- this._node.updated = _instanceof(at, Date) ? at.toJSON() : at;
77
- return this;
78
- }
79
- },
80
- {
81
- key: "size",
82
- value: function size(bytes) {
83
- this._node.size = typeof bytes == "number" ? BigInt(bytes) : bytes;
84
- return this;
85
- }
86
- },
87
- {
88
- key: "path",
89
- value: function path(path) {
90
- this._node.path = path;
91
- return this;
92
- }
93
- },
94
- {
95
- key: "type",
96
- value: function type(type) {
97
- this._node.type = type;
98
- return this;
99
- }
100
- },
101
- {
102
- key: "build",
103
- value: function build() {
104
- var clone = structuredClone(this._node);
105
- return omitBy(clone, isUndefined);
106
- }
107
- }
108
- ]);
109
- return ZFileSystemNodeBuilder;
110
- }();
111
-
112
- function _array_like_to_array(arr, len) {
113
- if (len == null || len > arr.length) len = arr.length;
114
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
115
- return arr2;
116
- }
117
- function _array_with_holes(arr) {
118
- if (Array.isArray(arr)) return arr;
119
- }
120
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
121
- try {
122
- var info = gen[key](arg);
123
- var value = info.value;
124
- } catch (error) {
125
- reject(error);
126
- return;
24
+ created(at) {
25
+ this._node.created = at instanceof Date ? at.toJSON() : at;
26
+ return this;
127
27
  }
128
- if (info.done) {
129
- resolve(value);
130
- } else {
131
- Promise.resolve(value).then(_next, _throw);
28
+ updated(at) {
29
+ this._node.updated = at instanceof Date ? at.toJSON() : at;
30
+ return this;
132
31
  }
133
- }
134
- function _async_to_generator(fn) {
135
- return function() {
136
- var self = this, args = arguments;
137
- return new Promise(function(resolve, reject) {
138
- var gen = fn.apply(self, args);
139
- function _next(value) {
140
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
141
- }
142
- function _throw(err) {
143
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
144
- }
145
- _next(undefined);
146
- });
147
- };
148
- }
149
- function _class_call_check(instance, Constructor) {
150
- if (!(instance instanceof Constructor)) {
151
- throw new TypeError("Cannot call a class as a function");
32
+ size(bytes) {
33
+ this._node.size = typeof bytes == "number" ? BigInt(bytes) : bytes;
34
+ return this;
152
35
  }
153
- }
154
- function _defineProperties(target, props) {
155
- for(var i = 0; i < props.length; i++){
156
- var descriptor = props[i];
157
- descriptor.enumerable = descriptor.enumerable || false;
158
- descriptor.configurable = true;
159
- if ("value" in descriptor) descriptor.writable = true;
160
- Object.defineProperty(target, descriptor.key, descriptor);
36
+ path(path) {
37
+ this._node.path = path;
38
+ return this;
161
39
  }
162
- }
163
- function _create_class(Constructor, protoProps, staticProps) {
164
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
165
- return Constructor;
166
- }
167
- function _define_property(obj, key, value) {
168
- if (key in obj) {
169
- Object.defineProperty(obj, key, {
170
- value: value,
171
- enumerable: true,
172
- configurable: true,
173
- writable: true
174
- });
175
- } else {
176
- obj[key] = value;
40
+ type(type) {
41
+ this._node.type = type;
42
+ return this;
177
43
  }
178
- return obj;
179
- }
180
- function _iterable_to_array_limit(arr, i) {
181
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
182
- if (_i == null) return;
183
- var _arr = [];
184
- var _n = true;
185
- var _d = false;
186
- var _s, _e;
187
- try {
188
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
189
- _arr.push(_s.value);
190
- if (i && _arr.length === i) break;
191
- }
192
- } catch (err) {
193
- _d = true;
194
- _e = err;
195
- } finally{
196
- try {
197
- if (!_n && _i["return"] != null) _i["return"]();
198
- } finally{
199
- if (_d) throw _e;
200
- }
44
+ file = this.type.bind(this, "file");
45
+ folder = this.type.bind(this, "folder");
46
+ build() {
47
+ const clone = structuredClone(this._node);
48
+ return omitBy(clone, isUndefined);
201
49
  }
202
- return _arr;
203
50
  }
204
- function _non_iterable_rest() {
205
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
206
- }
207
- function _object_spread(target) {
208
- for(var i = 1; i < arguments.length; i++){
209
- var source = arguments[i] != null ? arguments[i] : {};
210
- var ownKeys = Object.keys(source);
211
- if (typeof Object.getOwnPropertySymbols === "function") {
212
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
213
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
214
- }));
215
- }
216
- ownKeys.forEach(function(key) {
217
- _define_property(target, key, source[key]);
51
+
52
+ /**
53
+ * Represents a node implementation of a file system service.
54
+ */ class ZFileSystemService {
55
+ async info(path) {
56
+ const [file] = await this.search(path);
57
+ return file;
58
+ }
59
+ async search(pattern, options) {
60
+ const paths = await glob(pattern, {
61
+ stat: true,
62
+ ...options,
63
+ withFileTypes: true
218
64
  });
219
- }
220
- return target;
221
- }
222
- function ownKeys(object, enumerableOnly) {
223
- var keys = Object.keys(object);
224
- if (Object.getOwnPropertySymbols) {
225
- var symbols = Object.getOwnPropertySymbols(object);
226
- keys.push.apply(keys, symbols);
227
- }
228
- return keys;
229
- }
230
- function _object_spread_props(target, source) {
231
- source = source != null ? source : {};
232
- if (Object.getOwnPropertyDescriptors) {
233
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
234
- } else {
235
- ownKeys(Object(source)).forEach(function(key) {
236
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
65
+ return paths.map((path)=>{
66
+ let info = new ZFileSystemNodeBuilder().path(path.fullpath()).created(path.birthtime).updated(path.atime).size(path.size);
67
+ // Note that for folders, node will return the size of the underlying OS metadata,
68
+ // hence, why we remove the size on the folder here.
69
+ info = path.isFile() ? info.file() : info.folder().size(undefined);
70
+ return info.build();
237
71
  });
238
72
  }
239
- return target;
240
- }
241
- function _sliced_to_array(arr, i) {
242
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
243
- }
244
- function _unsupported_iterable_to_array(o, minLen) {
245
- if (!o) return;
246
- if (typeof o === "string") return _array_like_to_array(o, minLen);
247
- var n = Object.prototype.toString.call(o).slice(8, -1);
248
- if (n === "Object" && o.constructor) n = o.constructor.name;
249
- if (n === "Map" || n === "Set") return Array.from(n);
250
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
251
- }
252
- function _ts_generator(thisArg, body) {
253
- var f, y, t, _ = {
254
- label: 0,
255
- sent: function() {
256
- if (t[0] & 1) throw t[1];
257
- return t[1];
258
- },
259
- trys: [],
260
- ops: []
261
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
262
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
263
- return this;
264
- }), g;
265
- function verb(n) {
266
- return function(v) {
267
- return step([
268
- n,
269
- v
270
- ]);
271
- };
272
- }
273
- function step(op) {
274
- if (f) throw new TypeError("Generator is already executing.");
275
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
276
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
277
- if (y = 0, t) op = [
278
- op[0] & 2,
279
- t.value
280
- ];
281
- switch(op[0]){
282
- case 0:
283
- case 1:
284
- t = op;
285
- break;
286
- case 4:
287
- _.label++;
288
- return {
289
- value: op[1],
290
- done: false
291
- };
292
- case 5:
293
- _.label++;
294
- y = op[1];
295
- op = [
296
- 0
297
- ];
298
- continue;
299
- case 7:
300
- op = _.ops.pop();
301
- _.trys.pop();
302
- continue;
303
- default:
304
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
305
- _ = 0;
306
- continue;
307
- }
308
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
309
- _.label = op[1];
310
- break;
311
- }
312
- if (op[0] === 6 && _.label < t[1]) {
313
- _.label = t[1];
314
- t = op;
315
- break;
316
- }
317
- if (t && _.label < t[2]) {
318
- _.label = t[2];
319
- _.ops.push(op);
320
- break;
321
- }
322
- if (t[2]) _.ops.pop();
323
- _.trys.pop();
324
- continue;
73
+ async walk(search, options) {
74
+ const start = options?.start || cwd();
75
+ const stop = options?.stop || "/";
76
+ const mode = options?.mode;
77
+ const _test = async (path)=>{
78
+ try {
79
+ await access(path, mode);
80
+ return true;
81
+ } catch {
82
+ return false;
325
83
  }
326
- op = body.call(thisArg, _);
327
- } catch (e) {
328
- op = [
329
- 6,
330
- e
331
- ];
332
- y = 0;
333
- } finally{
334
- f = t = 0;
335
- }
336
- if (op[0] & 5) throw op[1];
337
- return {
338
- value: op[0] ? op[1] : void 0,
339
- done: true
340
84
  };
85
+ if (isAbsolute(search)) {
86
+ return await _test(search) ? search : null;
87
+ }
88
+ let dir = start;
89
+ do {
90
+ const path = resolve(dir, search);
91
+ const exists = await _test(path);
92
+ if (exists) {
93
+ return path;
94
+ }
95
+ dir = dir === stop ? "" : dirname(dir);
96
+ }while (dir.length)
97
+ return null;
341
98
  }
342
99
  }
343
- /**
344
- * Represents a node implementation of a file system service.
345
- */ var ZFileSystemService = /*#__PURE__*/ function() {
346
- function ZFileSystemService() {
347
- _class_call_check(this, ZFileSystemService);
348
- }
349
- _create_class(ZFileSystemService, [
350
- {
351
- key: "info",
352
- value: function info(path) {
353
- return _async_to_generator(function() {
354
- var _ref, file;
355
- return _ts_generator(this, function(_state) {
356
- switch(_state.label){
357
- case 0:
358
- return [
359
- 4,
360
- this.search(path)
361
- ];
362
- case 1:
363
- _ref = _sliced_to_array.apply(void 0, [
364
- _state.sent(),
365
- 1
366
- ]), file = _ref[0];
367
- return [
368
- 2,
369
- file
370
- ];
371
- }
372
- });
373
- }).call(this);
374
- }
375
- },
376
- {
377
- key: "search",
378
- value: function search(pattern, options) {
379
- return _async_to_generator(function() {
380
- var paths;
381
- return _ts_generator(this, function(_state) {
382
- switch(_state.label){
383
- case 0:
384
- return [
385
- 4,
386
- glob(pattern, _object_spread_props(_object_spread({}, options), {
387
- stat: true,
388
- withFileTypes: true
389
- }))
390
- ];
391
- case 1:
392
- paths = _state.sent();
393
- return [
394
- 2,
395
- paths.map(function(path) {
396
- var info = new ZFileSystemNodeBuilder().path(path.fullpath()).created(path.birthtime).updated(path.atime).size(path.size);
397
- // Note that for folders, node will return the size of the underlying OS metadata,
398
- // hence, why we 0 out the size on a folder here.
399
- info = path.isFile() ? info.file() : info.folder().size(undefined);
400
- return info.build();
401
- })
402
- ];
403
- }
404
- });
405
- })();
406
- }
407
- },
408
- {
409
- key: "walk",
410
- value: function walk(search, options) {
411
- return _async_to_generator(function() {
412
- var start, stop, mode, _test, dir, path, exists;
413
- return _ts_generator(this, function(_state) {
414
- switch(_state.label){
415
- case 0:
416
- start = (options === null || options === void 0 ? void 0 : options.start) || cwd();
417
- stop = (options === null || options === void 0 ? void 0 : options.stop) || "/";
418
- mode = options === null || options === void 0 ? void 0 : options.mode;
419
- _test = function(path) {
420
- return _async_to_generator(function() {
421
- return _ts_generator(this, function(_state) {
422
- switch(_state.label){
423
- case 0:
424
- _state.trys.push([
425
- 0,
426
- 2,
427
- ,
428
- 3
429
- ]);
430
- return [
431
- 4,
432
- access(path, mode)
433
- ];
434
- case 1:
435
- _state.sent();
436
- return [
437
- 2,
438
- true
439
- ];
440
- case 2:
441
- _state.sent();
442
- return [
443
- 2,
444
- false
445
- ];
446
- case 3:
447
- return [
448
- 2
449
- ];
450
- }
451
- });
452
- })();
453
- };
454
- if (!isAbsolute(search)) return [
455
- 3,
456
- 2
457
- ];
458
- return [
459
- 4,
460
- _test(search)
461
- ];
462
- case 1:
463
- return [
464
- 2,
465
- _state.sent() ? search : null
466
- ];
467
- case 2:
468
- dir = start;
469
- _state.label = 3;
470
- case 3:
471
- path = resolve(dir, search);
472
- return [
473
- 4,
474
- _test(path)
475
- ];
476
- case 4:
477
- exists = _state.sent();
478
- if (exists) {
479
- return [
480
- 2,
481
- path
482
- ];
483
- }
484
- dir = dir === stop ? "" : dirname(dir);
485
- _state.label = 5;
486
- case 5:
487
- if (dir.length) return [
488
- 3,
489
- 3
490
- ];
491
- _state.label = 6;
492
- case 6:
493
- return [
494
- 2,
495
- null
496
- ];
497
- }
498
- });
499
- })();
500
- }
501
- }
502
- ]);
503
- return ZFileSystemService;
504
- }();
505
100
 
506
101
  export { ZFileSystemNodeBuilder, ZFileSystemNodeType, ZFileSystemService };
507
102
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts"],"sourcesContent":["import { isUndefined, omitBy } from \"lodash-es\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: IZFileSystemNode;\n\n public constructor() {\n this._node = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n };\n }\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n return this;\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n return this;\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public build() {\n const clone = structuredClone(this._node);\n return omitBy<IZFileSystemNode>(clone, isUndefined) as IZFileSystemNode;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string,\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n ...options,\n stat: true,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we 0 out the size on a folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","_define_property","_node","file","type","bind","folder","path","created","at","Date","toJSON","updated","size","bytes","BigInt","build","clone","structuredClone","omitBy","isUndefined","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","birthtime","atime","isFile","undefined","walk","start","stop","mode","_test","dir","exists","cwd","access","isAbsolute","resolve","dirname","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;IAGO,IAAKA,mBAAAA,iBAAAA,SAAAA,mBAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,mBAAAA;AAGX,CAAA,CAAA,EAAA;AA6BD;;IA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GAAS,MAAA,CAAA,IAAA,EAAA;AAEf,gCAAA,IAAIA,MAAAA,EAAQ;AACV,oCAAA,OAAA;;AAAOnC,wCAAAA;;AACT;gCAEAkC,GAAAA,GAAMA,GAAAA,KAAQH,IAAAA,GAAO,EAAA,GAAKS,OAAAA,CAAQN,GAAAA,CAAAA;;;AAC3BA,gCAAAA,IAAAA,GAAAA,CAAIO,MAAM,EAAVP,OAAAA;;;;;;AAET,gCAAA,OAAA;;AAAO,oCAAA;;;;AACT,iBAAA,CAAA,EAAA;;;;AA9DWpB,IAAAA,OAAAA,kBAAAA;AA+DZ,CAAA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts"],"sourcesContent":["import { isUndefined, omitBy } from \"lodash-es\";\n\n/**\n * Represents a type of a file system node.\n */\nexport enum ZFileSystemNodeType {\n File = \"file\",\n Folder = \"folder\",\n}\n\nexport interface IZFileSystemNode {\n /**\n * The absolute path of the node.\n */\n path: string;\n\n /**\n * The type of the node (file or folder).\n */\n type: ZFileSystemNodeType;\n\n /**\n * The creation date of the node.\n */\n created?: string;\n\n /**\n * The modification date of the node.\n */\n updated?: string;\n\n /**\n * The size of the node in bytes.\n */\n size?: bigint;\n}\n\n/**\n * Represents a builder for a file system node.\n */\nexport class ZFileSystemNodeBuilder {\n private _node: IZFileSystemNode;\n\n public constructor() {\n this._node = {\n path: \"/\",\n type: ZFileSystemNodeType.Folder,\n };\n }\n\n public created(at?: Date | string | undefined) {\n this._node.created = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public updated(at?: Date | string | undefined) {\n this._node.updated = at instanceof Date ? at.toJSON() : at;\n return this;\n }\n\n public size(bytes: bigint | number | undefined) {\n this._node.size = typeof bytes == \"number\" ? BigInt(bytes) : bytes;\n return this;\n }\n\n public path(path: string) {\n this._node.path = path;\n return this;\n }\n\n public type(type: ZFileSystemNodeType) {\n this._node.type = type;\n return this;\n }\n\n public file = this.type.bind(this, ZFileSystemNodeType.File);\n public folder = this.type.bind(this, ZFileSystemNodeType.Folder);\n\n public build() {\n const clone = structuredClone(this._node);\n return omitBy(clone, isUndefined) as IZFileSystemNode;\n }\n}\n","import { glob } from \"glob\";\nimport { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport type { IZFileSystemNode } from \"./file-system-node.mjs\";\nimport { ZFileSystemNodeBuilder } from \"./file-system-node.mjs\";\n\n/**\n * Represents options for searches.\n */\nexport interface IZFileSystemSearchOptions {\n /**\n * The directory to search in.\n *\n * If this is not set, then the cwd of the application is used.\n */\n cwd?: string;\n\n /**\n * A flag that determines whether or not to load the\n * file system information.\n *\n * This is true by default.\n */\n stat?: boolean;\n}\n\n/**\n * Represents options for directory walking.\n */\nexport interface IZFileSystemWalkOptions {\n /**\n * The starting directory.\n *\n * The default is the current working directory\n *\n * @see process.cwd for more information.\n */\n start?: string;\n\n /**\n * The directory to stop at.\n *\n * The default is the root of the file system.\n */\n stop?: string;\n\n /**\n * The type of mode that the path must support in order\n * to be approved.\n *\n * The default is undefined and left up to the node api.\n */\n mode?: number;\n}\n\n/**\n * Represents a service to enumerate the file system.\n */\nexport interface IZFileSystemService {\n /**\n * Gets information about a node.\n *\n * @param path -\n * The path to get information for.\n *\n * @returns\n * Information about the node.\n */\n info(path: string): Promise<IZFileSystemNode>;\n\n /**\n * Reads all nodes that match a pattern.\n *\n * @param pattern -\n * The pattern string to match against.\n * @param options -\n * The options for the search.\n *\n * @returns\n * A list of path strings that match the given patterns.\n */\n search(\n pattern: string,\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]>;\n\n /**\n * Walks up a directory tree to search for existence of a given path.\n *\n * @param search -\n * The path to search for. This is the candidate folder path that\n * may or may not exist somewhere from the start directory all the\n * way up the directory tree.\n * @param options -\n * The given options for the search.\n *\n * @returns\n * The fully qualified path to the first path that matches the search\n * starting at the options start or the current working directory if not\n * specified. Returns null if no such directory exists.\n *\n * @example\n *\n * ```ts\n * import { resolve } from 'path'\n *\n * // Find any folder named .vscode from the current working directory all the way\n * // up the directory tree. Returns null if no vscode directory can be found.\n * const service = new ZFileSystemService();\n * const vscode = service.walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = service.walk('.config', { start: __dirname });\n *\n * // Walk the directory tree from the current script and stop when we reach\n * // at most 2 directories up.\n * const start = __dirname;\n * const stop = resolve(__dirname, '../..');\n * const file = service.walk('path/to/file.json', { start, stop });\n * ```\n */\n walk(\n search: string,\n options?: IZFileSystemWalkOptions,\n ): Promise<string | null>;\n}\n\n/**\n * Represents a node implementation of a file system service.\n */\nexport class ZFileSystemService implements IZFileSystemService {\n public async info(path: string): Promise<IZFileSystemNode> {\n const [file] = await this.search(path);\n return file;\n }\n\n public async search(\n pattern: string | string[],\n options?: IZFileSystemSearchOptions,\n ): Promise<IZFileSystemNode[]> {\n const paths = await glob(pattern, {\n stat: true,\n ...options,\n withFileTypes: true,\n });\n\n return paths.map((path) => {\n let info = new ZFileSystemNodeBuilder()\n .path(path.fullpath())\n .created(path.birthtime)\n .updated(path.atime)\n .size(path.size);\n\n // Note that for folders, node will return the size of the underlying OS metadata,\n // hence, why we remove the size on the folder here.\n info = path.isFile() ? info.file() : info.folder().size(undefined);\n\n return info.build();\n });\n }\n\n public async walk(search: string, options?: IZFileSystemWalkOptions) {\n const start = options?.start || cwd();\n const stop = options?.stop || \"/\";\n const mode = options?.mode;\n\n const _test = async (path: string) => {\n try {\n await access(path, mode);\n return true;\n } catch {\n return false;\n }\n };\n\n if (isAbsolute(search)) {\n return (await _test(search)) ? search : null;\n }\n\n let dir = start;\n do {\n const path = resolve(dir, search);\n const exists = await _test(path);\n\n if (exists) {\n return path;\n }\n\n dir = dir === stop ? \"\" : dirname(dir);\n } while (dir.length);\n\n return null;\n }\n}\n"],"names":["ZFileSystemNodeType","ZFileSystemNodeBuilder","_node","path","type","created","at","Date","toJSON","updated","size","bytes","BigInt","file","bind","folder","build","clone","structuredClone","omitBy","isUndefined","ZFileSystemService","info","search","pattern","options","paths","glob","stat","withFileTypes","map","fullpath","birthtime","atime","isFile","undefined","walk","start","cwd","stop","mode","_test","access","isAbsolute","dir","resolve","exists","dirname","length"],"mappings":";;;;;;AAEA;;IAGO,IAAKA,mBAAAA,iBAAAA,SAAAA,mBAAAA,EAAAA;;;AAAAA,IAAAA,OAAAA,mBAAAA;AAGX,CAAA,CAAA,EAAA;AA6BD;;AAEC,IACM,MAAMC,sBAAAA,CAAAA;IACHC,KAAAA;IAER,WAAA,EAAqB;QACnB,IAAI,CAACA,KAAK,GAAG;YACXC,IAAAA,EAAM,GAAA;YACNC,IAAI,EAAA;AACN,SAAA;AACF,IAAA;AAEOC,IAAAA,OAAAA,CAAQC,EAA8B,EAAE;QAC7C,IAAI,CAACJ,KAAK,CAACG,OAAO,GAAGC,EAAAA,YAAcC,IAAAA,GAAOD,EAAAA,CAAGE,MAAM,EAAA,GAAKF,EAAAA;AACxD,QAAA,OAAO,IAAI;AACb,IAAA;AAEOG,IAAAA,OAAAA,CAAQH,EAA8B,EAAE;QAC7C,IAAI,CAACJ,KAAK,CAACO,OAAO,GAAGH,EAAAA,YAAcC,IAAAA,GAAOD,EAAAA,CAAGE,MAAM,EAAA,GAAKF,EAAAA;AACxD,QAAA,OAAO,IAAI;AACb,IAAA;AAEOI,IAAAA,IAAAA,CAAKC,KAAkC,EAAE;QAC9C,IAAI,CAACT,KAAK,CAACQ,IAAI,GAAG,OAAOC,KAAAA,IAAS,QAAA,GAAWC,MAAAA,CAAOD,KAAAA,CAAAA,GAASA,KAAAA;AAC7D,QAAA,OAAO,IAAI;AACb,IAAA;AAEOR,IAAAA,IAAAA,CAAKA,IAAY,EAAE;AACxB,QAAA,IAAI,CAACD,KAAK,CAACC,IAAI,GAAGA,IAAAA;AAClB,QAAA,OAAO,IAAI;AACb,IAAA;AAEOC,IAAAA,IAAAA,CAAKA,IAAyB,EAAE;AACrC,QAAA,IAAI,CA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
4
4
  "description": "A better file system module for node",
5
5
  "author": "Anthony Bonta",
6
6
  "license": "MIT",
@@ -32,13 +32,13 @@
32
32
  "lodash-es": "^4.17.21"
33
33
  },
34
34
  "devDependencies": {
35
- "@zthun/janitor-build-config": "^19.2.4",
36
- "vite": "^6.3.5",
35
+ "@zthun/janitor-build-config": "^19.3.1",
36
+ "vite": "^7.0.5",
37
37
  "vitest": "^3.2.4"
38
38
  },
39
39
  "files": [
40
40
  "dist"
41
41
  ],
42
42
  "sideEffects": false,
43
- "gitHead": "d7d91d6e423b015d3933e515aadebe87f9c42038"
43
+ "gitHead": "d564d17a1cfb1e616ca6595eee7e6bc281078830"
44
44
  }