@zthun/crumbtrail-fs 1.1.0 → 2.0.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.
@@ -10,6 +10,32 @@ export interface IZFileSystemSearchOptions {
10
10
  */
11
11
  cwd?: string;
12
12
  }
13
+ /**
14
+ * Represents options for directory walking.
15
+ */
16
+ export interface IZFileSystemWalkOptions {
17
+ /**
18
+ * The starting directory.
19
+ *
20
+ * The default is the current working directory
21
+ *
22
+ * @see process.cwd for more information.
23
+ */
24
+ start?: string;
25
+ /**
26
+ * The directory to stop at.
27
+ *
28
+ * The default is the root of the file system.
29
+ */
30
+ stop?: string;
31
+ /**
32
+ * The type of mode that the path must support in order
33
+ * to be approved.
34
+ *
35
+ * The default is undefined and left up to the node api.
36
+ */
37
+ mode?: number;
38
+ }
13
39
  /**
14
40
  * Represents a service to enumerate the file system.
15
41
  */
@@ -36,16 +62,48 @@ export interface IZFileSystemService {
36
62
  * A list of path strings that match the given patterns.
37
63
  */
38
64
  search(pattern: string, options?: IZFileSystemSearchOptions): Promise<IZFileSystemNode[]>;
65
+ /**
66
+ * Walks up a directory tree to search for existence of a given path.
67
+ *
68
+ * @param search -
69
+ * The path to search for. This is the candidate folder path that
70
+ * may or may not exist somewhere from the start directory all the
71
+ * way up the directory tree.
72
+ * @param options -
73
+ * The given options for the search.
74
+ *
75
+ * @returns
76
+ * The fully qualified path to the first path that matches the search
77
+ * starting at the options start or the current working directory if not
78
+ * specified. Returns null if no such directory exists.
79
+ *
80
+ * @example
81
+ *
82
+ * ```ts
83
+ * import { resolve } from 'path'
84
+ *
85
+ * // Find any folder named .vscode from the current working directory all the way
86
+ * // up the directory tree. Returns null if no vscode directory can be found.
87
+ * const service = new ZFileSystemService();
88
+ * const vscode = service.walk('.vscode');
89
+ *
90
+ * // Walk the directory tree from the current script and find the .config folder.
91
+ * const config = service.walk('.config', { start: __dirname });
92
+ *
93
+ * // Walk the directory tree from the current script and stop when we reach
94
+ * // at most 2 directories up.
95
+ * const start = __dirname;
96
+ * const stop = resolve(__dirname, '../..');
97
+ * const file = service.walk('path/to/file.json', { start, stop });
98
+ * ```
99
+ */
100
+ walk(search: string, options?: IZFileSystemWalkOptions): Promise<string | null>;
39
101
  }
40
- /**
41
- * A token that you can use with a framework like nest-js to describe
42
- * a file system service implementation.
43
- */
44
- export declare const ZFileSystemToken: unique symbol;
45
102
  /**
46
103
  * Represents a node implementation of a file system service.
47
104
  */
48
105
  export declare class ZFileSystemService implements IZFileSystemService {
49
106
  info(path: string): Promise<IZFileSystemNode>;
50
107
  search(pattern: string | string[], options?: IZFileSystemSearchOptions): Promise<IZFileSystemNode[]>;
108
+ walk(search: string, options?: IZFileSystemWalkOptions): Promise<string | null>;
51
109
  }
package/dist/index.cjs CHANGED
@@ -53,7 +53,6 @@ class ZFileSystemNodeBuilder {
53
53
  return lodashEs.omitBy(clone, lodashEs.isUndefined);
54
54
  }
55
55
  }
56
- const ZFileSystemToken = Symbol("file-system");
57
56
  class ZFileSystemService {
58
57
  async info(path) {
59
58
  const [file] = await this.search(path);
@@ -71,36 +70,34 @@ class ZFileSystemService {
71
70
  return info.build();
72
71
  });
73
72
  }
