@visulima/fs 4.0.3 → 4.0.5
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 +35 -0
- package/LICENSE.md +4 -1
- package/dist/constants.d.ts +42 -0
- package/dist/ensure/ensure-dir-sync.d.ts +14 -0
- package/dist/ensure/ensure-dir.d.ts +14 -0
- package/dist/ensure/ensure-file-sync.d.ts +15 -0
- package/dist/ensure/ensure-file.d.ts +27 -0
- package/dist/ensure/ensure-link-sync.d.ts +16 -0
- package/dist/ensure/ensure-link.d.ts +16 -0
- package/dist/ensure/ensure-symlink-sync.d.ts +23 -0
- package/dist/ensure/ensure-symlink.d.ts +23 -0
- package/dist/ensure/utils/get-file-info-type.d.ts +7 -0
- package/dist/ensure/utils/is-stats-identical.d.ts +3 -0
- package/dist/ensure/utils/resolve-symlink-target.d.ts +2 -0
- package/dist/eol.d.ts +35 -7
- package/dist/eol.js +26 -3
- package/dist/error/already-exists-error.d.ts +39 -0
- package/dist/error/directory-error.d.ts +47 -0
- package/dist/error/json-error.d.ts +52 -0
- package/dist/error/not-empty-error.d.ts +51 -0
- package/dist/error/not-found-error.d.ts +44 -0
- package/dist/error/permission-error.d.ts +45 -0
- package/dist/error/walk-error.d.ts +51 -0
- package/dist/error.d.ts +7 -50
- package/dist/error.js +7 -1
- package/dist/find/collect-sync.d.ts +31 -0
- package/dist/find/collect.d.ts +35 -0
- package/dist/find/find-up-sync.d.ts +42 -0
- package/dist/find/find-up.d.ts +46 -0
- package/dist/find/utils/glob-to-regex.d.ts +2 -0
- package/dist/find/utils/walk-include.d.ts +2 -0
- package/dist/find/walk-sync.d.ts +26 -0
- package/dist/find/walk.d.ts +29 -0
- package/dist/index.d.ts +34 -136
- package/dist/index.js +32 -1
- package/dist/is-accessible-sync.d.ts +3 -0
- package/dist/is-accessible.d.ts +29 -0
- package/dist/move/index.d.ts +70 -0
- package/dist/move/types.d.ts +38 -0
- package/dist/move/utils/internal-move-file-sync.d.ts +3 -0
- package/dist/move/utils/internal-move-file.d.ts +3 -0
- package/dist/move/utils/validate-same-directory.d.ts +2 -0
- package/dist/packem_shared/AlreadyExistsError-D5BGeeNR.js +27 -0
- package/dist/packem_shared/DirectoryError-CaUV2Pbk.js +27 -0
- package/dist/packem_shared/F_OK-BalxCn9n.js +8 -0
- package/dist/packem_shared/JSONError-BkHRnInH.js +26 -0
- package/dist/packem_shared/NotEmptyError-mOHWXE0m.js +27 -0
- package/dist/packem_shared/NotFoundError-D4llRgRs.js +27 -0
- package/dist/packem_shared/PermissionError-1qs0skfo.js +27 -0
- package/dist/packem_shared/WalkError-DUdQd6FT.js +24 -0
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +7 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +7 -0
- package/dist/packem_shared/collect-DcBwsYYd.js +14 -0
- package/dist/packem_shared/collectSync-Bkjf9Dbm.js +14 -0
- package/dist/packem_shared/emptyDir-CYB5Tict.js +43 -0
- package/dist/packem_shared/emptyDirSync-BD8-1Ytl.js +41 -0
- package/dist/packem_shared/ensureDir-C_kuQ5Ik.js +53 -0
- package/dist/packem_shared/ensureDirSync-CI5g-uBI.js +53 -0
- package/dist/packem_shared/ensureFile-BUtXGlGT.js +47 -0
- package/dist/packem_shared/ensureFileSync-C8hASR-1.js +47 -0
- package/dist/packem_shared/ensureLink-BPnAG5-P.js +54 -0
- package/dist/packem_shared/ensureLinkSync-B-Z7X0ub.js +54 -0
- package/dist/packem_shared/ensureSymlink-BGz6W-Wa.js +73 -0
- package/dist/packem_shared/ensureSymlinkSync-C5Gk8QYi.js +74 -0
- package/dist/packem_shared/findUp-Lv9mZCIQ.js +85 -0
- package/dist/packem_shared/findUpSync-BsK4Nrrq.js +85 -0
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +14 -0
- package/dist/packem_shared/index-CHM-in-V.js +100 -0
- package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +3 -0
- package/dist/packem_shared/isAccessible-iOp0Bou6.js +38 -0
- package/dist/packem_shared/isAccessibleSync-38BmiIcx.js +38 -0
- package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +62 -0
- package/dist/packem_shared/move-BD6JbYSu.js +134 -0
- package/dist/packem_shared/parseJson-CqUuRguZ.js +231 -0
- package/dist/packem_shared/readFile-XVOjAw8r.js +65 -0
- package/dist/packem_shared/readFileSync-B9Zg5PSF.js +53 -0
- package/dist/packem_shared/readJson-Dra2m6s-.js +22 -0
- package/dist/packem_shared/readJsonSync-B6Dl1I_6.js +22 -0
- package/dist/packem_shared/readYaml-Bu1nsexB.js +10 -0
- package/dist/packem_shared/readYamlSync-Di88aMME.js +10 -0
- package/dist/packem_shared/remove-_oDY3uKo.js +38 -0
- package/dist/packem_shared/removeSync-DETRj7Qn.js +38 -0
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +16 -0
- package/dist/packem_shared/stripJsonComments-21XWVDwP.js +19 -0
- package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +19 -0
- package/dist/packem_shared/walk-BhTbpr3y.js +115 -0
- package/dist/packem_shared/walk-include-CZco7BvN.js +16 -0
- package/dist/packem_shared/walkSync-DDBq95s8.js +114 -0
- package/dist/packem_shared/writeFile-NT1fLEEe.js +83 -0
- package/dist/packem_shared/writeFileSync-Bj5UDSf0.js +83 -0
- package/dist/packem_shared/writeJson-DQLdAi0d.js +50 -0
- package/dist/packem_shared/writeJsonSync-DvTCjVUi.js +50 -0
- package/dist/packem_shared/writeYaml-BMY0kOPf.js +24 -0
- package/dist/packem_shared/writeYamlSync-DqPu8cCd.js +24 -0
- package/dist/read/read-file-sync.d.ts +37 -0
- package/dist/read/read-file.d.ts +41 -0
- package/dist/read/read-json-sync.d.ts +5 -0
- package/dist/read/read-json.d.ts +5 -0
- package/dist/read/read-yaml-sync.d.ts +4 -0
- package/dist/read/read-yaml.d.ts +4 -0
- package/dist/remove/empty-dir-sync.d.ts +24 -0
- package/dist/remove/empty-dir.d.ts +28 -0
- package/dist/remove/remove-sync.d.ts +28 -0
- package/dist/remove/remove.d.ts +32 -0
- package/dist/size.d.ts +245 -12
- package/dist/size.js +144 -1
- package/dist/types.d.ts +299 -0
- package/dist/utils/assert-valid-file-contents.d.ts +27 -0
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +26 -0
- package/dist/utils/parse-json.d.ts +5 -0
- package/dist/utils/strip-json-comments.d.ts +44 -0
- package/dist/utils.d.ts +6 -19
- package/dist/utils.js +6 -1
- package/dist/write/utils/to-uint-8-array.d.ts +2 -0
- package/dist/write/write-file-sync.d.ts +30 -0
- package/dist/write/write-file.d.ts +30 -0
- package/dist/write/write-json-sync.d.ts +30 -0
- package/dist/write/write-json.d.ts +30 -0
- package/dist/write/write-yaml-sync.d.ts +4 -0
- package/dist/write/write-yaml.d.ts +4 -0
- package/dist/yaml.d.ts +5 -17
- package/dist/yaml.js +4 -1
- package/package.json +2 -3
- package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.js +0 -1
- package/dist/packem_shared/DirectoryError-ddlbUV8C.js +0 -1
- package/dist/packem_shared/F_OK-CAwY1qU7.js +0 -1
- package/dist/packem_shared/JSONError-D7h6PNWc.js +0 -4
- package/dist/packem_shared/NotEmptyError-DMh1o7UL.js +0 -1
- package/dist/packem_shared/NotFoundError-BPiW0icm.js +0 -1
- package/dist/packem_shared/PermissionError-B1Emi5a9.js +0 -1
- package/dist/packem_shared/WalkError-BsngoIKJ.js +0 -1
- package/dist/packem_shared/assertValidFileContents-BZFnXa7K.js +0 -1
- package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.js +0 -1
- package/dist/packem_shared/collect-DO31RsLs.js +0 -1
- package/dist/packem_shared/collectSync-Cy7ULmjZ.js +0 -1
- package/dist/packem_shared/emptyDir-zBLHyPsJ.js +0 -1
- package/dist/packem_shared/emptyDirSync-DZ8nTo6g.js +0 -1
- package/dist/packem_shared/ensureDir-CwcwvbZ0.js +0 -1
- package/dist/packem_shared/ensureDirSync-DsFhH5oQ.js +0 -1
- package/dist/packem_shared/ensureFile-DwcEQVDX.js +0 -1
- package/dist/packem_shared/ensureFileSync-KnrH51Ox.js +0 -1
- package/dist/packem_shared/ensureLink-5rjQGEBb.js +0 -1
- package/dist/packem_shared/ensureLinkSync-CYXpscf2.js +0 -1
- package/dist/packem_shared/ensureSymlink-GATTbE5c.js +0 -1
- package/dist/packem_shared/ensureSymlinkSync-CvXgTFrl.js +0 -1
- package/dist/packem_shared/findUp-Di7Az07S.js +0 -1
- package/dist/packem_shared/findUpSync-iV97v14Q.js +0 -1
- package/dist/packem_shared/get-file-info-type-CaWGXRjY.js +0 -1
- package/dist/packem_shared/index-CYIVJA0W.js +0 -1
- package/dist/packem_shared/is-stats-identical-CohsLtWy.js +0 -1
- package/dist/packem_shared/isAccessible-CDFxsAAo.js +0 -1
- package/dist/packem_shared/isAccessibleSync-5nzZWgin.js +0 -1
- package/dist/packem_shared/isFsCaseSensitive-Drl8fHLV.js +0 -1
- package/dist/packem_shared/json-error-ZPgZIXcg.d.ts +0 -11
- package/dist/packem_shared/move-Bz4gSIjp.js +0 -1
- package/dist/packem_shared/parseJson-Cj4v3qzl.js +0 -6
- package/dist/packem_shared/readFile-CbxFM_zp.js +0 -1
- package/dist/packem_shared/readFileSync-B9iv2Sb8.js +0 -1
- package/dist/packem_shared/readJson-BgC3msx-.js +0 -1
- package/dist/packem_shared/readJsonSync-DHO1vjAG.js +0 -1
- package/dist/packem_shared/readYaml-D5mtfANg.js +0 -1
- package/dist/packem_shared/readYamlSync-D0igCVDE.js +0 -1
- package/dist/packem_shared/remove-BUqZUj1W.js +0 -1
- package/dist/packem_shared/removeSync-BbT4vmDi.js +0 -1
- package/dist/packem_shared/resolve-symlink-target-BofZSDIc.js +0 -1
- package/dist/packem_shared/stripJsonComments-DbMjL4qv.js +0 -1
- package/dist/packem_shared/to-uint-8-array-DwgaTasY.js +0 -1
- package/dist/packem_shared/types-T308NKwz.d.ts +0 -90
- package/dist/packem_shared/walk-ZrZngpc4.js +0 -1
- package/dist/packem_shared/walk-include-DCiVAwMP.js +0 -1
- package/dist/packem_shared/walkSync-BQa4NKSG.js +0 -1
- package/dist/packem_shared/writeFile-D5OYEMHu.js +0 -1
- package/dist/packem_shared/writeFileSync-CO4ySqUn.js +0 -1
- package/dist/packem_shared/writeJson-DfmgiY_s.js +0 -4
- package/dist/packem_shared/writeJsonSync-Ck1pmmj_.js +0 -4
- package/dist/packem_shared/writeYaml-BJeyUpyY.js +0 -1
- package/dist/packem_shared/writeYamlSync-D87XCS7Y.js +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const y = __cjs_getBuiltinModule("fs");
|
|
21
|
+
const h = __cjs_getBuiltinModule("os");
|
|
22
|
+
const u = __cjs_getBuiltinModule("path");
|
|
23
|
+
|
|
24
|
+
var l = Object.defineProperty;
|
|
25
|
+
var s = (i, t) => l(i, "name", { value: t, configurable: true });
|
|
26
|
+
const a = s((i) => {
|
|
27
|
+
let t = "";
|
|
28
|
+
for (let e = 0; e < i.length; e += 1) {
|
|
29
|
+
const r = i[e], o = r.toUpperCase();
|
|
30
|
+
t += r === o ? r.toLowerCase() : o;
|
|
31
|
+
}
|
|
32
|
+
return t;
|
|
33
|
+
}, "invertCase");
|
|
34
|
+
const c = /* @__PURE__ */ new Map();
|
|
35
|
+
const p = s((i, t) => {
|
|
36
|
+
const e = u.join(i, `.is-fs-case-sensitive-test-${process.pid}`);
|
|
37
|
+
try {
|
|
38
|
+
return t.writeFileSync(e, ""), !t.existsSync(a(e));
|
|
39
|
+
} finally {
|
|
40
|
+
try {
|
|
41
|
+
t.unlinkSync(e);
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, "checkDirectoryCaseWithWrite");
|
|
46
|
+
const m = s((i, t, e) => {
|
|
47
|
+
try {
|
|
48
|
+
return p(i, e);
|
|
49
|
+
} catch (r) {
|
|
50
|
+
if (t === void 0) return p(h.tmpdir(), e);
|
|
51
|
+
throw r;
|
|
52
|
+
}
|
|
53
|
+
}, "checkDirectoryCaseWithFallback");
|
|
54
|
+
const S = s((i, t = y, e = true) => {
|
|
55
|
+
const r = i ?? process.cwd();
|
|
56
|
+
if (e && c.has(r)) return c.get(r);
|
|
57
|
+
let o;
|
|
58
|
+
const n = a(r);
|
|
59
|
+
return n !== r && t.existsSync(r) ? o = !t.existsSync(n) : o = m(r, i, t), e && c.set(r, o), o;
|
|
60
|
+
}, "isFsCaseSensitive");
|
|
61
|
+
|
|
62
|
+
export { S as isFsCaseSensitive };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
cwd
|
|
22
|
+
} = __cjs_getProcess;
|
|
23
|
+
import { toPath } from '@visulima/path/utils';
|
|
24
|
+
const {
|
|
25
|
+
mkdir,
|
|
26
|
+
rename: rename$1,
|
|
27
|
+
copyFile,
|
|
28
|
+
unlink
|
|
29
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
30
|
+
import { dirname, resolve } from '@visulima/path';
|
|
31
|
+
import isAccessible from './isAccessible-iOp0Bou6.js';
|
|
32
|
+
const {
|
|
33
|
+
mkdirSync,
|
|
34
|
+
renameSync: renameSync$1,
|
|
35
|
+
copyFileSync,
|
|
36
|
+
unlinkSync
|
|
37
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
38
|
+
import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
|
|
39
|
+
|
|
40
|
+
class SameDirectoryError extends Error {
|
|
41
|
+
constructor(source, destination) {
|
|
42
|
+
super(`Source directory "${dirname(source)}" does not match destination directory "${dirname(destination)}"`);
|
|
43
|
+
this.name = "SameDirectoryError";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const validateSameDirectory = (source, destination) => {
|
|
47
|
+
if (!source || !destination) {
|
|
48
|
+
throw new Error("Source and destination paths must not be empty");
|
|
49
|
+
}
|
|
50
|
+
if (dirname(source) !== dirname(destination)) {
|
|
51
|
+
throw new SameDirectoryError(source, destination);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const internalMoveFile = async (sourcePath, destinationPath, { cwd, directoryMode, overwrite, validateDirectory }) => {
|
|
56
|
+
if (cwd) {
|
|
57
|
+
sourcePath = resolve(cwd, sourcePath);
|
|
58
|
+
destinationPath = resolve(cwd, destinationPath);
|
|
59
|
+
}
|
|
60
|
+
if (validateDirectory) {
|
|
61
|
+
validateSameDirectory(sourcePath, destinationPath);
|
|
62
|
+
}
|
|
63
|
+
if (!overwrite && await isAccessible(destinationPath)) {
|
|
64
|
+
throw new Error(`The destination file exists: ${destinationPath}`);
|
|
65
|
+
}
|
|
66
|
+
await mkdir(dirname(destinationPath), {
|
|
67
|
+
mode: directoryMode,
|
|
68
|
+
recursive: true
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
await rename$1(sourcePath, destinationPath);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (error.code === "EXDEV") {
|
|
74
|
+
await copyFile(sourcePath, destinationPath);
|
|
75
|
+
await unlink(sourcePath);
|
|
76
|
+
} else {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const internalMoveFileSync = (sourcePath, destinationPath, { cwd, directoryMode, overwrite, validateDirectory }) => {
|
|
83
|
+
if (cwd) {
|
|
84
|
+
sourcePath = resolve(cwd, sourcePath);
|
|
85
|
+
destinationPath = resolve(cwd, destinationPath);
|
|
86
|
+
}
|
|
87
|
+
if (validateDirectory) {
|
|
88
|
+
validateSameDirectory(sourcePath, destinationPath);
|
|
89
|
+
}
|
|
90
|
+
if (!overwrite && isAccessibleSync(destinationPath)) {
|
|
91
|
+
throw new Error(`The destination file exists: ${destinationPath}`);
|
|
92
|
+
}
|
|
93
|
+
mkdirSync(dirname(destinationPath), {
|
|
94
|
+
mode: directoryMode,
|
|
95
|
+
recursive: true
|
|
96
|
+
});
|
|
97
|
+
try {
|
|
98
|
+
renameSync$1(sourcePath, destinationPath);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error.code === "EXDEV") {
|
|
101
|
+
copyFileSync(sourcePath, destinationPath);
|
|
102
|
+
unlinkSync(sourcePath);
|
|
103
|
+
} else {
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const move = async (sourcePath, destinationPath, options = {}) => {
|
|
110
|
+
const internalOptions = {
|
|
111
|
+
overwrite: true,
|
|
112
|
+
validateDirectory: false,
|
|
113
|
+
...options,
|
|
114
|
+
cwd: options.cwd ? toPath(options.cwd) : cwd()
|
|
115
|
+
};
|
|
116
|
+
await internalMoveFile(sourcePath, destinationPath, internalOptions);
|
|
117
|
+
};
|
|
118
|
+
const moveSync = (sourcePath, destinationPath, options) => {
|
|
119
|
+
const internalOptions = { overwrite: true, validateDirectory: false, ...options };
|
|
120
|
+
internalOptions.cwd = internalOptions.cwd ? toPath(internalOptions.cwd) : cwd();
|
|
121
|
+
internalMoveFileSync(sourcePath, destinationPath, internalOptions);
|
|
122
|
+
};
|
|
123
|
+
const rename = async (source, destination, options) => {
|
|
124
|
+
const internalOptions = { overwrite: true, ...options, validateDirectory: true };
|
|
125
|
+
internalOptions.cwd = internalOptions.cwd ? toPath(internalOptions.cwd) : cwd();
|
|
126
|
+
await internalMoveFile(source, destination, internalOptions);
|
|
127
|
+
};
|
|
128
|
+
const renameSync = (source, destination, options) => {
|
|
129
|
+
const internalOptions = { overwrite: true, ...options, validateDirectory: true };
|
|
130
|
+
internalOptions.cwd = internalOptions.cwd ? toPath(internalOptions.cwd) : cwd();
|
|
131
|
+
internalMoveFileSync(source, destination, internalOptions);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export { move, moveSync, rename, renameSync };
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import JSONError from './JSONError-BkHRnInH.js';
|
|
2
|
+
|
|
3
|
+
const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
|
|
4
|
+
const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
|
|
5
|
+
const processShims = {
|
|
6
|
+
versions: {}
|
|
7
|
+
};
|
|
8
|
+
const process = new Proxy(_process, {
|
|
9
|
+
get(target, property) {
|
|
10
|
+
if (property in target) {
|
|
11
|
+
return target[property];
|
|
12
|
+
}
|
|
13
|
+
if (property in processShims) {
|
|
14
|
+
return processShims[property];
|
|
15
|
+
}
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const getMarkerLines = (loc, source, linesAbove, linesBelow) => {
|
|
20
|
+
const startLoc = {
|
|
21
|
+
column: 0,
|
|
22
|
+
// @ts-expect-error Can be overwritten
|
|
23
|
+
line: -1,
|
|
24
|
+
...loc.start
|
|
25
|
+
};
|
|
26
|
+
const endLoc = {
|
|
27
|
+
...startLoc,
|
|
28
|
+
...loc.end
|
|
29
|
+
};
|
|
30
|
+
const startLine = startLoc.line;
|
|
31
|
+
const startColumn = startLoc.column;
|
|
32
|
+
const endLine = endLoc.line;
|
|
33
|
+
const endColumn = endLoc.column;
|
|
34
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
35
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
36
|
+
if (startLine === -1) {
|
|
37
|
+
start = 0;
|
|
38
|
+
}
|
|
39
|
+
if (endLine === -1) {
|
|
40
|
+
end = source.length;
|
|
41
|
+
}
|
|
42
|
+
const lineDiff = endLine - startLine;
|
|
43
|
+
const markerLines = {};
|
|
44
|
+
if (lineDiff) {
|
|
45
|
+
for (let index = 0; index <= lineDiff; index++) {
|
|
46
|
+
const lineNumber = index + startLine;
|
|
47
|
+
if (!startColumn) {
|
|
48
|
+
markerLines[lineNumber] = true;
|
|
49
|
+
} else if (index === 0) {
|
|
50
|
+
const sourceLength = source[lineNumber - 1]?.length;
|
|
51
|
+
markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
|
|
52
|
+
} else if (index === lineDiff) {
|
|
53
|
+
markerLines[lineNumber] = [0, endColumn];
|
|
54
|
+
} else {
|
|
55
|
+
const sourceLength = source[lineNumber - index]?.length;
|
|
56
|
+
markerLines[lineNumber] = [0, sourceLength];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} else if (startColumn === endColumn) {
|
|
60
|
+
markerLines[startLine] = startColumn ? [startColumn, 0] : true;
|
|
61
|
+
} else {
|
|
62
|
+
markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
|
|
63
|
+
}
|
|
64
|
+
return { end, markerLines, start };
|
|
65
|
+
};
|
|
66
|
+
const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
|
|
67
|
+
const codeFrame = (source, loc, options) => {
|
|
68
|
+
const config = {
|
|
69
|
+
// grab 2 lines before, and 3 lines after focused line
|
|
70
|
+
linesAbove: 2,
|
|
71
|
+
linesBelow: 3,
|
|
72
|
+
prefix: "",
|
|
73
|
+
showGutter: true,
|
|
74
|
+
tabWidth: 4,
|
|
75
|
+
...options,
|
|
76
|
+
color: {
|
|
77
|
+
gutter: (value) => value,
|
|
78
|
+
marker: (value) => value,
|
|
79
|
+
message: (value) => value,
|
|
80
|
+
...options?.color
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const hasColumns = loc.start && typeof loc.start.column === "number";
|
|
84
|
+
let lines = normalizeLF(source).split("\n");
|
|
85
|
+
if (typeof config?.tabWidth === "number") {
|
|
86
|
+
lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
|
|
87
|
+
}
|
|
88
|
+
const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
|
|
89
|
+
const numberMaxWidth = String(end).length;
|
|
90
|
+
const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
|
|
91
|
+
let frame = lines.slice(start, end).map((line, index) => {
|
|
92
|
+
const number = start + 1 + index;
|
|
93
|
+
const hasMarker = markerLines[number];
|
|
94
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
95
|
+
const lastMarkerLine = !markerLines[number + 1];
|
|
96
|
+
const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
|
|
97
|
+
if (hasMarker) {
|
|
98
|
+
let markerLine = "";
|
|
99
|
+
if (Array.isArray(hasMarker)) {
|
|
100
|
+
const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
|
|
101
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
102
|
+
markerLine = [
|
|
103
|
+
"\n ",
|
|
104
|
+
config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
|
|
105
|
+
" ",
|
|
106
|
+
markerSpacing,
|
|
107
|
+
colorizeMarker("^").repeat(numberOfMarkers)
|
|
108
|
+
].join("");
|
|
109
|
+
if (lastMarkerLine && config.message) {
|
|
110
|
+
markerLine += ` ${colorizeMessage(config.message)}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
|
114
|
+
}
|
|
115
|
+
return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
|
|
116
|
+
}).join("\n");
|
|
117
|
+
if (config.message && !hasColumns) {
|
|
118
|
+
frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
|
|
119
|
+
${frame}`;
|
|
120
|
+
}
|
|
121
|
+
return frame;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const binarySearch = (element, array) => {
|
|
125
|
+
let m = 0;
|
|
126
|
+
let n = array.length - 2;
|
|
127
|
+
while (m < n) {
|
|
128
|
+
const key = m + (n - m >> 1);
|
|
129
|
+
if (element < array[key]) {
|
|
130
|
+
n = key - 1;
|
|
131
|
+
} else if (element >= array[key + 1]) {
|
|
132
|
+
m = key + 1;
|
|
133
|
+
} else {
|
|
134
|
+
m = key;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return m;
|
|
139
|
+
};
|
|
140
|
+
const getLineStartIndexes = (string_) => (
|
|
141
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
142
|
+
string_.split(/\n|\r(?!\n)/).reduce(
|
|
143
|
+
(accumulator, current) => {
|
|
144
|
+
accumulator.push(accumulator.at(-1) + current.length + 1);
|
|
145
|
+
return accumulator;
|
|
146
|
+
},
|
|
147
|
+
[0]
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
const indexToLineColumn = (input, index, options) => {
|
|
151
|
+
if ((!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
|
|
152
|
+
return { column: 0, line: 0 };
|
|
153
|
+
}
|
|
154
|
+
if ((typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
|
|
155
|
+
return { column: 0, line: 0 };
|
|
156
|
+
}
|
|
157
|
+
if (typeof input === "string") {
|
|
158
|
+
const startIndexesOfEachLine = getLineStartIndexes(input);
|
|
159
|
+
const line2 = binarySearch(index, startIndexesOfEachLine);
|
|
160
|
+
return {
|
|
161
|
+
column: index - startIndexesOfEachLine[line2] + 1,
|
|
162
|
+
line: line2 + 1
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const line = binarySearch(index, input);
|
|
166
|
+
return {
|
|
167
|
+
column: index - input[line] + 1,
|
|
168
|
+
line: line + 1
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const getCodePoint = (character) => `\\u{${character.codePointAt(0).toString(16)}}`;
|
|
173
|
+
const generateCodeFrame = (source, location, options) => codeFrame(
|
|
174
|
+
source,
|
|
175
|
+
{ start: location },
|
|
176
|
+
{
|
|
177
|
+
tabWidth: false,
|
|
178
|
+
...options
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
const getErrorLocation = (source, message) => {
|
|
182
|
+
const match = /in JSON at position (?<index>\d+)(?: \(line (?<line>\d+) column (?<column>\d+)\))?$/.exec(message);
|
|
183
|
+
if (!match) {
|
|
184
|
+
return void 0;
|
|
185
|
+
}
|
|
186
|
+
let { column, index, line } = match.groups;
|
|
187
|
+
if (line && column) {
|
|
188
|
+
return { column: Number(column), line: Number(line) };
|
|
189
|
+
}
|
|
190
|
+
index = Number(index);
|
|
191
|
+
if (index === source.length) {
|
|
192
|
+
index = source.length - 1;
|
|
193
|
+
}
|
|
194
|
+
return indexToLineColumn(source, index);
|
|
195
|
+
};
|
|
196
|
+
const addCodePointToUnexpectedToken = (message) => message.replace(
|
|
197
|
+
// TODO[engine:node@>=20]: The token always quoted after Node.js 20
|
|
198
|
+
// eslint-disable-next-line regexp/no-potentially-useless-backreference
|
|
199
|
+
/(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/,
|
|
200
|
+
(_, _quote, token) => `"${token}"(${getCodePoint(token)})`
|
|
201
|
+
);
|
|
202
|
+
function parseJson(string, reviver, fileName, options) {
|
|
203
|
+
if (typeof reviver === "string") {
|
|
204
|
+
if (typeof fileName === "object") {
|
|
205
|
+
options = fileName;
|
|
206
|
+
}
|
|
207
|
+
fileName = reviver;
|
|
208
|
+
reviver = void 0;
|
|
209
|
+
}
|
|
210
|
+
let message;
|
|
211
|
+
try {
|
|
212
|
+
return JSON.parse(string, reviver);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
message = error.message;
|
|
215
|
+
}
|
|
216
|
+
let location;
|
|
217
|
+
if (string) {
|
|
218
|
+
location = getErrorLocation(string, message);
|
|
219
|
+
message = addCodePointToUnexpectedToken(message);
|
|
220
|
+
} else {
|
|
221
|
+
message += " while parsing empty string";
|
|
222
|
+
}
|
|
223
|
+
const jsonError = new JSONError(message);
|
|
224
|
+
jsonError.fileName = fileName;
|
|
225
|
+
if (location) {
|
|
226
|
+
jsonError.codeFrame = generateCodeFrame(string, location, options);
|
|
227
|
+
}
|
|
228
|
+
throw jsonError;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export { parseJson as default };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
readFile: readFile$1
|
|
22
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
23
|
+
const {
|
|
24
|
+
unzip,
|
|
25
|
+
brotliDecompress
|
|
26
|
+
} = __cjs_getBuiltinModule("node:zlib");
|
|
27
|
+
import { toPath } from '@visulima/path/utils';
|
|
28
|
+
import { R_OK } from './F_OK-BalxCn9n.js';
|
|
29
|
+
import PermissionError from './PermissionError-1qs0skfo.js';
|
|
30
|
+
import isAccessible from './isAccessible-iOp0Bou6.js';
|
|
31
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
32
|
+
|
|
33
|
+
const decompressionMethods = {
|
|
34
|
+
brotli: brotliDecompress,
|
|
35
|
+
gzip: unzip,
|
|
36
|
+
none: (buffer, callback) => {
|
|
37
|
+
callback(null, buffer);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const readFile = async (path, options) => {
|
|
41
|
+
assertValidFileOrDirectoryPath(path);
|
|
42
|
+
path = toPath(path);
|
|
43
|
+
if (!await isAccessible(path)) {
|
|
44
|
+
throw new PermissionError(`unable to read the non-accessible file: ${path}`);
|
|
45
|
+
}
|
|
46
|
+
if (!await isAccessible(path, R_OK)) {
|
|
47
|
+
throw new Error(`Unable to read the non-readable file: ${path}`);
|
|
48
|
+
}
|
|
49
|
+
const { buffer, compression, encoding, flag } = options ?? {};
|
|
50
|
+
return await readFile$1(path, flag ? { encoding, flag } : { encoding }).then(
|
|
51
|
+
async (content) => await new Promise((resolve, reject) => {
|
|
52
|
+
decompressionMethods[compression ?? "none"](content, (error, result) => {
|
|
53
|
+
if (error) {
|
|
54
|
+
reject(error);
|
|
55
|
+
} else {
|
|
56
|
+
resolve(buffer ? result : result.toString());
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
})
|
|
60
|
+
).catch((error) => {
|
|
61
|
+
throw error;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { readFile as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
readFileSync: readFileSync$1
|
|
22
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
23
|
+
const {
|
|
24
|
+
unzipSync,
|
|
25
|
+
brotliDecompressSync
|
|
26
|
+
} = __cjs_getBuiltinModule("node:zlib");
|
|
27
|
+
import { toPath } from '@visulima/path/utils';
|
|
28
|
+
import { R_OK } from './F_OK-BalxCn9n.js';
|
|
29
|
+
import PermissionError from './PermissionError-1qs0skfo.js';
|
|
30
|
+
import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
|
|
31
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
32
|
+
|
|
33
|
+
const decompressionMethods = {
|
|
34
|
+
brotli: brotliDecompressSync,
|
|
35
|
+
gzip: unzipSync,
|
|
36
|
+
none: (buffer) => buffer
|
|
37
|
+
};
|
|
38
|
+
const readFileSync = (path, options) => {
|
|
39
|
+
assertValidFileOrDirectoryPath(path);
|
|
40
|
+
path = toPath(path);
|
|
41
|
+
if (!isAccessibleSync(path)) {
|
|
42
|
+
throw new PermissionError(`unable to read the non-accessible file: ${path}`);
|
|
43
|
+
}
|
|
44
|
+
if (!isAccessibleSync(path, R_OK)) {
|
|
45
|
+
throw new PermissionError(`invalid access to read file at: ${path}`);
|
|
46
|
+
}
|
|
47
|
+
const { buffer, compression, encoding, flag } = options ?? {};
|
|
48
|
+
const content = readFileSync$1(path, flag ? { encoding, flag } : { encoding });
|
|
49
|
+
const decompressed = decompressionMethods[compression ?? "none"](content);
|
|
50
|
+
return buffer ? decompressed : decompressed.toString();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { readFileSync as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toPath } from '@visulima/path/utils';
|
|
2
|
+
import parseJson from './parseJson-CqUuRguZ.js';
|
|
3
|
+
import readFile from './readFile-XVOjAw8r.js';
|
|
4
|
+
|
|
5
|
+
async function readJson(path, reviver, options) {
|
|
6
|
+
if (typeof reviver === "object") {
|
|
7
|
+
options = reviver;
|
|
8
|
+
reviver = void 0;
|
|
9
|
+
}
|
|
10
|
+
const content = await readFile(path, {
|
|
11
|
+
buffer: true,
|
|
12
|
+
encoding: void 0
|
|
13
|
+
});
|
|
14
|
+
let data = new TextDecoder().decode(content);
|
|
15
|
+
const { beforeParse, color } = options ?? {};
|
|
16
|
+
if (typeof beforeParse === "function") {
|
|
17
|
+
data = beforeParse(data);
|
|
18
|
+
}
|
|
19
|
+
return parseJson(data, reviver, toPath(path), { color });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { readJson as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toPath } from '@visulima/path/utils';
|
|
2
|
+
import parseJson from './parseJson-CqUuRguZ.js';
|
|
3
|
+
import readFileSync from './readFileSync-B9Zg5PSF.js';
|
|
4
|
+
|
|
5
|
+
function readJsonSync(path, reviver, options) {
|
|
6
|
+
if (typeof reviver === "object") {
|
|
7
|
+
options = reviver;
|
|
8
|
+
reviver = void 0;
|
|
9
|
+
}
|
|
10
|
+
const content = readFileSync(path, {
|
|
11
|
+
buffer: true,
|
|
12
|
+
encoding: void 0
|
|
13
|
+
});
|
|
14
|
+
let data = new TextDecoder().decode(content);
|
|
15
|
+
const { beforeParse, color } = options ?? {};
|
|
16
|
+
if (typeof beforeParse === "function") {
|
|
17
|
+
data = beforeParse(data);
|
|
18
|
+
}
|
|
19
|
+
return parseJson(data, reviver, toPath(path), { color });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { readJsonSync as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
import readFile from './readFile-XVOjAw8r.js';
|
|
3
|
+
|
|
4
|
+
async function readYaml(path, reviver, options) {
|
|
5
|
+
const { buffer, compression, encoding = "utf8", flag, ...parseOptions } = options ?? {};
|
|
6
|
+
const content = await readFile(path, { buffer, compression, encoding, flag });
|
|
7
|
+
return typeof reviver === "function" ? parse(content, reviver, parseOptions) : parse(content, parseOptions);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { readYaml as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
import readFileSync from './readFileSync-B9Zg5PSF.js';
|
|
3
|
+
|
|
4
|
+
function readYamlSync(path, reviver, options) {
|
|
5
|
+
const { buffer, compression, encoding = "utf8", flag, ...parseOptions } = options ?? {};
|
|
6
|
+
const content = readFileSync(path, { buffer, compression, encoding, flag });
|
|
7
|
+
return typeof reviver === "function" ? parse(content, reviver, parseOptions) : parse(content, parseOptions);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { readYamlSync as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
unlink,
|
|
22
|
+
rm
|
|
23
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
24
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
25
|
+
|
|
26
|
+
const remove = async (path, options = {}) => {
|
|
27
|
+
assertValidFileOrDirectoryPath(path);
|
|
28
|
+
try {
|
|
29
|
+
await unlink(path);
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await rm(path, { force: true, maxRetries: options?.maxRetries, recursive: true, retryDelay: options?.retryDelay });
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { remove as default };
|