@visulima/fs 5.0.0-alpha.13 → 5.0.0-alpha.14
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 +16 -0
- package/LICENSE.md +30 -0
- package/dist/eol.js +3 -26
- package/dist/error.js +1 -7
- package/dist/glob-parent.js +1 -90
- package/dist/glob.d.ts +2 -2
- package/dist/glob.js +1 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -38
- package/dist/ini.d.ts +2 -2
- package/dist/ini.js +1 -4
- package/dist/is-glob.js +1 -9
- package/dist/json5.d.ts +2 -2
- package/dist/json5.js +1 -4
- package/dist/jsonc.d.ts +2 -2
- package/dist/jsonc.js +1 -4
- package/dist/match.d.ts +1 -1
- package/dist/match.js +1 -15
- 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-Dsxhj3BW.d.ts → glob-sync.d-p6lOZXnE.d.ts} +1 -1
- 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/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-CixEXeyM.d.ts → types.d-BsmmADqx.d.ts} +26 -26
- 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.js +1 -146
- package/dist/toml.d.ts +1 -1
- package/dist/toml.js +1 -4
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -6
- package/dist/yaml.d.ts +2 -2
- package/dist/yaml.js +1 -4
- package/package.json +22 -22
- 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-DER5A43G.js +0 -24
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
- package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +0 -12
- package/dist/packem_shared/collect-CqQ3eVab.js +0 -14
- package/dist/packem_shared/collectSync-noE08NNv.js +0 -14
- package/dist/packem_shared/emptyDir-DnwENOaV.js +0 -46
- package/dist/packem_shared/emptyDirSync-6WiHBo8a.js +0 -43
- package/dist/packem_shared/ensureDir-DNlPftys.js +0 -53
- package/dist/packem_shared/ensureDirSync-DcPZFMy5.js +0 -53
- package/dist/packem_shared/ensureFile-BRQpUOUM.js +0 -47
- package/dist/packem_shared/ensureFileSync-SBY7A9-C.js +0 -47
- package/dist/packem_shared/ensureLink-DJQeauEn.js +0 -55
- package/dist/packem_shared/ensureLinkSync-D9RVAglV.js +0 -55
- package/dist/packem_shared/ensureSymlink-CoRYDRwr.js +0 -80
- package/dist/packem_shared/ensureSymlinkSync-CFimFlgh.js +0 -81
- package/dist/packem_shared/findUp-YcNLKdfV.js +0 -84
- package/dist/packem_shared/findUpSync-BfA5fheN.js +0 -83
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
- package/dist/packem_shared/glob-DY8l7izD.js +0 -5
- package/dist/packem_shared/globSync-5P2KJf_g.js +0 -5
- package/dist/packem_shared/index-C8W8sfzP.js +0 -830
- package/dist/packem_shared/index-CHM-in-V.js +0 -100
- package/dist/packem_shared/index-bhgnhm4u.js +0 -167
- package/dist/packem_shared/index-xe4o3cYi.js +0 -1784
- package/dist/packem_shared/indexToLineColumn-BUb0GPKl-BF770uX7.js +0 -171
- package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +0 -251
- 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-DunL7Iry.js +0 -62
- package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +0 -72
- package/dist/packem_shared/move-DbpW5_vA.js +0 -134
- package/dist/packem_shared/parseJson-BIp89Xjo.js +0 -63
- package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
- package/dist/packem_shared/readFileSync-gm9yfIhh.js +0 -54
- package/dist/packem_shared/readIni-CJ2xfpjB.js +0 -10
- package/dist/packem_shared/readIniSync-9LUjaSSp.js +0 -10
- package/dist/packem_shared/readJson-C_rwm-wq.js +0 -22
- package/dist/packem_shared/readJson5-mBoTZppy.js +0 -15
- package/dist/packem_shared/readJson5Sync-8WS2yUok.js +0 -15
- package/dist/packem_shared/readJsonSync-BMEmCcJ6.js +0 -22
- package/dist/packem_shared/readJsonc-j-OS-APg.js +0 -28
- package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +0 -16
- package/dist/packem_shared/readToml-B2MHaSes.js +0 -9
- package/dist/packem_shared/readTomlSync-DNbK8NEb.js +0 -9
- package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
- package/dist/packem_shared/readYamlSync-BKX-PAfq.js +0 -10
- package/dist/packem_shared/remove-C8_gl3jF.js +0 -39
- package/dist/packem_shared/removeSync-BJR_wTwN.js +0 -39
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
- package/dist/packem_shared/sanitize-BZoLN9Fg.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-CSZgCuDx.js +0 -124
- package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
- package/dist/packem_shared/walkSync-C4Cy28xb.js +0 -123
- package/dist/packem_shared/writeFile-B8HX0JIQ.js +0 -81
- package/dist/packem_shared/writeFileSync-DB8vv8xR.js +0 -81
- package/dist/packem_shared/writeIni-i55QrL8y.js +0 -65
- package/dist/packem_shared/writeIniSync-CLqJE5t3.js +0 -64
- package/dist/packem_shared/writeJson-Bo7C2UHw.js +0 -50
- package/dist/packem_shared/writeJson5-vVmHUQOd.js +0 -53
- package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +0 -53
- package/dist/packem_shared/writeJsonSync-BKZ_9Acr.js +0 -50
- package/dist/packem_shared/writeJsonc-BufH_oC5.js +0 -60
- package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +0 -59
- package/dist/packem_shared/writeToml-DgTW_-7F.js +0 -8
- package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +0 -8
- package/dist/packem_shared/writeYaml-BWCOome-.js +0 -24
- package/dist/packem_shared/writeYamlSync-DBVnXmuY.js +0 -24
|
@@ -1,205 +0,0 @@
|
|
|
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 {
|
|
8
|
-
platform
|
|
9
|
-
} = __cjs_getProcess;
|
|
10
|
-
|
|
11
|
-
const FALLBACK_NAME = "unnamed";
|
|
12
|
-
const MAX_LENGTH = 128;
|
|
13
|
-
const REPLACEMENT_CHARACTERS = {
|
|
14
|
-
'"': "ˮ",
|
|
15
|
-
// 0x02EE - MODIFIER LETTER DOUBLE APOSTROPHE
|
|
16
|
-
"*": "⁎",
|
|
17
|
-
// 0x204E - LOW ASTERISK
|
|
18
|
-
"/": "⁄",
|
|
19
|
-
// 0x2044 - FRACTION SLASH
|
|
20
|
-
":": "꞉",
|
|
21
|
-
// 0xA789 - MODIFIER LETTER COLON
|
|
22
|
-
"<": "‹",
|
|
23
|
-
// 0x2039 - SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
|
24
|
-
">": "›",
|
|
25
|
-
// 0x203A - SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
|
26
|
-
"?": "ʔ",
|
|
27
|
-
// 0x0294 - LATIN LETTER GLOTTAL STOP
|
|
28
|
-
"\\": "∖",
|
|
29
|
-
// 0x2216 - SET MINUS
|
|
30
|
-
"|": "ǀ"
|
|
31
|
-
// 0x01C0 - LATIN LETTER DENTAL CLICK
|
|
32
|
-
};
|
|
33
|
-
const CONTROL_CHARS_REGEX = /[\u0000-\u001F\u0080-\u009F]/g;
|
|
34
|
-
const RELATIVE_PATHS_REGEX = /^(?:\.+[/\\]+)+|^\.+$/g;
|
|
35
|
-
const WINDOWS_SPECIAL_NAMES_REGEX = /^(?:con|prn|aux|nul|com\d|lpt\d)$/i;
|
|
36
|
-
const WINDOWS_FORBIDDEN_CHARS_REGEX = /[<>:"/\\|?*]/g;
|
|
37
|
-
const UNIX_FORBIDDEN_CHARS_REGEX = /\//g;
|
|
38
|
-
const TRIM_CHARS = /* @__PURE__ */ new Set([" ", " ", "."]);
|
|
39
|
-
const hasExtension = (name, lastDotIndex) => lastDotIndex > 0 && lastDotIndex < name.length - 1;
|
|
40
|
-
const truncateWithExtension = (name, maxLength) => {
|
|
41
|
-
const lastDotIndex = name.lastIndexOf(".");
|
|
42
|
-
if (!hasExtension(name, lastDotIndex)) {
|
|
43
|
-
return name.slice(0, maxLength);
|
|
44
|
-
}
|
|
45
|
-
const baseName = name.slice(0, lastDotIndex);
|
|
46
|
-
const extension = name.slice(lastDotIndex);
|
|
47
|
-
const maxBaseLength = maxLength - extension.length;
|
|
48
|
-
return maxBaseLength > 0 ? `${baseName.slice(0, maxBaseLength)}${extension}` : name.slice(0, maxLength);
|
|
49
|
-
};
|
|
50
|
-
const trimSpacesAndPeriods = (input) => {
|
|
51
|
-
let start = 0;
|
|
52
|
-
let end = input.length;
|
|
53
|
-
while (start < end) {
|
|
54
|
-
const char = input[start];
|
|
55
|
-
if (char === void 0 || !TRIM_CHARS.has(char)) {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
start += 1;
|
|
59
|
-
}
|
|
60
|
-
while (end > start) {
|
|
61
|
-
const char = input[end - 1];
|
|
62
|
-
if (char === void 0 || !TRIM_CHARS.has(char)) {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
end -= 1;
|
|
66
|
-
}
|
|
67
|
-
return input.slice(start, end);
|
|
68
|
-
};
|
|
69
|
-
const cleanWindowsName = (name) => {
|
|
70
|
-
const lastDotIndex = name.lastIndexOf(".");
|
|
71
|
-
if (hasExtension(name, lastDotIndex)) {
|
|
72
|
-
const baseName = name.slice(0, lastDotIndex);
|
|
73
|
-
const extension = name.slice(lastDotIndex);
|
|
74
|
-
let cleanedBaseName = baseName;
|
|
75
|
-
while (cleanedBaseName.length > 0) {
|
|
76
|
-
const char = cleanedBaseName.at(-1);
|
|
77
|
-
if (char === void 0 || !TRIM_CHARS.has(char)) {
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
cleanedBaseName = cleanedBaseName.slice(0, -1);
|
|
81
|
-
}
|
|
82
|
-
if (cleanedBaseName.length === 0) {
|
|
83
|
-
return extension.slice(1);
|
|
84
|
-
}
|
|
85
|
-
return `${cleanedBaseName}${extension}`;
|
|
86
|
-
}
|
|
87
|
-
let cleaned = name;
|
|
88
|
-
while (cleaned.length > 0) {
|
|
89
|
-
const char = cleaned.at(-1);
|
|
90
|
-
if (char === void 0 || !TRIM_CHARS.has(char)) {
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
cleaned = cleaned.slice(0, -1);
|
|
94
|
-
}
|
|
95
|
-
return cleaned;
|
|
96
|
-
};
|
|
97
|
-
const isWindowsReservedName = (name) => {
|
|
98
|
-
const lastDotIndex = name.lastIndexOf(".");
|
|
99
|
-
if (hasExtension(name, lastDotIndex)) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
if (WINDOWS_SPECIAL_NAMES_REGEX.test(name)) {
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
let trimmed = name;
|
|
106
|
-
while (trimmed.length > 0) {
|
|
107
|
-
const char = trimmed.at(-1);
|
|
108
|
-
if (char === void 0 || !TRIM_CHARS.has(char)) {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
trimmed = trimmed.slice(0, -1);
|
|
112
|
-
}
|
|
113
|
-
if (trimmed.length > 0 && WINDOWS_SPECIAL_NAMES_REGEX.test(trimmed)) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
};
|
|
118
|
-
const cleanFat32Name = (name) => {
|
|
119
|
-
const lastDotIndex = name.lastIndexOf(".");
|
|
120
|
-
if (hasExtension(name, lastDotIndex)) {
|
|
121
|
-
const baseName = name.slice(0, lastDotIndex);
|
|
122
|
-
const extension = name.slice(lastDotIndex);
|
|
123
|
-
const cleanedBaseName = trimSpacesAndPeriods(baseName);
|
|
124
|
-
if (cleanedBaseName.length === 0) {
|
|
125
|
-
return void 0;
|
|
126
|
-
}
|
|
127
|
-
return `${cleanedBaseName}${extension}`;
|
|
128
|
-
}
|
|
129
|
-
const trimmed = name.trim();
|
|
130
|
-
if (trimmed.length > 0 && trimmed[0] === "." && trimmed.length <= 5) {
|
|
131
|
-
const secondDotIndex = trimmed.indexOf(".", 1);
|
|
132
|
-
if (secondDotIndex === -1) {
|
|
133
|
-
return void 0;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const cleaned = trimSpacesAndPeriods(name);
|
|
137
|
-
if (cleaned.length === 0) {
|
|
138
|
-
return void 0;
|
|
139
|
-
}
|
|
140
|
-
return cleaned;
|
|
141
|
-
};
|
|
142
|
-
const getFileSystemType = (options) => {
|
|
143
|
-
const filesystem = options?.filesystem ?? "auto";
|
|
144
|
-
if (filesystem === "auto") {
|
|
145
|
-
return platform === "win32" ? "win32" : "unix";
|
|
146
|
-
}
|
|
147
|
-
if (filesystem === "darwin") {
|
|
148
|
-
return "unix";
|
|
149
|
-
}
|
|
150
|
-
return filesystem;
|
|
151
|
-
};
|
|
152
|
-
const sanitize = (name, options) => {
|
|
153
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
154
|
-
return FALLBACK_NAME;
|
|
155
|
-
}
|
|
156
|
-
const fileSystemType = getFileSystemType(options);
|
|
157
|
-
let sanitized = name;
|
|
158
|
-
sanitized = sanitized.replace(CONTROL_CHARS_REGEX, "");
|
|
159
|
-
if (sanitized.length === 0) {
|
|
160
|
-
return FALLBACK_NAME;
|
|
161
|
-
}
|
|
162
|
-
sanitized = sanitized.replace(RELATIVE_PATHS_REGEX, "");
|
|
163
|
-
if (sanitized.length === 0) {
|
|
164
|
-
return FALLBACK_NAME;
|
|
165
|
-
}
|
|
166
|
-
if (fileSystemType === "win32" || fileSystemType === "fat32") {
|
|
167
|
-
const lastDotIndex = sanitized.lastIndexOf(".");
|
|
168
|
-
if (!hasExtension(sanitized, lastDotIndex) && WINDOWS_SPECIAL_NAMES_REGEX.test(sanitized)) {
|
|
169
|
-
return FALLBACK_NAME;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
sanitized = fileSystemType === "win32" || fileSystemType === "fat32" ? sanitized.replaceAll(WINDOWS_FORBIDDEN_CHARS_REGEX, (char) => REPLACEMENT_CHARACTERS[char] ?? "") : sanitized.replaceAll(UNIX_FORBIDDEN_CHARS_REGEX, REPLACEMENT_CHARACTERS["/"]);
|
|
173
|
-
sanitized = sanitized.trim();
|
|
174
|
-
if (fileSystemType === "win32" || fileSystemType === "fat32") {
|
|
175
|
-
if (isWindowsReservedName(sanitized)) {
|
|
176
|
-
return FALLBACK_NAME;
|
|
177
|
-
}
|
|
178
|
-
if (fileSystemType === "win32") {
|
|
179
|
-
sanitized = cleanWindowsName(sanitized);
|
|
180
|
-
if (sanitized.length === 0) {
|
|
181
|
-
return FALLBACK_NAME;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (fileSystemType === "fat32") {
|
|
186
|
-
const cleaned = cleanFat32Name(sanitized);
|
|
187
|
-
if (cleaned === void 0) {
|
|
188
|
-
return FALLBACK_NAME;
|
|
189
|
-
}
|
|
190
|
-
sanitized = cleaned;
|
|
191
|
-
}
|
|
192
|
-
if (sanitized.length === 0) {
|
|
193
|
-
return FALLBACK_NAME;
|
|
194
|
-
}
|
|
195
|
-
const maxLength = options?.maxLength ?? MAX_LENGTH;
|
|
196
|
-
if (sanitized.length > maxLength) {
|
|
197
|
-
sanitized = truncateWithExtension(sanitized, maxLength);
|
|
198
|
-
if (sanitized.length === 0) {
|
|
199
|
-
return FALLBACK_NAME;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return sanitized;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export { sanitize };
|
|
@@ -1,19 +0,0 @@
|
|
|
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 };
|
|
@@ -1,19 +0,0 @@
|
|
|
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 };
|
|
@@ -1,124 +0,0 @@
|
|
|
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-DER5A43G.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(
|
|
58
|
-
// eslint-disable-next-line no-confusing-arrow
|
|
59
|
-
(pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
|
|
60
|
-
) : void 0;
|
|
61
|
-
const mappedSkip = skip ? skip.map(
|
|
62
|
-
// eslint-disable-next-line no-confusing-arrow
|
|
63
|
-
(pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
|
|
64
|
-
) : void 0;
|
|
65
|
-
const resolvedDirectory = resolve(toPath(directory));
|
|
66
|
-
directory = resolvedDirectory;
|
|
67
|
-
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
68
|
-
yield await _createWalkEntry(directory);
|
|
69
|
-
}
|
|
70
|
-
if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
const entries = await readdir(directory, {
|
|
75
|
-
withFileTypes: true
|
|
76
|
-
});
|
|
77
|
-
for (const entry of entries) {
|
|
78
|
-
let path = join(directory, entry.name);
|
|
79
|
-
if (entry.isSymbolicLink()) {
|
|
80
|
-
if (followSymlinks) {
|
|
81
|
-
path = await realpath(path);
|
|
82
|
-
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
83
|
-
yield {
|
|
84
|
-
isDirectory: () => entry.isDirectory(),
|
|
85
|
-
isFile: () => entry.isFile(),
|
|
86
|
-
isSymbolicLink: () => entry.isSymbolicLink(),
|
|
87
|
-
name: entry.name,
|
|
88
|
-
path
|
|
89
|
-
};
|
|
90
|
-
continue;
|
|
91
|
-
} else {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (entry.isDirectory()) {
|
|
96
|
-
yield* walk(path, {
|
|
97
|
-
extensions,
|
|
98
|
-
followSymlinks,
|
|
99
|
-
includeDirs: includeDirectories,
|
|
100
|
-
includeFiles,
|
|
101
|
-
includeSymlinks,
|
|
102
|
-
match: mappedMatch,
|
|
103
|
-
maxDepth: maxDepth - 1,
|
|
104
|
-
skip: mappedSkip
|
|
105
|
-
});
|
|
106
|
-
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
107
|
-
yield {
|
|
108
|
-
isDirectory: () => entry.isDirectory(),
|
|
109
|
-
isFile: () => entry.isFile(),
|
|
110
|
-
isSymbolicLink: () => entry.isSymbolicLink(),
|
|
111
|
-
name: entry.name,
|
|
112
|
-
path
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
if (error instanceof WalkError) {
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
throw new WalkError(error, directory);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export { walk as default };
|
|
@@ -1,16 +0,0 @@
|
|
|
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 };
|
|
@@ -1,123 +0,0 @@
|
|
|
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-DER5A43G.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(
|
|
57
|
-
// eslint-disable-next-line no-confusing-arrow
|
|
58
|
-
(pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
|
|
59
|
-
) : void 0;
|
|
60
|
-
const mappedSkip = skip ? skip.map(
|
|
61
|
-
// eslint-disable-next-line no-confusing-arrow
|
|
62
|
-
(pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern
|
|
63
|
-
) : void 0;
|
|
64
|
-
const resolvedDirectory = resolve(toPath(directory));
|
|
65
|
-
directory = resolvedDirectory;
|
|
66
|
-
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
67
|
-
yield _createWalkEntry(directory);
|
|
68
|
-
}
|
|
69
|
-
if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
const entries = readdirSync(directory, {
|
|
74
|
-
withFileTypes: true
|
|
75
|
-
});
|
|
76
|
-
for (const entry of entries) {
|
|
77
|
-
let path = join(directory, entry.name);
|
|
78
|
-
if (entry.isSymbolicLink()) {
|
|
79
|
-
if (followSymlinks) {
|
|
80
|
-
path = realpathSync(path);
|
|
81
|
-
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
82
|
-
yield {
|
|
83
|
-
isDirectory: () => entry.isDirectory(),
|
|
84
|
-
isFile: () => entry.isFile(),
|
|
85
|
-
isSymbolicLink: () => entry.isSymbolicLink(),
|
|
86
|
-
name: entry.name,
|
|
87
|
-
path: normalize(path)
|
|
88
|
-
};
|
|
89
|
-
continue;
|
|
90
|
-
} else {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (entry.isDirectory()) {
|
|
95
|
-
yield* walkSync(path, {
|
|
96
|
-
extensions,
|
|
97
|
-
followSymlinks,
|
|
98
|
-
includeDirs: includeDirectories,
|
|
99
|
-
includeFiles,
|
|
100
|
-
includeSymlinks,
|
|
101
|
-
match: mappedMatch,
|
|
102
|
-
maxDepth: maxDepth - 1,
|
|
103
|
-
skip: mappedSkip
|
|
104
|
-
});
|
|
105
|
-
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
106
|
-
yield {
|
|
107
|
-
isDirectory: () => entry.isDirectory(),
|
|
108
|
-
isFile: () => entry.isFile(),
|
|
109
|
-
isSymbolicLink: () => entry.isSymbolicLink(),
|
|
110
|
-
name: entry.name,
|
|
111
|
-
path: normalize(path)
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} catch (error) {
|
|
116
|
-
if (error instanceof WalkError) {
|
|
117
|
-
throw error;
|
|
118
|
-
}
|
|
119
|
-
throw new WalkError(error, directory);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export { walkSync as default };
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
options.chown ??= { gid: stat$1.gid, uid: stat$1.uid };
|
|
62
|
-
await rename(path, `${path}.bak`);
|
|
63
|
-
}
|
|
64
|
-
if (options.chown) {
|
|
65
|
-
try {
|
|
66
|
-
await chown(temporaryPath, options.chown.uid, options.chown.gid);
|
|
67
|
-
} catch {
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
await chmod(temporaryPath, stat$1 && !options.mode ? stat$1.mode : options.mode ?? 438);
|
|
71
|
-
await rename(temporaryPath, path);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
|
|
74
|
-
} finally {
|
|
75
|
-
if (await isAccessible(temporaryPath)) {
|
|
76
|
-
await unlink(`${path}.tmp`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export { writeFile as default };
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
options.chown ??= { gid: stat.gid, uid: stat.uid };
|
|
62
|
-
renameSync(path, `${path}.bak`);
|
|
63
|
-
}
|
|
64
|
-
if (options.chown) {
|
|
65
|
-
try {
|
|
66
|
-
chownSync(temporaryPath, options.chown.uid, options.chown.gid);
|
|
67
|
-
} catch {
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
chmodSync(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
|
|
71
|
-
renameSync(temporaryPath, path);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
|
|
74
|
-
} finally {
|
|
75
|
-
if (isAccessibleSync(temporaryPath)) {
|
|
76
|
-
unlinkSync(`${path}.tmp`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export { writeFileSync as default };
|