74
- }
75
- async function walk(search, options) {
76
- const start = (options == null ? void 0 : options.start) || node_process.cwd();
77
- const stop = (options == null ? void 0 : options.stop) || "/";
78
- const mode = options == null ? void 0 : options.mode;
79
- const _test = async (path) => {
80
- try {
81
- await promises.access(path, mode);
82
- return true;
83
- } catch {
84
- return false;
73
+ async walk(search, options) {
74
+ const start = (options == null ? void 0 : options.start) || node_process.cwd();
75
+ const stop = (options == null ? void 0 : options.stop) || "/";
76
+ const mode = options == null ? void 0 : options.mode;
77
+ const _test = async (path) => {
78
+ try {
79
+ await promises.access(path, mode);
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ };
85
+ if (node_path.isAbsolute(search)) {
86
+ return await _test(search) ? search : null;
85
87
  }
86
- };
87
- if (node_path.isAbsolute(search)) {
88
- return await _test(search) ? search : null;
88
+ let dir = start;
89
+ do {
90
+ const path = node_path.resolve(dir, search);
91
+ const exists = await _test(path);
92
+ if (exists) {
93
+ return path;
94
+ }
95
+ dir = dir === stop ? "" : node_path.dirname(dir);
96
+ } while (dir.length);
97
+ return null;
89
98
  }
90
- let dir = start;
91
- do {
92
- const path = node_path.resolve(dir, search);
93
- const exists = await _test(path);
94
- if (exists) {
95
- return path;
96
- }
97
- dir = dir === stop ? "" : node_path.dirname(dir);
98
- } while (dir.length);
99
- return null;
100
99
  }
101
100
  exports.ZFileSystemNodeBuilder = ZFileSystemNodeBuilder;
102
101
  exports.ZFileSystemNodeType = ZFileSystemNodeType;
103
102
  exports.ZFileSystemService = ZFileSystemService;
104
- exports.ZFileSystemToken = ZFileSystemToken;
105
- exports.walk = walk;
106
103
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/file-system/file-system-node.mts","../src/file-system/file-system-service.mts","../src/walk/walk.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 {\n IZFileSystemNode,\n ZFileSystemNodeBuilder,\n} 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 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/**\n * A token that you can use with a framework like nest-js to describe\n * a file system service implementation.\n */\nexport const ZFileSystemToken = Symbol(\"file-system\");\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","import { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\n\n/**\n * Options for where a directory walk starts.\n */\nexport interface ZWalkOptions {\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 * 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 vscode = walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = 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 = walk('path/to/file.json', { start, stop });\n * ```\n */\nexport async function walk(\n search: string,\n options?: ZWalkOptions,\n): Promise<string | null> {\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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WAAA;AAAA,EAAA;AAAA,EAGT,MAAa,OACX,SACA,SAC6B;AACvB,UAAA,QAAQ,MAAMC,KAAA,KAAK,SAAS;AAAA,MAChC,GAAG;AAAA,MACH,MAAM;AAAA,MACN,eAAe;AAAA,IAAA,CAChB;AAEM,WAAA,MAAM,IAAI,CAAC,SAAS;AACzB,UAAI,OAAO,IAAI,yBACZ,KAAK,KAAK,SAAU,CAAA,EACpB,QAAQ,KAAK,SAAS,EACtB,QAAQ,KAAK,KAAK,EAClB,KAAK,KAAK,IAAI;AAIV,aAAA,KAAK,OAAO,IAAI,KAAK,SAAS,KAAK,OAAA,EAAS,KAAK,MAAS;AAEjE,aAAO,KAAK,MAAM;AAAA,IAAA,CACnB;AAAA,EAAA;AAEL;ACtBsB,eAAA,KACpB,QACA,SACwB;AAClB,QAAA,SAAQ,mCAAS,UAASC,iBAAI;AAC9B,QAAA,QAAO,mCAAS,SAAQ;AAC9B,QAAM,OAAO,mCAAS;AAEhB,QAAA,QAAQ,OAAO,SAAiB;AAChC,QAAA;AACI,YAAAC,SAAA,OAAO,MAAM,IAAI;AAChB,aAAA;AAAA,IAAA,QACD;AACC,aAAA;AAAA,IAAA;AAAA,EAEX;AAEI,MAAAC,UAAAA,WAAW,MAAM,GAAG;AACtB,WAAQ,MAAM,MAAM,MAAM,IAAK,SAAS;AAAA,EAAA;AAG1C,MAAI,MAAM;AACP,KAAA;AACK,UAAA,OAAOC,UAAAA,QAAQ,KAAK,MAAM;AAC1B,UAAA,SAAS,MAAM,MAAM,IAAI;AAE/B,QAAI,QAAQ;AACH,aAAA;AAAA,IAAA;AAGT,UAAM,QAAQ,OAAO,KAAKC,UAAAA,QAAQ,GAAG;AAAA,WAC9B,IAAI;AAEN,SAAA;AACT;;;;;;"}
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 {\n IZFileSystemNode,\n ZFileSystemNodeBuilder,\n} 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","omitBy","isUndefined","glob","cwd","access","isAbsolute","resolve","dirname"],"mappings":";;;;;;;AAKY,IAAA,wCAAAA,yBAAL;AACLA,uBAAA,MAAO,IAAA;AACPA,uBAAA,QAAS,IAAA;AAFCA,SAAAA;AAAA,GAAA,uBAAA,CAAA,CAAA;AAmCL,MAAM,uBAAuB;AAAA,EAG3B,cAAc;AAgCrB,SAAO,OAAO,KAAK,KAAK;AAAA,MAAK;AAAA,MAAM;AAAA;AAAA,IAAwB;AAC3D,SAAO,SAAS,KAAK,KAAK;AAAA,MAAK;AAAA,MAAM;AAAA;AAAA,IAA0B;AAhC7D,SAAK,QAAQ;AAAA,MACX,MAAM;AAAA,MACN,MAAM;AAAA;AAAA,IACR;AAAA,EAAA;AAAA,EAGK,QAAQ,IAAgC;AAC7C,SAAK,MAAM,UAAU,cAAc,OAAO,GAAG,WAAW;AACjD,WAAA;AAAA,EAAA;AAAA,EAGF,QAAQ,IAAgC;AAC7C,SAAK,MAAM,UAAU,cAAc,OAAO,GAAG,WAAW;AACjD,WAAA;AAAA,E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IAEX;AAEI,QAAAC,UAAAA,WAAW,MAAM,GAAG;AACtB,aAAQ,MAAM,MAAM,MAAM,IAAK,SAAS;AAAA,IAAA;AAG1C,QAAI,MAAM;AACP,OAAA;AACK,YAAA,OAAOC,UAAAA,QAAQ,KAAK,MAAM;AAC1B,YAAA,SAAS,MAAM,MAAM,IAAI;AAE/B,UAAI,QAAQ;AACH,eAAA;AAAA,MAAA;AAGT,YAAM,QAAQ,OAAO,KAAKC,UAAAA,QAAQ,GAAG;AAAA,aAC9B,IAAI;AAEN,WAAA;AAAA,EAAA;AAEX;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './file-system/file-system-node.mjs';
2
2
  export * from './file-system/file-system-service.mjs';
3
- export * from './walk/walk.mjs';
package/dist/index.js CHANGED
@@ -51,7 +51,6 @@ class ZFileSystemNodeBuilder {
51
51
  return omitBy(clone, isUndefined);
52
52
  }
53
53
  }
54
- const ZFileSystemToken = Symbol("file-system");
55
54
  class ZFileSystemService {
56
55
  async info(path) {
57
56
  const [file] = await this.search(path);
@@ -69,38 +68,36 @@ class ZFileSystemService {
69
68
  return info.build();
70
69
  });
71
70
  }
72
- }
73
- async function walk(search, options) {
74
- const start = (options == null ? void 0 : options.start) || cwd();
75
- const stop = (options == null ? void 0 : options.stop) || "/";
76
- const mode = options == null ? void 0 : options.mode;
77
- const _test = async (path) => {
78
- try {
79
- await access(path, mode);
80
- return true;
81
- } catch {
82
- return false;
71
+ async walk(search, options) {
72
+ const start = (options == null ? void 0 : options.start) || cwd();
73
+ const stop = (options == null ? void 0 : options.stop) || "/";
74
+ const mode = options == null ? void 0 : options.mode;
75
+ const _test = async (path) => {
76
+ try {
77
+ await access(path, mode);
78
+ return true;
79
+ } catch {
80
+ return false;
81
+ }
82
+ };
83
+ if (isAbsolute(search)) {
84
+ return await _test(search) ? search : null;
83
85
  }
84
- };
85
- if (isAbsolute(search)) {
86
- return await _test(search) ? search : null;
86
+ let dir = start;
87
+ do {
88
+ const path = resolve(dir, search);
89
+ const exists = await _test(path);
90
+ if (exists) {
91
+ return path;
92
+ }
93
+ dir = dir === stop ? "" : dirname(dir);
94
+ } while (dir.length);
95
+ return null;
87
96
  }
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;
98
97
  }
99
98
  export {
100
99
  ZFileSystemNodeBuilder,
101
100
  ZFileSystemNodeType,
102
- ZFileSystemService,
103
- ZFileSystemToken,
104
- walk
101
+ ZFileSystemService
105
102
  };
106
103
  //# 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","../src/walk/walk.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 {\n IZFileSystemNode,\n ZFileSystemNodeBuilder,\n} 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 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/**\n * A token that you can use with a framework like nest-js to describe\n * a file system service implementation.\n */\nexport const ZFileSystemToken = Symbol(\"file-system\");\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","import { access } from \"node:fs/promises\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { cwd } from \"node:process\";\n\n/**\n * Options for where a directory walk starts.\n */\nexport interface ZWalkOptions {\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 * 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 vscode = walk('.vscode');\n *\n * // Walk the directory tree from the current script and find the .config folder.\n * const config = 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 = walk('path/to/file.json', { start, stop });\n * ```\n */\nexport async function walk(\n search: string,\n options?: ZWalkOptions,\n): Promise<string | null> {\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"],"names":["ZFileSystemNodeType"],"mappings":";;;;;AAKY,IAAA,wCAAAA,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;AAAA,IAAA,CAChB;AAEM,WAAA,MAAM,IAAI,CAAC,SAAS;AACzB,UAAI,OAAO,IAAI,yBACZ,KAAK,KAAK,SAAU,CAAA,EACpB,QAAQ,KAAK,SAAS,EACtB,QAAQ,KAAK,KAAK,EAClB,KAAK,KAAK,IAAI;AAIV,aAAA,KAAK,OAAO,IAAI,KAAK,SAAS,KAAK,OAAA,EAAS,KAAK,MAAS;AAEjE,aAAO,KAAK,MAAM;AAAA,IAAA,CACnB;AAAA,EAAA;AAEL;ACtBsB,eAAA,KACpB,QACA,SACwB;AAClB,QAAA,SAAQ,mCAAS,UAAS,IAAI;AAC9B,QAAA,QAAO,mCAAS,SAAQ;AAC9B,QAAM,OAAO,mCAAS;AAEhB,QAAA,QAAQ,OAAO,SAAiB;AAChC,QAAA;AACI,YAAA,OAAO,MAAM,IAAI;AAChB,aAAA;AAAA,IAAA,QACD;AACC,aAAA;AAAA,IAAA;AAAA,EAEX;AAEI,MAAA,WAAW,MAAM,GAAG;AACtB,WAAQ,MAAM,MAAM,MAAM,IAAK,SAAS;AAAA,EAAA;AAG1C,MAAI,MAAM;AACP,KAAA;AACK,UAAA,OAAO,QAAQ,KAAK,MAAM;AAC1B,UAAA,SAAS,MAAM,MAAM,IAAI;AAE/B,QAAI,QAAQ;AACH,aAAA;AAAA,IAAA;AAGT,UAAM,QAAQ,OAAO,KAAK,QAAQ,GAAG;AAAA,WAC9B,IAAI;AAEN,SAAA;AACT;"}
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 {\n IZFileSystemNode,\n ZFileSystemNodeBuilder,\n} 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"],"mappings":";;;;;AAKY,IAAA,wCAAAA,yBAAL;AACLA,uBAAA,MAAO,IAAA;AACPA,uBAAA,QAAS,IAAA;AAFCA,SAAAA;AAAA,GAAA,uBAAA,CAAA,CAAA;AAmCL,MAAM,uBAAuB;AAAA,EAG3B,cAAc;AAgCrB,SAAO,OAAO,KAAK,KAAK;AAAA,MAAK;AAAA,MAAM;AAAA;AAAA,IAAwB;AAC3D,SAAO,SAAS,KAAK,KAAK;AAAA,MAAK;AAAA,MAAM;AAAA;AAAA,IAA0B;AAhC7D,SAAK,QAAQ;AAAA,MACX,MAAM;AAAA,MACN,MAAM;AAAA;AAAA,IACR;AAAA,EAAA;AAAA,EAGK,QAAQ,IAAgC;AAC7C,SAAK,MAAM,UAAU,cAAc,OAAO,GAAG,WAAW;AACjD,WAAA;AAAA,EAAA;AAAA,EAGF,QAAQ,IAAgC;AAC7C,SAAK,MAAM,UAAU,cAAc,OAAO,GAAG,WAAW;AACjD,WAAA;AAAA,EAAA;AAAA,EAGF,KAAK,OAAoC;AAC9C,SAAK,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK,IAAI;AACtD,WAAA;AAAA,EAAA;AAAA,EAGF,KAAK,MAAc;AACxB,SAAK,MAAM,OAAO;AACX,WAAA;AAAA,EAAA;AAAA,EAGF,KAAK,MAA2B;AACrC,SAAK,MAAM,OAAO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AO,KAAK,QAAQ,GAAG;AAAA,aAC9B,IAAI;AAEN,WAAA;AAAA,EAAA;AAEX;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/crumbtrail-fs",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "A better file system module for node",
5
5
  "author": "Anthony Bonta",
6
6
  "license": "MIT",
@@ -39,5 +39,5 @@
39
39
  "dist"
40
40
  ],
41
41
  "sideEffects": false,
42
- "gitHead": "3e311966e8d62306da2cf5427f4db2cf1a027bf5"
42
+ "gitHead": "cd7670e529ce087c9095e16dfbeb3aed9ca856c2"
43
43
  }
@@ -1,61 +0,0 @@
1
- /**
2
- * Options for where a directory walk starts.
3
- */
4
- export interface ZWalkOptions {
5
- /**
6
- * The starting directory.
7
- *
8
- * The default is the current working directory
9
- *
10
- * @see process.cwd for more information.
11
- */
12
- start?: string;
13
- /**
14
- * The directory to stop at.
15
- *
16
- * The default is the root of the file system.
17
- */
18
- stop?: string;
19
- /**
20
- * The type of mode that the path must support in order
21
- * to be approved.
22
- *
23
- * The default is undefined and left up to the node api.
24
- */
25
- mode?: number;
26
- }
27
- /**
28
- * Walks up a directory tree to search for existence of a given path.
29
- *
30
- * @param search -
31
- * The path to search for. This is the candidate folder path that
32
- * may or may not exist somewhere from the start directory all the
33
- * way up the directory tree.
34
- * @param options -
35
- * The given options for the search.
36
- *
37
- * @returns
38
- * The fully qualified path to the first path that matches the search
39
- * starting at the options start or the current working directory if not
40
- * specified. Returns null if no such directory exists.
41
- *
42
- * @example
43
- *
44
- * ```ts
45
- * import { resolve } from 'path'
46
- *
47
- * // Find any folder named .vscode from the current working directory all the way
48
- * // up the directory tree. Returns null if no vscode directory can be found.
49
- * const vscode = walk('.vscode');
50
- *
51
- * // Walk the directory tree from the current script and find the .config folder.
52
- * const config = walk('.config', { start: __dirname });
53
- *
54
- * // Walk the directory tree from the current script and stop when we reach
55
- * // at most 2 directories up.
56
- * const start = __dirname;
57
- * const stop = resolve(__dirname, '../..');
58
- * const file = walk('path/to/file.json', { start, stop });
59
- * ```
60
- */
61
- export declare function walk(search: string, options?: ZWalkOptions): Promise<string | null>;