@visulima/fs 4.0.3 → 4.0.4
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 +17 -0
- package/LICENSE.md +1 -1
- package/dist/eol.js +26 -3
- package/dist/error.js +7 -1
- package/dist/index.js +32 -1
- package/dist/packem_shared/AlreadyExistsError-D5BGeeNR.js +27 -0
- package/dist/packem_shared/DirectoryError-CaUV2Pbk.js +27 -0
- package/dist/packem_shared/F_OK-MldBaGxb.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-BSnyGqer.js +85 -0
- package/dist/packem_shared/findUpSync-jRHbSCMV.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-DuVrTNFV.js +38 -0
- package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +38 -0
- package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +62 -0
- package/dist/packem_shared/move-DbpW5_vA.js +134 -0
- package/dist/packem_shared/parseJson-CqUuRguZ.js +231 -0
- package/dist/packem_shared/readFile-iHOVXeH-.js +68 -0
- package/dist/packem_shared/readFileSync-BkEj9BQY.js +53 -0
- package/dist/packem_shared/readJson-pdfQBWDR.js +22 -0
- package/dist/packem_shared/readJsonSync-BZqGcA5d.js +22 -0
- package/dist/packem_shared/readYaml-BQXTlR2p.js +10 -0
- package/dist/packem_shared/readYamlSync-BBBQ5ujx.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-vo4k0mpF.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-DSHERs0Z.js +83 -0
- package/dist/packem_shared/writeFileSync-CJp1kXQR.js +83 -0
- package/dist/packem_shared/writeJson-C0OfLDbe.js +50 -0
- package/dist/packem_shared/writeJsonSync-Cs21FE7v.js +50 -0
- package/dist/packem_shared/writeYaml-n4xzYN9a.js +24 -0
- package/dist/packem_shared/writeYamlSync-DnOEnP10.js +24 -0
- package/dist/size.js +144 -1
- package/dist/utils.js +6 -1
- package/dist/yaml.js +4 -1
- package/package.json +2 -2
- 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/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/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,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
|
+
unlinkSync,
|
|
22
|
+
rmSync
|
|
23
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
24
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
25
|
+
|
|
26
|
+
const removeSync = (path, options = {}) => {
|
|
27
|
+
assertValidFileOrDirectoryPath(path);
|
|
28
|
+
try {
|
|
29
|
+
unlinkSync(path);
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
rmSync(path, { force: true, maxRetries: options?.maxRetries, recursive: true, retryDelay: options?.retryDelay });
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { removeSync as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { resolve, dirname } from '@visulima/path';
|
|
2
|
+
|
|
3
|
+
const resolveSymlinkTarget = (target, linkName) => {
|
|
4
|
+
if (typeof target !== "string") {
|
|
5
|
+
return target;
|
|
6
|
+
}
|
|
7
|
+
if (target.startsWith("./")) {
|
|
8
|
+
return resolve(target);
|
|
9
|
+
}
|
|
10
|
+
if (typeof linkName === "string") {
|
|
11
|
+
return resolve(dirname(linkName), target);
|
|
12
|
+
}
|
|
13
|
+
return new URL(target, linkName);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { resolveSymlinkTarget as r };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { INTERNAL_STRIP_JSON_REGEX } from './F_OK-MldBaGxb.js';
|
|
2
|
+
|
|
3
|
+
const stripJsonComments = (jsonString, { whitespace = true } = {}) => (
|
|
4
|
+
// This regular expression translates to:
|
|
5
|
+
//
|
|
6
|
+
// /quoted-string|line-comment|block-comment/g
|
|
7
|
+
//
|
|
8
|
+
// This means that comment characters inside of strings will match
|
|
9
|
+
// as strings, not comments, so we can just skip the whole string
|
|
10
|
+
// in the replacer function.
|
|
11
|
+
jsonString.replace(INTERNAL_STRIP_JSON_REGEX, (match) => {
|
|
12
|
+
if (match.startsWith('"') || match[1] === "*" && !match.endsWith("*/")) {
|
|
13
|
+
return match;
|
|
14
|
+
}
|
|
15
|
+
return whitespace ? match.replaceAll(/\S/g, " ") : "";
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export { stripJsonComments as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const encoder = new TextEncoder();
|
|
2
|
+
const toUint8Array = (contents) => {
|
|
3
|
+
if (contents instanceof Uint8Array) {
|
|
4
|
+
return contents;
|
|
5
|
+
}
|
|
6
|
+
if (typeof contents === "string") {
|
|
7
|
+
return encoder.encode(contents);
|
|
8
|
+
}
|
|
9
|
+
if (contents instanceof ArrayBuffer) {
|
|
10
|
+
return new Uint8Array(contents);
|
|
11
|
+
}
|
|
12
|
+
if (ArrayBuffer.isView(contents)) {
|
|
13
|
+
const bytes = contents.buffer.slice(contents.byteOffset, contents.byteOffset + contents.byteLength);
|
|
14
|
+
return new Uint8Array(bytes);
|
|
15
|
+
}
|
|
16
|
+
throw new TypeError("Invalid contents type. Expected string or ArrayBuffer.");
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { toUint8Array as t };
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
readdir,
|
|
22
|
+
realpath,
|
|
23
|
+
stat
|
|
24
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
25
|
+
import { resolve, join, normalize, basename } from '@visulima/path';
|
|
26
|
+
import { toPath } from '@visulima/path/utils';
|
|
27
|
+
import WalkError from './WalkError-DUdQd6FT.js';
|
|
28
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
29
|
+
import { g as globToRegExp, w as walkInclude } from './walk-include-CZco7BvN.js';
|
|
30
|
+
|
|
31
|
+
const _createWalkEntry = async (path) => {
|
|
32
|
+
const normalizePath = normalize(path);
|
|
33
|
+
const name = basename(normalizePath);
|
|
34
|
+
const info = await stat(normalizePath);
|
|
35
|
+
return {
|
|
36
|
+
isDirectory: () => info.isDirectory(),
|
|
37
|
+
isFile: () => info.isFile(),
|
|
38
|
+
isSymbolicLink: () => info.isSymbolicLink(),
|
|
39
|
+
name,
|
|
40
|
+
path: normalizePath
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
async function* walk(directory, {
|
|
44
|
+
extensions,
|
|
45
|
+
followSymlinks = false,
|
|
46
|
+
includeDirs: includeDirectories = true,
|
|
47
|
+
includeFiles = true,
|
|
48
|
+
includeSymlinks = true,
|
|
49
|
+
match,
|
|
50
|
+
maxDepth = Number.POSITIVE_INFINITY,
|
|
51
|
+
skip
|
|
52
|
+
} = {}) {
|
|
53
|
+
assertValidFileOrDirectoryPath(directory);
|
|
54
|
+
if (maxDepth < 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
58
|
+
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
59
|
+
directory = resolve(toPath(directory));
|
|
60
|
+
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
61
|
+
yield await _createWalkEntry(directory);
|
|
62
|
+
}
|
|
63
|
+
if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
for await (const entry of await readdir(directory, {
|
|
68
|
+
withFileTypes: true
|
|
69
|
+
})) {
|
|
70
|
+
let path = join(directory, entry.name);
|
|
71
|
+
if (entry.isSymbolicLink()) {
|
|
72
|
+
if (followSymlinks) {
|
|
73
|
+
path = await realpath(path);
|
|
74
|
+
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
75
|
+
yield {
|
|
76
|
+
isDirectory: entry.isDirectory,
|
|
77
|
+
isFile: entry.isFile,
|
|
78
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
79
|
+
name: entry.name,
|
|
80
|
+
path
|
|
81
|
+
};
|
|
82
|
+
} else {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
87
|
+
yield* walk(path, {
|
|
88
|
+
extensions,
|
|
89
|
+
followSymlinks,
|
|
90
|
+
includeDirs: includeDirectories,
|
|
91
|
+
includeFiles,
|
|
92
|
+
includeSymlinks,
|
|
93
|
+
match: mappedMatch,
|
|
94
|
+
maxDepth: maxDepth - 1,
|
|
95
|
+
skip: mappedSkip
|
|
96
|
+
});
|
|
97
|
+
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
98
|
+
yield {
|
|
99
|
+
isDirectory: () => entry.isDirectory(),
|
|
100
|
+
isFile: () => entry.isFile(),
|
|
101
|
+
isSymbolicLink: () => entry.isSymbolicLink(),
|
|
102
|
+
name: entry.name,
|
|
103
|
+
path
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (error instanceof WalkError) {
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
throw new WalkError(error, directory);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { walk as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const globToRegExp = (glob) => {
|
|
2
|
+
const reString = glob.replace(/\.\*/g, ".([^/]*)").replace(/\*\*/g, "(.*)").replace(/(?<!\.)\*(?!\*)/g, "([^/]*)").replace(/\?/g, "[^/]").replace(/\.(?!\*)/g, String.raw`\.`).replace(/\{/g, "(").replace(/\}/g, ")").replace(/,/g, "|").replace(/\[!(.*?)\]/g, "[^$1]");
|
|
3
|
+
return new RegExp(`^${reString}$`);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const walkInclude = (path, extensions, match, skip) => {
|
|
7
|
+
if (Array.isArray(extensions) && extensions.length > 0 && !extensions.some((extension) => path.endsWith(extension))) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (match && !match.some((pattern) => pattern.test(path))) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return !skip?.some((pattern) => pattern.test(path));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { globToRegExp as g, walkInclude as w };
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
readdirSync,
|
|
22
|
+
realpathSync,
|
|
23
|
+
statSync
|
|
24
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
25
|
+
import { resolve, join, normalize, basename } from '@visulima/path';
|
|
26
|
+
import { toPath } from '@visulima/path/utils';
|
|
27
|
+
import WalkError from './WalkError-DUdQd6FT.js';
|
|
28
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
29
|
+
import { g as globToRegExp, w as walkInclude } from './walk-include-CZco7BvN.js';
|
|
30
|
+
|
|
31
|
+
const _createWalkEntry = (path) => {
|
|
32
|
+
const normalizePath = normalize(path);
|
|
33
|
+
const info = statSync(normalizePath);
|
|
34
|
+
return {
|
|
35
|
+
isDirectory: info.isDirectory,
|
|
36
|
+
isFile: info.isFile,
|
|
37
|
+
isSymbolicLink: info.isSymbolicLink,
|
|
38
|
+
name: basename(normalizePath),
|
|
39
|
+
path: normalizePath
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
function* walkSync(directory, {
|
|
43
|
+
extensions,
|
|
44
|
+
followSymlinks = false,
|
|
45
|
+
includeDirs: includeDirectories = true,
|
|
46
|
+
includeFiles = true,
|
|
47
|
+
includeSymlinks = true,
|
|
48
|
+
match,
|
|
49
|
+
maxDepth = Number.POSITIVE_INFINITY,
|
|
50
|
+
skip
|
|
51
|
+
} = {}) {
|
|
52
|
+
assertValidFileOrDirectoryPath(directory);
|
|
53
|
+
if (maxDepth < 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
57
|
+
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
58
|
+
directory = resolve(toPath(directory));
|
|
59
|
+
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
60
|
+
yield _createWalkEntry(directory);
|
|
61
|
+
}
|
|
62
|
+
if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
for (const entry of readdirSync(directory, {
|
|
67
|
+
withFileTypes: true
|
|
68
|
+
})) {
|
|
69
|
+
let path = join(directory, entry.name);
|
|
70
|
+
if (entry.isSymbolicLink()) {
|
|
71
|
+
if (followSymlinks) {
|
|
72
|
+
path = realpathSync(path);
|
|
73
|
+
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
74
|
+
yield {
|
|
75
|
+
isDirectory: entry.isDirectory,
|
|
76
|
+
isFile: entry.isFile,
|
|
77
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
78
|
+
name: entry.name,
|
|
79
|
+
path: normalize(path)
|
|
80
|
+
};
|
|
81
|
+
} else {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
86
|
+
yield* walkSync(path, {
|
|
87
|
+
extensions,
|
|
88
|
+
followSymlinks,
|
|
89
|
+
includeDirs: includeDirectories,
|
|
90
|
+
includeFiles,
|
|
91
|
+
includeSymlinks,
|
|
92
|
+
match: mappedMatch,
|
|
93
|
+
maxDepth: maxDepth - 1,
|
|
94
|
+
skip: mappedSkip
|
|
95
|
+
});
|
|
96
|
+
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
97
|
+
yield {
|
|
98
|
+
isDirectory: entry.isDirectory,
|
|
99
|
+
isFile: entry.isFile,
|
|
100
|
+
isSymbolicLink: entry.isSymbolicLink,
|
|
101
|
+
name: entry.name,
|
|
102
|
+
path: normalize(path)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (error instanceof WalkError) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
throw new WalkError(error, directory);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { walkSync as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
mkdir,
|
|
22
|
+
writeFile: writeFile$1,
|
|
23
|
+
stat,
|
|
24
|
+
rename,
|
|
25
|
+
chown,
|
|
26
|
+
chmod,
|
|
27
|
+
unlink
|
|
28
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
29
|
+
import { dirname } from '@visulima/path';
|
|
30
|
+
import { toPath } from '@visulima/path/utils';
|
|
31
|
+
import { F_OK } from './F_OK-MldBaGxb.js';
|
|
32
|
+
import isAccessible from './isAccessible-DuVrTNFV.js';
|
|
33
|
+
import assertValidFileContents from './assertValidFileContents-BmcLtsGd.js';
|
|
34
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
35
|
+
import { t as toUint8Array } from './to-uint-8-array-Dz2nF1y1.js';
|
|
36
|
+
|
|
37
|
+
const writeFile = async (path, content, options) => {
|
|
38
|
+
options = {
|
|
39
|
+
encoding: "utf8",
|
|
40
|
+
flag: "w",
|
|
41
|
+
overwrite: true,
|
|
42
|
+
recursive: true,
|
|
43
|
+
...options
|
|
44
|
+
};
|
|
45
|
+
assertValidFileOrDirectoryPath(path);
|
|
46
|
+
assertValidFileContents(content);
|
|
47
|
+
path = toPath(path);
|
|
48
|
+
const temporaryPath = `${path}.tmp`;
|
|
49
|
+
try {
|
|
50
|
+
const pathExists = await isAccessible(path, F_OK);
|
|
51
|
+
if (!pathExists && options.recursive) {
|
|
52
|
+
const directory = dirname(path);
|
|
53
|
+
if (!await isAccessible(directory, F_OK)) {
|
|
54
|
+
await mkdir(directory, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let stat$1;
|
|
58
|
+
await writeFile$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
59
|
+
if (pathExists && !options.overwrite) {
|
|
60
|
+
stat$1 = await stat(path);
|
|
61
|
+
if (options.chown === void 0) {
|
|
62
|
+
options.chown = { gid: stat$1.gid, uid: stat$1.uid };
|
|
63
|
+
}
|
|
64
|
+
await rename(path, `${path}.bak`);
|
|
65
|
+
}
|
|
66
|
+
if (options.chown) {
|
|
67
|
+
try {
|
|
68
|
+
await chown(temporaryPath, options.chown.uid, options.chown.gid);
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
await chmod(temporaryPath, stat$1 && !options.mode ? stat$1.mode : options.mode ?? 438);
|
|
73
|
+
await rename(temporaryPath, path);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
|
|
76
|
+
} finally {
|
|
77
|
+
if (await isAccessible(temporaryPath)) {
|
|
78
|
+
await unlink(`${path}.tmp`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { writeFile as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
mkdirSync,
|
|
22
|
+
writeFileSync: writeFileSync$1,
|
|
23
|
+
statSync,
|
|
24
|
+
renameSync,
|
|
25
|
+
chownSync,
|
|
26
|
+
chmodSync,
|
|
27
|
+
unlinkSync
|
|
28
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
29
|
+
import { dirname } from '@visulima/path';
|
|
30
|
+
import { toPath } from '@visulima/path/utils';
|
|
31
|
+
import { F_OK } from './F_OK-MldBaGxb.js';
|
|
32
|
+
import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
|
|
33
|
+
import assertValidFileContents from './assertValidFileContents-BmcLtsGd.js';
|
|
34
|
+
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
35
|
+
import { t as toUint8Array } from './to-uint-8-array-Dz2nF1y1.js';
|
|
36
|
+
|
|
37
|
+
const writeFileSync = (path, content, options) => {
|
|
38
|
+
options = {
|
|
39
|
+
encoding: "utf8",
|
|
40
|
+
flag: "w",
|
|
41
|
+
overwrite: true,
|
|
42
|
+
recursive: true,
|
|
43
|
+
...options
|
|
44
|
+
};
|
|
45
|
+
assertValidFileOrDirectoryPath(path);
|
|
46
|
+
assertValidFileContents(content);
|
|
47
|
+
path = toPath(path);
|
|
48
|
+
const temporaryPath = `${path}.tmp`;
|
|
49
|
+
try {
|
|
50
|
+
const pathExists = isAccessibleSync(path, F_OK);
|
|
51
|
+
if (!pathExists && options.recursive) {
|
|
52
|
+
const directory = dirname(path);
|
|
53
|
+
if (!isAccessibleSync(directory, F_OK)) {
|
|
54
|
+
mkdirSync(directory, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let stat;
|
|
58
|
+
writeFileSync$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
59
|
+
if (pathExists && !options.overwrite) {
|
|
60
|
+
stat = statSync(path);
|
|
61
|
+
if (options.chown === void 0) {
|
|
62
|
+
options.chown = { gid: stat.gid, uid: stat.uid };
|
|
63
|
+
}
|
|
64
|
+
renameSync(path, `${path}.bak`);
|
|
65
|
+
}
|
|
66
|
+
if (options.chown) {
|
|
67
|
+
try {
|
|
68
|
+
chownSync(temporaryPath, options.chown.uid, options.chown.gid);
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
chmodSync(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
|
|
73
|
+
renameSync(temporaryPath, path);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
|
|
76
|
+
} finally {
|
|
77
|
+
if (isAccessibleSync(temporaryPath)) {
|
|
78
|
+
unlinkSync(`${path}.tmp`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { writeFileSync as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
|
22
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
23
|
+
import { d as detectIndent } from './index-CHM-in-V.js';
|
|
24
|
+
import { R_OK } from './F_OK-MldBaGxb.js';
|
|
25
|
+
import isAccessible from './isAccessible-DuVrTNFV.js';
|
|
26
|
+
import writeFile from './writeFile-DSHERs0Z.js';
|
|
27
|
+
|
|
28
|
+
const writeJson = async (path, data, options = {}) => {
|
|
29
|
+
const { detectIndent: detectIndent$1, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
|
|
30
|
+
let indent = indentOption;
|
|
31
|
+
let trailingNewline = "\n";
|
|
32
|
+
if (await isAccessible(path, R_OK)) {
|
|
33
|
+
try {
|
|
34
|
+
const file = await readFile(path, "utf8");
|
|
35
|
+
if (detectIndent$1) {
|
|
36
|
+
const { indent: dIndent } = detectIndent(file);
|
|
37
|
+
indent = dIndent;
|
|
38
|
+
}
|
|
39
|
+
trailingNewline = file.endsWith("\n") ? "\n" : "";
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error.code !== "ENOENT") {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const json = stringify(data, replacer, indent);
|
|
47
|
+
await writeFile(path, `${json}${trailingNewline}`, writeOptions);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { writeJson as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
|
22
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
23
|
+
import { d as detectIndent } from './index-CHM-in-V.js';
|
|
24
|
+
import { R_OK } from './F_OK-MldBaGxb.js';
|
|
25
|
+
import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
|
|
26
|
+
import writeFileSync from './writeFileSync-CJp1kXQR.js';
|
|
27
|
+
|
|
28
|
+
const writeJsonSync = (path, data, options = {}) => {
|
|
29
|
+
const { detectIndent: detectIndent$1, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
|
|
30
|
+
let indent = indentOption;
|
|
31
|
+
let trailingNewline = "\n";
|
|
32
|
+
if (isAccessibleSync(path, R_OK)) {
|
|
33
|
+
try {
|
|
34
|
+
const file = readFileSync(path, "utf8");
|
|
35
|
+
if (detectIndent$1) {
|
|
36
|
+
const { indent: dIndent } = detectIndent(file);
|
|
37
|
+
indent = dIndent;
|
|
38
|
+
}
|
|
39
|
+
trailingNewline = file.endsWith("\n") ? "\n" : "";
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error.code !== "ENOENT") {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const json = stringify(data, replacer, indent);
|
|
47
|
+
writeFileSync(path, `${json}${trailingNewline}`, writeOptions);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { writeJsonSync as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { stringify } from 'yaml';
|
|
2
|
+
import writeFile from './writeFile-DSHERs0Z.js';
|
|
3
|
+
|
|
4
|
+
async function writeYaml(path, data, replacer, options) {
|
|
5
|
+
let stringifyOptions;
|
|
6
|
+
let effectiveReplacer;
|
|
7
|
+
let space;
|
|
8
|
+
if (typeof replacer === "object" && replacer !== null && !Array.isArray(replacer) && typeof replacer !== "function") {
|
|
9
|
+
stringifyOptions = replacer;
|
|
10
|
+
effectiveReplacer = stringifyOptions.replacer;
|
|
11
|
+
space = stringifyOptions.space;
|
|
12
|
+
} else if (typeof options === "object" && options !== null) {
|
|
13
|
+
stringifyOptions = options;
|
|
14
|
+
effectiveReplacer = replacer;
|
|
15
|
+
space = stringifyOptions.space ?? (typeof options === "number" || typeof options === "string" ? options : void 0);
|
|
16
|
+
} else {
|
|
17
|
+
effectiveReplacer = replacer;
|
|
18
|
+
space = options;
|
|
19
|
+
}
|
|
20
|
+
const content = stringify(data, effectiveReplacer, space ?? stringifyOptions);
|
|
21
|
+
await writeFile(path, content, stringifyOptions);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { writeYaml as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { stringify } from 'yaml';
|
|
2
|
+
import writeFileSync from './writeFileSync-CJp1kXQR.js';
|
|
3
|
+
|
|
4
|
+
function writeYamlSync(path, data, replacer, options) {
|
|
5
|
+
let stringifyOptions;
|
|
6
|
+
let effectiveReplacer;
|
|
7
|
+
let space;
|
|
8
|
+
if (typeof replacer === "object" && replacer !== null && !Array.isArray(replacer) && typeof replacer !== "function") {
|
|
9
|
+
stringifyOptions = replacer;
|
|
10
|
+
effectiveReplacer = stringifyOptions.replacer;
|
|
11
|
+
space = stringifyOptions.space;
|
|
12
|
+
} else if (typeof options === "object" && options !== null) {
|
|
13
|
+
stringifyOptions = options;
|
|
14
|
+
effectiveReplacer = replacer;
|
|
15
|
+
space = stringifyOptions.space ?? (typeof options === "number" || typeof options === "string" ? options : void 0);
|
|
16
|
+
} else {
|
|
17
|
+
effectiveReplacer = replacer;
|
|
18
|
+
space = options;
|
|
19
|
+
}
|
|
20
|
+
const content = stringify(data, effectiveReplacer, space ?? stringifyOptions);
|
|
21
|
+
writeFileSync(path, content, stringifyOptions);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { writeYamlSync as default };
|