@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
package/dist/eol.d.ts
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
/** End-of-line character for POSIX platforms such as macOS and Linux. */
|
|
2
|
-
|
|
2
|
+
declare const LF: "\n";
|
|
3
3
|
/** End-of-line character for Windows platforms. */
|
|
4
|
-
|
|
4
|
+
declare const CRLF: "\r\n";
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
* End-of-line character evaluated for the current platform.
|
|
7
|
+
*/
|
|
8
|
+
declare const EOL: "\n" | "\r\n";
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
* Detect the EOL character for string input.
|
|
11
|
+
* Returns null if no newline.
|
|
12
|
+
* @param content The string content to detect the EOL from.
|
|
13
|
+
* @example
|
|
14
|
+
* ```javascript
|
|
15
|
+
* import { detect } from "@visulima/fs/eol";
|
|
16
|
+
*
|
|
17
|
+
* detect("Hello\r\nWorld"); // "\r\n"
|
|
18
|
+
* detect("Hello\nWorld"); // "\n"
|
|
19
|
+
* detect("HelloWorld"); // null
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const detect: (content: string) => typeof EOL | null;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
* Format the file to the targeted EOL.
|
|
25
|
+
* @param content The string content to format.
|
|
26
|
+
* @param eol The target EOL character.
|
|
27
|
+
* @example
|
|
28
|
+
* ```javascript
|
|
29
|
+
* import { format, LF, CRLF } from "@visulima/fs/eol";
|
|
30
|
+
*
|
|
31
|
+
* format("Hello\r\nWorld\nUnix", LF); // "Hello\nWorld\nUnix"
|
|
32
|
+
* format("Hello\nWorld\r\nWindows", CRLF); // "Hello\r\nWorld\r\nWindows"
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare const format: (content: string, eol: typeof EOL) => string;
|
|
36
|
+
export { CRLF, EOL, LF, detect, format };
|
package/dist/eol.js
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
platform
|
|
9
|
-
} = __cjs_getProcess;
|
|
10
|
-
|
|
11
|
-
const regDetect = /\r?\n/g;
|
|
12
|
-
const LF = "\n";
|
|
13
|
-
const CRLF = "\r\n";
|
|
14
|
-
const EOL = platform === "win32" ? CRLF : LF;
|
|
15
|
-
const detect = (content) => {
|
|
16
|
-
const matched = content.match(regDetect);
|
|
17
|
-
if (!matched || matched.length === 0) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const crlf = matched.filter((newline) => newline === CRLF).length;
|
|
21
|
-
const lf = matched.length - crlf;
|
|
22
|
-
return crlf > lf ? CRLF : LF;
|
|
23
|
-
};
|
|
24
|
-
const format = (content, eol) => content.replaceAll(regDetect, eol);
|
|
25
|
-
|
|
26
|
-
export { CRLF, EOL, LF, detect, format };
|
|
1
|
+
var f=Object.defineProperty;var c=(t,e)=>f(t,"name",{value:e,configurable:!0});import{createRequire as u}from"node:module";const h=u(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,{platform:g}=p;var m=Object.defineProperty,n=c((t,e)=>m(t,"name",{value:e,configurable:!0}),"r");const s=/\r?\n/g,l=`
|
|
2
|
+
`,r=`\r
|
|
3
|
+
`,b=g==="win32"?r:l,j=n(t=>{const e=t.match(s);if(!e||e.length===0)return null;const o=e.filter(i=>i===r).length,a=e.length-o;return o>a?r:l},"detect"),q=n((t,e)=>t.replaceAll(s,e),"format");export{r as CRLF,b as EOL,l as LF,j as detect,q as format};
|
package/dist/error.d.ts
CHANGED
|
@@ -1,7 +1,273 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export { J as JSONError } from "./packem_shared/json-error.d-DVILOyHc.js";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to.
|
|
4
|
+
* @example
|
|
5
|
+
* ```javascript
|
|
6
|
+
* import { AlreadyExistsError } from "@visulima/fs/error"; // Assuming it's exported from an index or directly
|
|
7
|
+
* import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might throw this
|
|
8
|
+
* import { join } from "node:path";
|
|
9
|
+
*
|
|
10
|
+
* try {
|
|
11
|
+
* // Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName
|
|
12
|
+
* // For demonstration, let's assume someFunction internally throws it:
|
|
13
|
+
* const someFunctionThatMightThrow = (path) => {
|
|
14
|
+
* if (path === "/tmp/existing-file.txt") { // Simulate a check
|
|
15
|
+
* throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* someFunctionThatMightThrow("/tmp/existing-file.txt");
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* if (error instanceof AlreadyExistsError) {
|
|
21
|
+
* console.error(`Operation failed because path exists: ${error.message}`);
|
|
22
|
+
* console.error(`Error code: ${error.code}`); // EEXIST
|
|
23
|
+
* } else {
|
|
24
|
+
* console.error("An unexpected error occurred:", error);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare class AlreadyExistsError extends Error {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new instance.
|
|
32
|
+
* @param message
|
|
33
|
+
*/
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
get code(): string;
|
|
36
|
+
set code(_name: string);
|
|
37
|
+
override get name(): string;
|
|
38
|
+
override set name(_name: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Error thrown when an operation that is not allowed on a directory is attempted.
|
|
42
|
+
* This typically occurs when a file-specific operation is used on a directory path.
|
|
43
|
+
* @example
|
|
44
|
+
* ```javascript
|
|
45
|
+
* import { DirectoryError } from "@visulima/fs/error";
|
|
46
|
+
* import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
47
|
+
* import { join } from "node:path";
|
|
48
|
+
*
|
|
49
|
+
* const attemptToReadFileFromDir = async () => {
|
|
50
|
+
* try {
|
|
51
|
+
* // Attempting to read a directory as if it were a file
|
|
52
|
+
* // This is a conceptual example; readFile might throw a different error first
|
|
53
|
+
* // depending on its internal checks, but EISDIR is the underlying system error.
|
|
54
|
+
* // Forcing the scenario:
|
|
55
|
+
* const pretendReadFileOnDir = (path) => {
|
|
56
|
+
* if (path === "/tmp/my-directory") { // Simulate a directory path
|
|
57
|
+
* throw new DirectoryError(`read '/tmp/my-directory'`);
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* pretendReadFileOnDir("/tmp/my-directory");
|
|
61
|
+
* // await readFile(join("/tmp", "my-directory"));
|
|
62
|
+
* } catch (error) {
|
|
63
|
+
* if (error instanceof DirectoryError) {
|
|
64
|
+
* console.error(`Operation failed, path is a directory: ${error.message}`);
|
|
65
|
+
* console.error(`Error code: ${error.code}`); // EISDIR
|
|
66
|
+
* } else {
|
|
67
|
+
* console.error("An unexpected error occurred:", error);
|
|
68
|
+
* }
|
|
69
|
+
* }
|
|
70
|
+
* };
|
|
71
|
+
*
|
|
72
|
+
* attemptToReadFileFromDir();
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare class DirectoryError extends Error {
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new instance.
|
|
78
|
+
* @param message
|
|
79
|
+
*/
|
|
80
|
+
constructor(message: string);
|
|
81
|
+
get code(): string;
|
|
82
|
+
set code(_name: string);
|
|
83
|
+
override get name(): string;
|
|
84
|
+
override set name(_name: string);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when a directory is not empty.
|
|
88
|
+
* @example
|
|
89
|
+
* ```javascript
|
|
90
|
+
* import { NotEmptyError } from "@visulima/fs/error";
|
|
91
|
+
* import { rmdir } from "node:fs/promises"; // Or any fs function that might throw this system error
|
|
92
|
+
* import { join } from "node:path";
|
|
93
|
+
*
|
|
94
|
+
* const attemptToRemoveNonEmptyDir = async () => {
|
|
95
|
+
* const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files
|
|
96
|
+
* try {
|
|
97
|
+
* // Forcing the scenario for demonstration, as rmdir might throw its own specific error.
|
|
98
|
+
* // Node.js fs operations that encounter a non-empty directory when expecting an empty one
|
|
99
|
+
* // typically throw an error with code ENOTEMPTY.
|
|
100
|
+
* const simulateNotEmpty = (path) => {
|
|
101
|
+
* if (path === dirPath) { // Simulate check for non-empty
|
|
102
|
+
* throw new NotEmptyError(`rmdir '${dirPath}'`);
|
|
103
|
+
* }
|
|
104
|
+
* }
|
|
105
|
+
* simulateNotEmpty(dirPath);
|
|
106
|
+
* // await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY
|
|
107
|
+
* } catch (error) {
|
|
108
|
+
* if (error instanceof NotEmptyError) {
|
|
109
|
+
* console.error(`Operation failed, directory is not empty: ${error.message}`);
|
|
110
|
+
* console.error(`Error code: ${error.code}`); // ENOTEMPTY
|
|
111
|
+
* } else {
|
|
112
|
+
* console.error("An unexpected error occurred:", error);
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* };
|
|
116
|
+
*
|
|
117
|
+
* // You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test
|
|
118
|
+
* // import { ensureDirSync, writeFileSync } from "@visulima/fs";
|
|
119
|
+
* // ensureDirSync(dirPath);
|
|
120
|
+
* // writeFileSync(join(dirPath, "somefile.txt"), "content");
|
|
121
|
+
*
|
|
122
|
+
* attemptToRemoveNonEmptyDir();
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare class NotEmptyError extends Error {
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new instance.
|
|
128
|
+
* @param message
|
|
129
|
+
*/
|
|
130
|
+
constructor(message: string);
|
|
131
|
+
get code(): string;
|
|
132
|
+
set code(_name: string);
|
|
133
|
+
override get name(): string;
|
|
134
|
+
override set name(_name: string);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Error thrown when a file or directory is not found at a specified path.
|
|
138
|
+
* @example
|
|
139
|
+
* ```javascript
|
|
140
|
+
* import { NotFoundError } from "@visulima/fs/error";
|
|
141
|
+
* import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
142
|
+
* import { join } from "node:path";
|
|
143
|
+
*
|
|
144
|
+
* const tryReadingNonExistentFile = async () => {
|
|
145
|
+
* const filePath = join("/tmp", "this-file-does-not-exist.txt");
|
|
146
|
+
* try {
|
|
147
|
+
* // Forcing the scenario for demonstration, as readFile itself would throw this.
|
|
148
|
+
* const simulateNotFound = (path) => {
|
|
149
|
+
* if (path === filePath) {
|
|
150
|
+
* throw new NotFoundError(`no such file or directory, open '${filePath}'`);
|
|
151
|
+
* }
|
|
152
|
+
* }
|
|
153
|
+
* simulateNotFound(filePath);
|
|
154
|
+
* // await readFile(filePath);
|
|
155
|
+
* } catch (error) {
|
|
156
|
+
* if (error instanceof NotFoundError) {
|
|
157
|
+
* console.error(`Operation failed, path not found: ${error.message}`);
|
|
158
|
+
* console.error(`Error code: ${error.code}`); // ENOENT
|
|
159
|
+
* } else {
|
|
160
|
+
* console.error("An unexpected error occurred:", error);
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* };
|
|
164
|
+
*
|
|
165
|
+
* tryReadingNonExistentFile();
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare class NotFoundError extends Error {
|
|
169
|
+
/**
|
|
170
|
+
* Creates a new instance.
|
|
171
|
+
* @param message
|
|
172
|
+
*/
|
|
173
|
+
constructor(message: string);
|
|
174
|
+
get code(): string;
|
|
175
|
+
set code(_name: string);
|
|
176
|
+
override get name(): string;
|
|
177
|
+
override set name(_name: string);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Error thrown when an operation is not permitted due to insufficient privileges
|
|
181
|
+
* or other access control restrictions.
|
|
182
|
+
* @example
|
|
183
|
+
* ```javascript
|
|
184
|
+
* import { PermissionError } from "@visulima/fs/error";
|
|
185
|
+
* import { writeFile } from "@visulima/fs"; // Or any function that might throw this
|
|
186
|
+
* import { join } from "node:path";
|
|
187
|
+
*
|
|
188
|
+
* const tryWritingToProtectedFile = async () => {
|
|
189
|
+
* const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges
|
|
190
|
+
* try {
|
|
191
|
+
* // Forcing the scenario for demonstration, as writeFile itself would throw this.
|
|
192
|
+
* const simulatePermissionError = (path) => {
|
|
193
|
+
* if (path === filePath) {
|
|
194
|
+
* throw new PermissionError(`open '${filePath}'`);
|
|
195
|
+
* }
|
|
196
|
+
* }
|
|
197
|
+
* simulatePermissionError(filePath);
|
|
198
|
+
* // await writeFile(filePath, "test content");
|
|
199
|
+
* } catch (error) {
|
|
200
|
+
* if (error instanceof PermissionError) {
|
|
201
|
+
* console.error(`Operation not permitted: ${error.message}`);
|
|
202
|
+
* console.error(`Error code: ${error.code}`); // EPERM
|
|
203
|
+
* } else {
|
|
204
|
+
* console.error("An unexpected error occurred:", error);
|
|
205
|
+
* }
|
|
206
|
+
* }
|
|
207
|
+
* };
|
|
208
|
+
*
|
|
209
|
+
* tryWritingToProtectedFile();
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
declare class PermissionError extends Error {
|
|
213
|
+
/**
|
|
214
|
+
* Creates a new instance.
|
|
215
|
+
* @param message
|
|
216
|
+
*/
|
|
217
|
+
constructor(message: string);
|
|
218
|
+
get code(): string;
|
|
219
|
+
set code(_name: string);
|
|
220
|
+
override get name(): string;
|
|
221
|
+
override set name(_name: string);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Error thrown in walk or walkSync during iteration.
|
|
225
|
+
* @example
|
|
226
|
+
* ```javascript
|
|
227
|
+
* import { WalkError } from "@visulima/fs/error";
|
|
228
|
+
* import { walk } from "@visulima/fs";
|
|
229
|
+
* import { join } from "node:path";
|
|
230
|
+
*
|
|
231
|
+
* const processDirectory = async () => {
|
|
232
|
+
* const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
|
|
233
|
+
* try {
|
|
234
|
+
* // Forcing the scenario: walk might throw a WalkError if it encounters an issue
|
|
235
|
+
* // like a directory it cannot read during the walk process.
|
|
236
|
+
* const simulateWalkError = async (rootDir) => {
|
|
237
|
+
* // Let's say readdir inside walk fails for a subdirectory.
|
|
238
|
+
* const underlyingError = new Error("Permission denied reading subdirectory");
|
|
239
|
+
* throw new WalkError(underlyingError, rootDir);
|
|
240
|
+
* }
|
|
241
|
+
* // This is conceptual. In a real scenario, 'walk' itself would throw.
|
|
242
|
+
* // for await (const entry of walk(dirToWalk)) {
|
|
243
|
+
* // console.log(entry.path);
|
|
244
|
+
* // }
|
|
245
|
+
* await simulateWalkError(dirToWalk);
|
|
246
|
+
* } catch (error) {
|
|
247
|
+
* if (error instanceof WalkError) {
|
|
248
|
+
* console.error(`Error during directory walk of "${error.root}": ${error.message}`);
|
|
249
|
+
* if (error.cause) {
|
|
250
|
+
* console.error(`Underlying cause: ${error.cause}`);
|
|
251
|
+
* }
|
|
252
|
+
* } else {
|
|
253
|
+
* console.error("An unexpected error occurred:", error);
|
|
254
|
+
* }
|
|
255
|
+
* }
|
|
256
|
+
* };
|
|
257
|
+
*
|
|
258
|
+
* processDirectory();
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare class WalkError extends Error {
|
|
262
|
+
/** File path of the root that's being walked. */
|
|
263
|
+
root: string;
|
|
264
|
+
/**
|
|
265
|
+
* Constructs a new instance.
|
|
266
|
+
* @param cause The underlying error or reason for the walk failure.
|
|
267
|
+
* @param root The root directory path where the walk operation started or encountered the error.
|
|
268
|
+
*/
|
|
269
|
+
constructor(cause: unknown, root: string);
|
|
270
|
+
override get name(): string;
|
|
271
|
+
override set name(_name: string);
|
|
272
|
+
}
|
|
273
|
+
export { AlreadyExistsError, DirectoryError, NotEmptyError, NotFoundError, PermissionError, WalkError };
|
package/dist/error.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as DirectoryError } from './packem_shared/DirectoryError-BfYPkIYP.js';
|
|
3
|
-
export { default as JSONError } from './packem_shared/JSONError-BkHRnInH.js';
|
|
4
|
-
export { default as NotEmptyError } from './packem_shared/NotEmptyError-B21RUlVr.js';
|
|
5
|
-
export { default as NotFoundError } from './packem_shared/NotFoundError-BIp61X6k.js';
|
|
6
|
-
export { default as PermissionError } from './packem_shared/PermissionError-CjoiJgip.js';
|
|
7
|
-
export { default as WalkError } from './packem_shared/WalkError-DUdQd6FT.js';
|
|
1
|
+
import{default as t}from"./packem_shared/AlreadyExistsError-CEu6_Tjb.js";import{default as a}from"./packem_shared/DirectoryError-ddlbUV8C.js";import{default as s}from"./packem_shared/JSONError-D7h6PNWc.js";import{default as l}from"./packem_shared/NotEmptyError-DMh1o7UL.js";import{default as E}from"./packem_shared/NotFoundError-BPiW0icm.js";import{default as u}from"./packem_shared/PermissionError-B1Emi5a9.js";import{default as i}from"./packem_shared/WalkError-Olmh4908.js";export{t as AlreadyExistsError,a as DirectoryError,s as JSONError,l as NotEmptyError,E as NotFoundError,u as PermissionError,i as WalkError};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options accepted by {@link globParent}.
|
|
3
|
+
*/
|
|
4
|
+
interface GlobParentOptions {
|
|
5
|
+
/**
|
|
6
|
+
* On Windows, flip backslashes to forward slashes before analysing the pattern.
|
|
7
|
+
*
|
|
8
|
+
* Disable when the input contains backslash escape sequences you want to preserve.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
flipBackslashes?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Extracts the non-glob parent directory from a glob pattern.
|
|
15
|
+
*
|
|
16
|
+
* Useful when you need to know which directory to watch or walk for a given pattern — for example
|
|
17
|
+
* `src/**\/*.ts` → `src`, `foo/{a,b}/*.js` → `foo`. Patterns without glob characters are returned
|
|
18
|
+
* unchanged.
|
|
19
|
+
*
|
|
20
|
+
* Powered by [`glob-parent`](https://github.com/gulpjs/glob-parent) which is bundled into the built output so
|
|
21
|
+
* it does not appear as a runtime dependency of `@visulima/fs`.
|
|
22
|
+
* @param pattern The glob pattern to inspect.
|
|
23
|
+
* @param options Optional configuration. See {@link GlobParentOptions}.
|
|
24
|
+
* @returns The static parent path of the glob.
|
|
25
|
+
* @example
|
|
26
|
+
* ```javascript
|
|
27
|
+
* import { globParent } from "@visulima/fs";
|
|
28
|
+
*
|
|
29
|
+
* globParent("src/**\/*.ts"); // "src"
|
|
30
|
+
* globParent("foo/{a,b}/*.js"); // "foo"
|
|
31
|
+
* globParent("foo/bar.js"); // "foo/bar.js"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const globParent: (pattern: string, options?: GlobParentOptions) => string;
|
|
35
|
+
export { type GlobParentOptions, globParent as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _=Object.defineProperty;var t=(s,r)=>_(s,"name",{value:r,configurable:!0});import{createRequire as P}from"node:module";import{g as q}from"./packem_shared/_commonjsHelpers-D6W6KoPK.js";import{r as x}from"./packem_shared/index-K-NNTkpb.js";const j=P(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,d=t(s=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[r,a]=i.versions.node.split(".").map(Number);if(r>22||r===22&&a>=3||r===20&&a>=16)return i.getBuiltinModule(s)}return j(s)},"__cjs_getBuiltinModule"),y=d("path"),G=d("os");var u,b;function $(){if(b)return u;b=1;var s=Object.defineProperty,r=t((e,n)=>s(e,"name",{value:n,configurable:!0}),"n"),a=x(),g=y.posix.dirname,m=G.platform()==="win32",l="/",v=/\\/g,h=/\\([!*?|[\](){}])/g;u=r(function(e,n){var o=Object.assign({flipBackslashes:!0},n);o.flipBackslashes&&m&&e.indexOf(l)<0&&(e=e.replace(v,l)),c(e)&&(e+=l),e+="a";do e=g(e);while(f(e));return e.replace(h,"$1")},"globParent");function c(e){var n=e.slice(-1),o;switch(n){case"}":o="{";break;case"]":o="[";break;default:return!1}var p=e.indexOf(o);return p<0?!1:e.slice(p+1,-1).includes(l)}t(c,"isEnclosure"),r(c,"isEnclosure");function f(e){return/\([^()]+$/.test(e)||e[0]==="{"||e[0]==="["||/[^\\][{[]/.test(e)?!0:a(e)}return t(f,"isGlobby"),r(f,"isGlobby"),u}t($,"requireGlobParent");var k=$();const O=q(k);var B=Object.defineProperty,E=t((s,r)=>B(s,"name",{value:r,configurable:!0}),"e");const M=E((s,r)=>O(s,r),"globParent");export{M as default};
|
package/dist/glob.d.ts
ADDED
package/dist/glob.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as e}from"./packem_shared/glob-MHJQjR39.js";import{default as l}from"./packem_shared/globSync-CwzlELgS.js";export{e as glob,l as globSync};
|