@visulima/fs 5.0.0-alpha.2 → 5.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +256 -0
- package/LICENSE.md +208 -131
- package/dist/eol.d.ts +31 -30
- package/dist/eol.js +3 -26
- package/dist/error.d.ts +273 -7
- package/dist/error.js +1 -7
- package/dist/glob-parent.d.ts +35 -0
- package/dist/glob-parent.js +1 -0
- package/dist/glob.d.ts +4 -0
- package/dist/glob.js +1 -0
- package/dist/index.d.ts +858 -36
- package/dist/index.js +1 -33
- package/dist/ini.d.ts +70 -0
- package/dist/ini.js +1 -0
- package/dist/is-glob.d.ts +34 -0
- package/dist/is-glob.js +1 -0
- package/dist/json5.d.ts +36 -0
- package/dist/json5.js +1 -0
- package/dist/jsonc.d.ts +65 -0
- package/dist/jsonc.js +1 -0
- package/dist/match.d.ts +46 -0
- package/dist/match.js +1 -0
- package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.js +1 -0
- package/dist/packem_shared/DirectoryError-ddlbUV8C.js +1 -0
- package/dist/packem_shared/F_OK-CAwY1qU7.js +1 -0
- package/dist/packem_shared/JSONError-D7h6PNWc.js +4 -0
- package/dist/packem_shared/NotEmptyError-DMh1o7UL.js +1 -0
- package/dist/packem_shared/NotFoundError-BPiW0icm.js +1 -0
- package/dist/packem_shared/PermissionError-B1Emi5a9.js +1 -0
- package/dist/packem_shared/WalkError-Olmh4908.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-D6W6KoPK.js +1 -0
- package/dist/packem_shared/assertValidFileContents-BZFnXa7K.js +1 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.js +1 -0
- package/dist/packem_shared/build-rm-options-C1R4reBu.js +1 -0
- package/dist/packem_shared/collect-2KPTpCdX.js +1 -0
- package/dist/packem_shared/collectSync-BX55r_BH.js +1 -0
- package/dist/packem_shared/emptyDir-8utO028L.js +1 -0
- package/dist/packem_shared/emptyDirSync-Bk5fUX73.js +1 -0
- package/dist/packem_shared/ensureDir-CZ4oUFuo.js +1 -0
- package/dist/packem_shared/ensureDirSync-CoPWhbjM.js +1 -0
- package/dist/packem_shared/ensureFile-CF1cAAyh.js +1 -0
- package/dist/packem_shared/ensureFileSync-C3qR6naU.js +1 -0
- package/dist/packem_shared/ensureLink-LLLxlGHn.js +1 -0
- package/dist/packem_shared/ensureLinkSync-Dh_GtT8F.js +1 -0
- package/dist/packem_shared/ensureSymlink-D50kj2zl.js +1 -0
- package/dist/packem_shared/ensureSymlinkSync-BbVDPvI4.js +1 -0
- package/dist/packem_shared/findUp-BT07y_Me.js +1 -0
- package/dist/packem_shared/findUpSync-BvZiYsKJ.js +1 -0
- package/dist/packem_shared/get-file-info-type-CaWGXRjY.js +1 -0
- package/dist/packem_shared/glob-MHJQjR39.js +1 -0
- package/dist/packem_shared/glob-sync.d-D1IzfyFn.d.ts +54 -0
- package/dist/packem_shared/globSync-CwzlELgS.js +1 -0
- package/dist/packem_shared/index-CYIVJA0W.js +1 -0
- package/dist/packem_shared/index-DrapuBsB.js +1 -0
- package/dist/packem_shared/index-K-NNTkpb.js +11 -0
- package/dist/packem_shared/index-yGx8uzZs.js +1 -0
- package/dist/packem_shared/indexToLineColumn-BRSZFC6I-BKj3uzZt.js +6 -0
- package/dist/packem_shared/ini-preserve-CXc_xkpG.js +4 -0
- package/dist/packem_shared/is-stats-identical-CohsLtWy.js +1 -0
- package/dist/packem_shared/isAccessible-CDFxsAAo.js +1 -0
- package/dist/packem_shared/isAccessibleSync-5nzZWgin.js +1 -0
- package/dist/packem_shared/isFsCaseSensitive-CMZVY1A2.js +1 -0
- package/dist/packem_shared/json-error.d-DVILOyHc.d.ts +52 -0
- package/dist/packem_shared/jsonc-merge-CQMjx3Vw.js +2 -0
- package/dist/packem_shared/move-LmP6P9sn.js +1 -0
- package/dist/packem_shared/parseJson-Xx6vHYbv.js +1 -0
- package/dist/packem_shared/readFile-BAVMZg5e.js +1 -0
- package/dist/packem_shared/readFileSync-CGmzMUF2.js +1 -0
- package/dist/packem_shared/readIni-Cfl6HmTS.js +1 -0
- package/dist/packem_shared/readIniSync-DPg4UD0P.js +1 -0
- package/dist/packem_shared/readJson-kPx68Wv1.js +1 -0
- package/dist/packem_shared/readJson5-pXTL9nUE.js +1 -0
- package/dist/packem_shared/readJson5Sync-BedQc292.js +1 -0
- package/dist/packem_shared/readJsonSync-_HXNI3Se.js +1 -0
- package/dist/packem_shared/readJsonc-BzvuAXbT.js +1 -0
- package/dist/packem_shared/readJsoncSync-CVG1_QnX.js +1 -0
- package/dist/packem_shared/readToml-BO5CZK2P.js +1 -0
- package/dist/packem_shared/readTomlSync-1fKo0R52.js +1 -0
- package/dist/packem_shared/readYaml-DjK_Vqj1.js +1 -0
- package/dist/packem_shared/readYamlSync-C3h6KA2c.js +1 -0
- package/dist/packem_shared/remove-DH41Ov_c.js +1 -0
- package/dist/packem_shared/removeSync-50OEdnHd.js +1 -0
- package/dist/packem_shared/resolve-symlink-target-BofZSDIc.js +1 -0
- package/dist/packem_shared/sanitize-CU1xmyrg.js +1 -0
- package/dist/packem_shared/stripJsonComments-CzNR77MF.js +1 -0
- package/dist/packem_shared/to-uint-8-array-DwgaTasY.js +1 -0
- package/dist/packem_shared/types.d-BB9TGb5v.d.ts +1660 -0
- package/dist/packem_shared/walk-D01Qmmvz.js +1 -0
- package/dist/packem_shared/walk-include-DCiVAwMP.js +1 -0
- package/dist/packem_shared/walkSync-BknSdmKD.js +1 -0
- package/dist/packem_shared/writeFile-DNGaDOMX.js +1 -0
- package/dist/packem_shared/writeFileSync-CE1i-eMA.js +1 -0
- package/dist/packem_shared/writeIni-DG7U4ji0.js +4 -0
- package/dist/packem_shared/writeIniSync-Ldt6HFLb.js +4 -0
- package/dist/packem_shared/writeJson-BkGlq1Kv.js +4 -0
- package/dist/packem_shared/writeJson5-Btud4sQh.js +4 -0
- package/dist/packem_shared/writeJson5Sync-Iln3i1IV.js +4 -0
- package/dist/packem_shared/writeJsonSync-HndmyvEK.js +4 -0
- package/dist/packem_shared/writeJsonc-9oiamG16.js +4 -0
- package/dist/packem_shared/writeJsoncSync-BHBziPiK.js +4 -0
- package/dist/packem_shared/writeToml-Cj57wZ8B.js +1 -0
- package/dist/packem_shared/writeTomlSync-B34ZZp0e.js +1 -0
- package/dist/packem_shared/writeYaml-BhQX2yN9.js +1 -0
- package/dist/packem_shared/writeYamlSync-DG01FBeC.js +1 -0
- package/dist/size.d.ts +246 -246
- package/dist/size.js +1 -144
- package/dist/toml.d.ts +63 -0
- package/dist/toml.js +1 -0
- package/dist/utils.d.ts +103 -6
- package/dist/utils.js +1 -6
- package/dist/yaml.d.ts +13 -5
- package/dist/yaml.js +1 -4
- package/package.json +89 -36
- package/dist/constants.d.ts +0 -42
- package/dist/ensure/ensure-dir-sync.d.ts +0 -14
- package/dist/ensure/ensure-dir.d.ts +0 -14
- package/dist/ensure/ensure-file-sync.d.ts +0 -15
- package/dist/ensure/ensure-file.d.ts +0 -27
- package/dist/ensure/ensure-link-sync.d.ts +0 -16
- package/dist/ensure/ensure-link.d.ts +0 -16
- package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
- package/dist/ensure/ensure-symlink.d.ts +0 -23
- package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
- package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
- package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
- package/dist/error/already-exists-error.d.ts +0 -39
- package/dist/error/directory-error.d.ts +0 -47
- package/dist/error/json-error.d.ts +0 -52
- package/dist/error/not-empty-error.d.ts +0 -51
- package/dist/error/not-found-error.d.ts +0 -44
- package/dist/error/permission-error.d.ts +0 -45
- package/dist/error/walk-error.d.ts +0 -51
- package/dist/find/collect-sync.d.ts +0 -31
- package/dist/find/collect.d.ts +0 -35
- package/dist/find/find-up-sync.d.ts +0 -42
- package/dist/find/find-up.d.ts +0 -46
- package/dist/find/utils/glob-to-regexp.d.ts +0 -2
- package/dist/find/utils/walk-include.d.ts +0 -2
- package/dist/find/walk-sync.d.ts +0 -34
- package/dist/find/walk.d.ts +0 -37
- package/dist/is-accessible-sync.d.ts +0 -3
- package/dist/is-accessible.d.ts +0 -29
- package/dist/move/index.d.ts +0 -68
- package/dist/move/types.d.ts +0 -36
- package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
- package/dist/move/utils/internal-move-file.d.ts +0 -3
- package/dist/move/utils/validate-same-directory.d.ts +0 -2
- package/dist/packem_shared/AlreadyExistsError-6Y9hjgMn.js +0 -27
- package/dist/packem_shared/DirectoryError-BfYPkIYP.js +0 -27
- package/dist/packem_shared/F_OK-MldBaGxb.js +0 -8
- package/dist/packem_shared/JSONError-BkHRnInH.js +0 -26
- package/dist/packem_shared/NotEmptyError-B21RUlVr.js +0 -27
- package/dist/packem_shared/NotFoundError-BIp61X6k.js +0 -27
- package/dist/packem_shared/PermissionError-CjoiJgip.js +0 -27
- package/dist/packem_shared/WalkError-DUdQd6FT.js +0 -24
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
- package/dist/packem_shared/collect-DcBwsYYd.js +0 -14
- package/dist/packem_shared/collectSync-Bkjf9Dbm.js +0 -14
- package/dist/packem_shared/emptyDir-CYB5Tict.js +0 -43
- package/dist/packem_shared/emptyDirSync-BD8-1Ytl.js +0 -41
- package/dist/packem_shared/ensureDir-C_kuQ5Ik.js +0 -53
- package/dist/packem_shared/ensureDirSync-CI5g-uBI.js +0 -53
- package/dist/packem_shared/ensureFile-BUtXGlGT.js +0 -47
- package/dist/packem_shared/ensureFileSync-C8hASR-1.js +0 -47
- package/dist/packem_shared/ensureLink-BPnAG5-P.js +0 -54
- package/dist/packem_shared/ensureLinkSync-B-Z7X0ub.js +0 -54
- package/dist/packem_shared/ensureSymlink-U5B6J0BN.js +0 -73
- package/dist/packem_shared/ensureSymlinkSync-DHnZj-9F.js +0 -74
- package/dist/packem_shared/findUp-BSnyGqer.js +0 -85
- package/dist/packem_shared/findUpSync-jRHbSCMV.js +0 -85
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
- package/dist/packem_shared/index-CHM-in-V.js +0 -100
- package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +0 -3
- package/dist/packem_shared/isAccessible-DuVrTNFV.js +0 -38
- package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +0 -38
- package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +0 -62
- package/dist/packem_shared/move-DbpW5_vA.js +0 -134
- package/dist/packem_shared/parseJson-C8xb-3LR.js +0 -231
- package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
- package/dist/packem_shared/readFileSync-6GEIrOnl.js +0 -53
- package/dist/packem_shared/readJson-vddQ97Ll.js +0 -22
- package/dist/packem_shared/readJsonSync-DzeAdYZl.js +0 -22
- package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
- package/dist/packem_shared/readYamlSync-DMV4U-gi.js +0 -10
- package/dist/packem_shared/remove-_oDY3uKo.js +0 -38
- package/dist/packem_shared/removeSync-DETRj7Qn.js +0 -38
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
- package/dist/packem_shared/sanitize-lOzE6k2A.js +0 -205
- package/dist/packem_shared/stripJsonComments-vo4k0mpF.js +0 -19
- package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +0 -19
- package/dist/packem_shared/walk-BhTbpr3y.js +0 -115
- package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
- package/dist/packem_shared/walkSync-DDBq95s8.js +0 -114
- package/dist/packem_shared/writeFile-DSHERs0Z.js +0 -83
- package/dist/packem_shared/writeFileSync-CJp1kXQR.js +0 -83
- package/dist/packem_shared/writeJson-C0OfLDbe.js +0 -50
- package/dist/packem_shared/writeJsonSync-Cs21FE7v.js +0 -50
- package/dist/packem_shared/writeYaml-n4xzYN9a.js +0 -24
- package/dist/packem_shared/writeYamlSync-DnOEnP10.js +0 -24
- package/dist/read/read-file-sync.d.ts +0 -37
- package/dist/read/read-file.d.ts +0 -41
- package/dist/read/read-json-sync.d.ts +0 -5
- package/dist/read/read-json.d.ts +0 -5
- package/dist/read/read-yaml-sync.d.ts +0 -4
- package/dist/read/read-yaml.d.ts +0 -4
- package/dist/remove/empty-dir-sync.d.ts +0 -23
- package/dist/remove/empty-dir.d.ts +0 -28
- package/dist/remove/remove-sync.d.ts +0 -27
- package/dist/remove/remove.d.ts +0 -32
- package/dist/sanitize.d.ts +0 -31
- package/dist/types.d.ts +0 -304
- package/dist/utils/assert-valid-file-contents.d.ts +0 -27
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
- package/dist/utils/parse-json.d.ts +0 -5
- package/dist/utils/strip-json-comments.d.ts +0 -44
- package/dist/write/utils/to-uint-8-array.d.ts +0 -2
- package/dist/write/write-file-sync.d.ts +0 -30
- package/dist/write/write-file.d.ts +0 -30
- package/dist/write/write-json-sync.d.ts +0 -29
- package/dist/write/write-json.d.ts +0 -30
- package/dist/write/write-yaml-sync.d.ts +0 -4
- package/dist/write/write-yaml.d.ts +0 -4
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asynchronously ensures that a file exists.
|
|
3
|
-
* If the directory structure for the file does not exist, it is created.
|
|
4
|
-
* If the file already exists, it is not modified.
|
|
5
|
-
* @param filePath The path to the file. Can be a string or a URL object.
|
|
6
|
-
* @returns A Promise that resolves when the file has been created or confirmed to exist.
|
|
7
|
-
* @throws Will throw an error if the path exists and is not a file.
|
|
8
|
-
* @throws Will throw an error if directory or file creation fails for reasons other than the path not existing initially.
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { ensureFile } from "@visulima/fs";
|
|
12
|
-
*
|
|
13
|
-
* (async () => {
|
|
14
|
-
* try {
|
|
15
|
-
* await ensureFile("path/to/my/file.txt");
|
|
16
|
-
* console.log("File ensured!");
|
|
17
|
-
*
|
|
18
|
-
* await ensureFile(new URL("file:///path/to/another/file.log"));
|
|
19
|
-
* console.log("Another file ensured!");
|
|
20
|
-
* } catch (error) {
|
|
21
|
-
* console.error("Failed to ensure file:", error);
|
|
22
|
-
* }
|
|
23
|
-
* })();
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
declare const ensureFile: (filePath: URL | string) => Promise<void>;
|
|
27
|
-
export default ensureFile;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ensures that the hard link exists.
|
|
3
|
-
* If the directory structure does not exist, it is created.
|
|
4
|
-
* @param source The path to the source file or directory.
|
|
5
|
-
* @param destination The path to the destination link.
|
|
6
|
-
* @example
|
|
7
|
-
* ```javascript
|
|
8
|
-
* import { ensureLinkSync } from "@visulima/fs";
|
|
9
|
-
* import { join } from "node:path";
|
|
10
|
-
*
|
|
11
|
-
* // ensure the link /tmp/foo/bar-link.txt points to /tmp/foo/bar.txt
|
|
12
|
-
* ensureLinkSync(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.txt"));
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
declare const ensureLinkSync: (source: URL | string, destination: URL | string) => void;
|
|
16
|
-
export default ensureLinkSync;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ensures that the hard link exists.
|
|
3
|
-
* If the directory structure does not exist, it is created.
|
|
4
|
-
* @param source The path to the source file or directory.
|
|
5
|
-
* @param destination The path to the destination link.
|
|
6
|
-
* @example
|
|
7
|
-
* ```javascript
|
|
8
|
-
* import { ensureLink } from "@visulima/fs";
|
|
9
|
-
* import { join } from "node:path";
|
|
10
|
-
*
|
|
11
|
-
* // ensure the link /tmp/foo/bar-link.txt points to /tmp/foo/bar.txt
|
|
12
|
-
* await ensureLink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.txt"));
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
declare const ensureLink: (source: URL | string, destination: URL | string) => Promise<void>;
|
|
16
|
-
export default ensureLink;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { symlink } from "node:fs";
|
|
2
|
-
/**
|
|
3
|
-
* Ensures that the link exists, and points to a valid file.
|
|
4
|
-
* If the directory structure does not exist, it is created.
|
|
5
|
-
* If the link already exists, it is not modified but error is thrown if it is not point to the given target.
|
|
6
|
-
* @param target the source file path
|
|
7
|
-
* @param linkName the destination link path
|
|
8
|
-
* @param type the type of the symlink, or null to use automatic detection
|
|
9
|
-
* @returns A void.
|
|
10
|
-
* @example
|
|
11
|
-
* ```javascript
|
|
12
|
-
* import { ensureSymlinkSync } from "@visulima/fs";
|
|
13
|
-
* import { join } from "node:path";
|
|
14
|
-
*
|
|
15
|
-
* // Ensure a symlink /tmp/foo/link-to-bar.txt points to /tmp/foo/bar.txt
|
|
16
|
-
* ensureSymlinkSync(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to-bar.txt"));
|
|
17
|
-
*
|
|
18
|
-
* // Ensure a directory symlink /tmp/foo/link-to-baz-dir points to /tmp/foo/baz-dir
|
|
19
|
-
* ensureSymlinkSync(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
declare const ensureSymlinkSync: (target: URL | string, linkName: URL | string, type?: symlink.Type) => void;
|
|
23
|
-
export default ensureSymlinkSync;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { symlink as symlinkSync } from "node:fs";
|
|
2
|
-
/**
|
|
3
|
-
* Ensures that the link exists, and points to a valid file.
|
|
4
|
-
* If the directory structure does not exist, it is created.
|
|
5
|
-
* If the link already exists, it is not modified but error is thrown if it is not point to the given target.
|
|
6
|
-
* @param target the source file path
|
|
7
|
-
* @param linkName the destination link path
|
|
8
|
-
* @param type the type of the symlink, or null to use automatic detection
|
|
9
|
-
* @returns A void promise that resolves once the link exists.
|
|
10
|
-
* @example
|
|
11
|
-
* ```javascript
|
|
12
|
-
* import { ensureSymlink } from "@visulima/fs";
|
|
13
|
-
* import { join } from "node:path";
|
|
14
|
-
*
|
|
15
|
-
* // Ensure a symlink /tmp/foo/link-to-bar.txt points to /tmp/foo/bar.txt
|
|
16
|
-
* await ensureSymlink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to-bar.txt"));
|
|
17
|
-
*
|
|
18
|
-
* // Ensure a directory symlink /tmp/foo/link-to-baz-dir points to /tmp/foo/baz-dir
|
|
19
|
-
* await ensureSymlink(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
declare const ensureSymlink: (target: URL | string, linkName: URL | string, type?: symlinkSync.Type) => Promise<void>;
|
|
23
|
-
export default ensureSymlink;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Stats } from "node:fs";
|
|
2
|
-
export type PathType = "dir" | "file" | "symlink";
|
|
3
|
-
/**
|
|
4
|
-
* Get a human-readable file type string.
|
|
5
|
-
* @param fileInfo A FileInfo describes a file and is returned by `stat`, `lstat`
|
|
6
|
-
*/
|
|
7
|
-
export declare const getFileInfoType: (fileInfo: Stats) => PathType | undefined;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { AlreadyExistsError } from "@visulima/fs/error"; // Assuming it's exported from an index or directly
|
|
6
|
-
* import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might throw this
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* try {
|
|
10
|
-
* // Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName
|
|
11
|
-
* // For demonstration, let's assume someFunction internally throws it:
|
|
12
|
-
* const someFunctionThatMightThrow = (path) => {
|
|
13
|
-
* if (path === "/tmp/existing-file.txt") { // Simulate a check
|
|
14
|
-
* throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`);
|
|
15
|
-
* }
|
|
16
|
-
* }
|
|
17
|
-
* someFunctionThatMightThrow("/tmp/existing-file.txt");
|
|
18
|
-
* } catch (error) {
|
|
19
|
-
* if (error instanceof AlreadyExistsError) {
|
|
20
|
-
* console.error(`Operation failed because path exists: ${error.message}`);
|
|
21
|
-
* console.error(`Error code: ${error.code}`); // EEXIST
|
|
22
|
-
* } else {
|
|
23
|
-
* console.error("An unexpected error occurred:", error);
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare class AlreadyExistsError extends Error {
|
|
29
|
-
/**
|
|
30
|
-
* Creates a new instance.
|
|
31
|
-
* @param message
|
|
32
|
-
*/
|
|
33
|
-
constructor(message: string);
|
|
34
|
-
get code(): string;
|
|
35
|
-
set code(_name: string);
|
|
36
|
-
get name(): string;
|
|
37
|
-
set name(_name: string);
|
|
38
|
-
}
|
|
39
|
-
export default AlreadyExistsError;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when an operation that is not allowed on a directory is attempted.
|
|
3
|
-
* This typically occurs when a file-specific operation is used on a directory path.
|
|
4
|
-
* @example
|
|
5
|
-
* ```javascript
|
|
6
|
-
* import { DirectoryError } from "@visulima/fs/error";
|
|
7
|
-
* import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
8
|
-
* import { join } from "node:path";
|
|
9
|
-
*
|
|
10
|
-
* const attemptToReadFileFromDir = async () => {
|
|
11
|
-
* try {
|
|
12
|
-
* // Attempting to read a directory as if it were a file
|
|
13
|
-
* // This is a conceptual example; readFile might throw a different error first
|
|
14
|
-
* // depending on its internal checks, but EISDIR is the underlying system error.
|
|
15
|
-
* // Forcing the scenario:
|
|
16
|
-
* const pretendReadFileOnDir = (path) => {
|
|
17
|
-
* if (path === "/tmp/my-directory") { // Simulate a directory path
|
|
18
|
-
* throw new DirectoryError(`read '/tmp/my-directory'`);
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* pretendReadFileOnDir("/tmp/my-directory");
|
|
22
|
-
* // await readFile(join("/tmp", "my-directory"));
|
|
23
|
-
* } catch (error) {
|
|
24
|
-
* if (error instanceof DirectoryError) {
|
|
25
|
-
* console.error(`Operation failed, path is a directory: ${error.message}`);
|
|
26
|
-
* console.error(`Error code: ${error.code}`); // EISDIR
|
|
27
|
-
* } else {
|
|
28
|
-
* console.error("An unexpected error occurred:", error);
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* };
|
|
32
|
-
*
|
|
33
|
-
* attemptToReadFileFromDir();
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
declare class DirectoryError extends Error {
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new instance.
|
|
39
|
-
* @param message
|
|
40
|
-
*/
|
|
41
|
-
constructor(message: string);
|
|
42
|
-
get code(): string;
|
|
43
|
-
set code(_name: string);
|
|
44
|
-
get name(): string;
|
|
45
|
-
set name(_name: string);
|
|
46
|
-
}
|
|
47
|
-
export default DirectoryError;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom error class for handling JSON parsing or related errors.
|
|
3
|
-
* It can optionally include a file name and a code frame for better debugging.
|
|
4
|
-
* @example
|
|
5
|
-
* ```javascript
|
|
6
|
-
* import { JSONError } from "@visulima/fs/error";
|
|
7
|
-
* import { readJsonSync } from "@visulima/fs"; // Or any function that might throw this
|
|
8
|
-
* import { join } from "node:path";
|
|
9
|
-
*
|
|
10
|
-
* try {
|
|
11
|
-
* // Imagine readJsonSync encounters a malformed JSON file and throws JSONError
|
|
12
|
-
* // Forcing the scenario for demonstration:
|
|
13
|
-
* const simulateJsonError = (filePath, content) => {
|
|
14
|
-
* const err = new JSONError(`Unexpected token '}' at position 15`);
|
|
15
|
-
* err.fileName = filePath;
|
|
16
|
-
* // A real implementation might generate a code frame using a library
|
|
17
|
-
* err.codeFrame = ` 13 | "key": "value",
|
|
18
|
-
* > 14 | "anotherKey": "anotherValue",}
|
|
19
|
-
* | ^
|
|
20
|
-
* 15 | "lastKey": "end"
|
|
21
|
-
* `;
|
|
22
|
-
* throw err;
|
|
23
|
-
* };
|
|
24
|
-
*
|
|
25
|
-
* simulateJsonError(join("path", "to", "corrupted.json"), '{ "key": "value", "anotherKey": "anotherValue",} ');
|
|
26
|
-
* // const jsonData = readJsonSync(join("path", "to", "corrupted.json"));
|
|
27
|
-
* } catch (error) {
|
|
28
|
-
* if (error instanceof JSONError) {
|
|
29
|
-
* console.error(`JSON Error: ${error.message}`);
|
|
30
|
-
* // message property will include fileName and codeFrame if they were set.
|
|
31
|
-
* // console.error(`File: ${error.fileName}`);
|
|
32
|
-
* // console.error(`Code Frame:\n${error.codeFrame}`);
|
|
33
|
-
* } else {
|
|
34
|
-
* console.error("An unexpected error occurred:", error);
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare class JSONError extends Error {
|
|
40
|
-
#private;
|
|
41
|
-
fileName: string | undefined;
|
|
42
|
-
codeFrame: string | undefined;
|
|
43
|
-
readonly name = "JSONError";
|
|
44
|
-
/**
|
|
45
|
-
* Creates a new JSONError instance.
|
|
46
|
-
* @param message The primary error message.
|
|
47
|
-
*/
|
|
48
|
-
constructor(message: string);
|
|
49
|
-
get message(): string;
|
|
50
|
-
set message(message: string);
|
|
51
|
-
}
|
|
52
|
-
export default JSONError;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a directory is not empty.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { NotEmptyError } from "@visulima/fs/error";
|
|
6
|
-
* import { rmdir } from "node:fs/promises"; // Or any fs function that might throw this system error
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* const attemptToRemoveNonEmptyDir = async () => {
|
|
10
|
-
* const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files
|
|
11
|
-
* try {
|
|
12
|
-
* // Forcing the scenario for demonstration, as rmdir might throw its own specific error.
|
|
13
|
-
* // Node.js fs operations that encounter a non-empty directory when expecting an empty one
|
|
14
|
-
* // typically throw an error with code ENOTEMPTY.
|
|
15
|
-
* const simulateNotEmpty = (path) => {
|
|
16
|
-
* if (path === dirPath) { // Simulate check for non-empty
|
|
17
|
-
* throw new NotEmptyError(`rmdir '${dirPath}'`);
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
* simulateNotEmpty(dirPath);
|
|
21
|
-
* // await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* if (error instanceof NotEmptyError) {
|
|
24
|
-
* console.error(`Operation failed, directory is not empty: ${error.message}`);
|
|
25
|
-
* console.error(`Error code: ${error.code}`); // ENOTEMPTY
|
|
26
|
-
* } else {
|
|
27
|
-
* console.error("An unexpected error occurred:", error);
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* };
|
|
31
|
-
*
|
|
32
|
-
* // You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test
|
|
33
|
-
* // import { ensureDirSync, writeFileSync } from "@visulima/fs";
|
|
34
|
-
* // ensureDirSync(dirPath);
|
|
35
|
-
* // writeFileSync(join(dirPath, "somefile.txt"), "content");
|
|
36
|
-
*
|
|
37
|
-
* attemptToRemoveNonEmptyDir();
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare class NotEmptyError extends Error {
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new instance.
|
|
43
|
-
* @param message
|
|
44
|
-
*/
|
|
45
|
-
constructor(message: string);
|
|
46
|
-
get code(): string;
|
|
47
|
-
set code(_name: string);
|
|
48
|
-
get name(): string;
|
|
49
|
-
set name(_name: string);
|
|
50
|
-
}
|
|
51
|
-
export default NotEmptyError;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a file or directory is not found at a specified path.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { NotFoundError } from "@visulima/fs/error";
|
|
6
|
-
* import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* const tryReadingNonExistentFile = async () => {
|
|
10
|
-
* const filePath = join("/tmp", "this-file-does-not-exist.txt");
|
|
11
|
-
* try {
|
|
12
|
-
* // Forcing the scenario for demonstration, as readFile itself would throw this.
|
|
13
|
-
* const simulateNotFound = (path) => {
|
|
14
|
-
* if (path === filePath) {
|
|
15
|
-
* throw new NotFoundError(`no such file or directory, open '${filePath}'`);
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* simulateNotFound(filePath);
|
|
19
|
-
* // await readFile(filePath);
|
|
20
|
-
* } catch (error) {
|
|
21
|
-
* if (error instanceof NotFoundError) {
|
|
22
|
-
* console.error(`Operation failed, path not found: ${error.message}`);
|
|
23
|
-
* console.error(`Error code: ${error.code}`); // ENOENT
|
|
24
|
-
* } else {
|
|
25
|
-
* console.error("An unexpected error occurred:", error);
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* };
|
|
29
|
-
*
|
|
30
|
-
* tryReadingNonExistentFile();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare class NotFoundError extends Error {
|
|
34
|
-
/**
|
|
35
|
-
* Creates a new instance.
|
|
36
|
-
* @param message
|
|
37
|
-
*/
|
|
38
|
-
constructor(message: string);
|
|
39
|
-
get code(): string;
|
|
40
|
-
set code(_name: string);
|
|
41
|
-
get name(): string;
|
|
42
|
-
set name(_name: string);
|
|
43
|
-
}
|
|
44
|
-
export default NotFoundError;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when an operation is not permitted due to insufficient privileges
|
|
3
|
-
* or other access control restrictions.
|
|
4
|
-
* @example
|
|
5
|
-
* ```javascript
|
|
6
|
-
* import { PermissionError } from "@visulima/fs/error";
|
|
7
|
-
* import { writeFile } from "@visulima/fs"; // Or any function that might throw this
|
|
8
|
-
* import { join } from "node:path";
|
|
9
|
-
*
|
|
10
|
-
* const tryWritingToProtectedFile = async () => {
|
|
11
|
-
* const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges
|
|
12
|
-
* try {
|
|
13
|
-
* // Forcing the scenario for demonstration, as writeFile itself would throw this.
|
|
14
|
-
* const simulatePermissionError = (path) => {
|
|
15
|
-
* if (path === filePath) {
|
|
16
|
-
* throw new PermissionError(`open '${filePath}'`);
|
|
17
|
-
* }
|
|
18
|
-
* }
|
|
19
|
-
* simulatePermissionError(filePath);
|
|
20
|
-
* // await writeFile(filePath, "test content");
|
|
21
|
-
* } catch (error) {
|
|
22
|
-
* if (error instanceof PermissionError) {
|
|
23
|
-
* console.error(`Operation not permitted: ${error.message}`);
|
|
24
|
-
* console.error(`Error code: ${error.code}`); // EPERM
|
|
25
|
-
* } else {
|
|
26
|
-
* console.error("An unexpected error occurred:", error);
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* };
|
|
30
|
-
*
|
|
31
|
-
* tryWritingToProtectedFile();
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
declare class PermissionError extends Error {
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new instance.
|
|
37
|
-
* @param message
|
|
38
|
-
*/
|
|
39
|
-
constructor(message: string);
|
|
40
|
-
get code(): string;
|
|
41
|
-
set code(_name: string);
|
|
42
|
-
get name(): string;
|
|
43
|
-
set name(_name: string);
|
|
44
|
-
}
|
|
45
|
-
export default PermissionError;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown in {@linkcode walk} or {@linkcode walkSync} during iteration.
|
|
3
|
-
* @example
|
|
4
|
-
* ```javascript
|
|
5
|
-
* import { WalkError } from "@visulima/fs/error";
|
|
6
|
-
* import { walk } from "@visulima/fs";
|
|
7
|
-
* import { join } from "node:path";
|
|
8
|
-
*
|
|
9
|
-
* const processDirectory = async () => {
|
|
10
|
-
* const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
|
|
11
|
-
* try {
|
|
12
|
-
* // Forcing the scenario: walk might throw a WalkError if it encounters an issue
|
|
13
|
-
* // like a directory it cannot read during the walk process.
|
|
14
|
-
* const simulateWalkError = async (rootDir) => {
|
|
15
|
-
* // Let's say readdir inside walk fails for a subdirectory.
|
|
16
|
-
* const underlyingError = new Error("Permission denied reading subdirectory");
|
|
17
|
-
* throw new WalkError(underlyingError, rootDir);
|
|
18
|
-
* }
|
|
19
|
-
* // This is conceptual. In a real scenario, 'walk' itself would throw.
|
|
20
|
-
* // for await (const entry of walk(dirToWalk)) {
|
|
21
|
-
* // console.log(entry.path);
|
|
22
|
-
* // }
|
|
23
|
-
* await simulateWalkError(dirToWalk);
|
|
24
|
-
* } catch (error) {
|
|
25
|
-
* if (error instanceof WalkError) {
|
|
26
|
-
* console.error(`Error during directory walk of "${error.root}": ${error.message}`);
|
|
27
|
-
* if (error.cause) {
|
|
28
|
-
* console.error(`Underlying cause: ${error.cause}`);
|
|
29
|
-
* }
|
|
30
|
-
* } else {
|
|
31
|
-
* console.error("An unexpected error occurred:", error);
|
|
32
|
-
* }
|
|
33
|
-
* }
|
|
34
|
-
* };
|
|
35
|
-
*
|
|
36
|
-
* processDirectory();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare class WalkError extends Error {
|
|
40
|
-
/** File path of the root that's being walked. */
|
|
41
|
-
root: string;
|
|
42
|
-
/**
|
|
43
|
-
* Constructs a new instance.
|
|
44
|
-
* @param cause The underlying error or reason for the walk failure.
|
|
45
|
-
* @param root The root directory path where the walk operation started or encountered the error.
|
|
46
|
-
*/
|
|
47
|
-
constructor(cause: unknown, root: string);
|
|
48
|
-
get name(): string;
|
|
49
|
-
set name(_name: string);
|
|
50
|
-
}
|
|
51
|
-
export default WalkError;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { WalkOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Synchronously collects all file paths within a directory that match the specified criteria.
|
|
4
|
-
* By default, it searches for JavaScript and TypeScript file extensions.
|
|
5
|
-
* @param directory The root directory to start collecting files from.
|
|
6
|
-
* @param options Optional configuration to control the collection process. See {@link WalkOptions}.
|
|
7
|
-
* @returns An array of absolute file paths.
|
|
8
|
-
* @example
|
|
9
|
-
* ```javascript
|
|
10
|
-
* import { collectSync } from "@visulima/fs";
|
|
11
|
-
* import { join } from "node:path";
|
|
12
|
-
*
|
|
13
|
-
* // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
14
|
-
* const files = collectSync(join("/tmp", "docs"), {
|
|
15
|
-
* extensions: ["txt", "md"],
|
|
16
|
-
* maxDepth: 2,
|
|
17
|
-
* includeDirs: false, // Only collect files
|
|
18
|
-
* });
|
|
19
|
-
* console.log(files);
|
|
20
|
-
* // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
21
|
-
*
|
|
22
|
-
* // Collect all .js files, excluding anything in node_modules
|
|
23
|
-
* const jsFiles = collectSync(join("/tmp", "project"), {
|
|
24
|
-
* extensions: ["js"],
|
|
25
|
-
* skip: [/node_modules/],
|
|
26
|
-
* });
|
|
27
|
-
* console.log(jsFiles);
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare const collectSync: (directory: string, options?: WalkOptions) => string[];
|
|
31
|
-
export default collectSync;
|
package/dist/find/collect.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { WalkOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Asynchronously collects all file paths within a directory that match the specified criteria.
|
|
4
|
-
* By default, it searches for JavaScript and TypeScript file extensions.
|
|
5
|
-
* @param directory The root directory to start collecting files from.
|
|
6
|
-
* @param options Optional configuration to control the collection process. See {@link WalkOptions}.
|
|
7
|
-
* @returns A promise that resolves to an array of absolute file paths.
|
|
8
|
-
* @example
|
|
9
|
-
* ```javascript
|
|
10
|
-
* import { collect } from "@visulima/fs";
|
|
11
|
-
* import { join } from "node:path";
|
|
12
|
-
*
|
|
13
|
-
* const collectFiles = async () => {
|
|
14
|
-
* // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
15
|
-
* const files = await collect(join("/tmp", "docs"), {
|
|
16
|
-
* extensions: ["txt", "md"],
|
|
17
|
-
* maxDepth: 2,
|
|
18
|
-
* includeDirs: false, // Only collect files
|
|
19
|
-
* });
|
|
20
|
-
* console.log(files);
|
|
21
|
-
* // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
22
|
-
*
|
|
23
|
-
* // Collect all .js files, excluding anything in node_modules
|
|
24
|
-
* const jsFiles = await collect(join("/tmp", "project"), {
|
|
25
|
-
* extensions: ["js"],
|
|
26
|
-
* skip: [/node_modules/],
|
|
27
|
-
* });
|
|
28
|
-
* console.log(jsFiles);
|
|
29
|
-
* };
|
|
30
|
-
*
|
|
31
|
-
* collectFiles();
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
declare const collect: (directory: string, options?: WalkOptions) => Promise<string[]>;
|
|
35
|
-
export default collect;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { FindUpNameSync, FindUpOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Synchronously finds a file or directory by walking up parent directories.
|
|
4
|
-
* @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
|
|
5
|
-
* @param options Optional configuration for the search. See {@link FindUpOptions}.
|
|
6
|
-
* @returns The absolute path of the first found file/directory, or `undefined` if not found.
|
|
7
|
-
* @example
|
|
8
|
-
* ```javascript
|
|
9
|
-
* import { findUpSync } from "@visulima/fs";
|
|
10
|
-
* import { join } from "node:path";
|
|
11
|
-
*
|
|
12
|
-
* // Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
13
|
-
* const projectRoot = findUpSync("package.json", {
|
|
14
|
-
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
15
|
-
* type: "file",
|
|
16
|
-
* });
|
|
17
|
-
* console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
18
|
-
*
|
|
19
|
-
* // Find the closest .git directory or a README.md file
|
|
20
|
-
* const gitDirOrReadme = findUpSync([".git", "README.md"], {
|
|
21
|
-
* cwd: join("/tmp", "foo", "bar"),
|
|
22
|
-
* });
|
|
23
|
-
* console.log(gitDirOrReadme);
|
|
24
|
-
*
|
|
25
|
-
* // Find using a custom function, stopping at /tmp
|
|
26
|
-
* const customFound = findUpSync(
|
|
27
|
-
* (directory) => {
|
|
28
|
-
* if (directory === join("/tmp", "foo")) {
|
|
29
|
-
* return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
30
|
-
* }
|
|
31
|
-
* return undefined;
|
|
32
|
-
* },
|
|
33
|
-
* {
|
|
34
|
-
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
35
|
-
* stopAt: join("/tmp"),
|
|
36
|
-
* }
|
|
37
|
-
* );
|
|
38
|
-
* console.log(customFound);
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
declare const findUpSync: (name: FindUpNameSync, options?: FindUpOptions) => string | undefined;
|
|
42
|
-
export default findUpSync;
|
package/dist/find/find-up.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { FindUpName, FindUpOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Asynchronously finds a file or directory by walking up parent directories.
|
|
4
|
-
* @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
|
|
5
|
-
* @param options Optional configuration for the search. See {@link FindUpOptions}.
|
|
6
|
-
* @returns A promise that resolves to the absolute path of the first found file/directory, or `undefined` if not found.
|
|
7
|
-
* @example
|
|
8
|
-
* ```javascript
|
|
9
|
-
* import { findUp } from "@visulima/fs";
|
|
10
|
-
* import { join } from "node:path";
|
|
11
|
-
*
|
|
12
|
-
* const findProjectRoot = async () => {
|
|
13
|
-
* // Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
14
|
-
* const projectRoot = await findUp("package.json", {
|
|
15
|
-
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
16
|
-
* type: "file",
|
|
17
|
-
* });
|
|
18
|
-
* console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
19
|
-
*
|
|
20
|
-
* // Find the closest .git directory or a README.md file
|
|
21
|
-
* const gitDirOrReadme = await findUp([".git", "README.md"], {
|
|
22
|
-
* cwd: join("/tmp", "foo", "bar"),
|
|
23
|
-
* });
|
|
24
|
-
* console.log(gitDirOrReadme);
|
|
25
|
-
*
|
|
26
|
-
* // Find using a custom function, stopping at /tmp
|
|
27
|
-
* const customFound = await findUp(
|
|
28
|
-
* (directory) => {
|
|
29
|
-
* if (directory === join("/tmp", "foo")) {
|
|
30
|
-
* return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
31
|
-
* }
|
|
32
|
-
* return undefined;
|
|
33
|
-
* },
|
|
34
|
-
* {
|
|
35
|
-
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
36
|
-
* stopAt: join("/tmp"),
|
|
37
|
-
* }
|
|
38
|
-
* );
|
|
39
|
-
* console.log(customFound);
|
|
40
|
-
* };
|
|
41
|
-
*
|
|
42
|
-
* findProjectRoot();
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
declare const findUp: (name: FindUpName, options?: FindUpOptions) => Promise<string | undefined>;
|
|
46
|
-
export default findUp;
|