@visulima/fs 3.1.6 → 3.1.8

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.
Files changed (232) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE.md +125 -0
  3. package/README.md +153 -153
  4. package/dist/eol.cjs +3 -28
  5. package/dist/eol.mjs +3 -20
  6. package/dist/error.cjs +1 -21
  7. package/dist/error.mjs +1 -7
  8. package/dist/index.cjs +1 -80
  9. package/dist/index.d.cts +2 -2
  10. package/dist/index.d.mts +2 -2
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.mjs +1 -31
  13. package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.mjs +1 -0
  14. package/dist/packem_shared/AlreadyExistsError-GC2XUgzJ.cjs +1 -0
  15. package/dist/packem_shared/DirectoryError-aGtmQVph.cjs +1 -0
  16. package/dist/packem_shared/DirectoryError-ddlbUV8C.mjs +1 -0
  17. package/dist/packem_shared/F_OK-7T91O6Oz.cjs +1 -0
  18. package/dist/packem_shared/F_OK-B71i3mUa.mjs +1 -0
  19. package/dist/packem_shared/JSONError-CVkb3xZ3.mjs +4 -0
  20. package/dist/packem_shared/JSONError-CWuiGmNc.cjs +4 -0
  21. package/dist/packem_shared/NotEmptyError-BWGfec5K.cjs +1 -0
  22. package/dist/packem_shared/NotEmptyError-DMh1o7UL.mjs +1 -0
  23. package/dist/packem_shared/NotFoundError-BPiW0icm.mjs +1 -0
  24. package/dist/packem_shared/NotFoundError-Diij7oqe.cjs +1 -0
  25. package/dist/packem_shared/PermissionError-B1Emi5a9.mjs +1 -0
  26. package/dist/packem_shared/PermissionError-Ck1Es7al.cjs +1 -0
  27. package/dist/packem_shared/WalkError-BsngoIKJ.mjs +1 -0
  28. package/dist/packem_shared/WalkError-gKgp0TWD.cjs +1 -0
  29. package/dist/packem_shared/assertValidFileContents-BZFnXa7K.mjs +1 -0
  30. package/dist/packem_shared/assertValidFileContents-CrbDz09d.cjs +1 -0
  31. package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.mjs +1 -0
  32. package/dist/packem_shared/assertValidFileOrDirectoryPath-HOUs73Jk.cjs +1 -0
  33. package/dist/packem_shared/collect-Bl2Oc1qs.cjs +1 -0
  34. package/dist/packem_shared/collect-CyYPQFMs.mjs +1 -0
  35. package/dist/packem_shared/collectSync-BHjyXWq4.cjs +1 -0
  36. package/dist/packem_shared/collectSync-CD9cXw2g.mjs +1 -0
  37. package/dist/packem_shared/emptyDir-BdjO-6Gu.mjs +1 -0
  38. package/dist/packem_shared/emptyDir-DGRw4yE9.cjs +1 -0
  39. package/dist/packem_shared/emptyDirSync-C1vsMEp-.mjs +1 -0
  40. package/dist/packem_shared/emptyDirSync-DzjDZxOx.cjs +1 -0
  41. package/dist/packem_shared/ensureDir-BuIFF_6B.mjs +1 -0
  42. package/dist/packem_shared/ensureDir-DtQzyA70.cjs +1 -0
  43. package/dist/packem_shared/ensureDirSync-BuPHxdP4.mjs +1 -0
  44. package/dist/packem_shared/ensureDirSync-C8hIoS3o.cjs +1 -0
  45. package/dist/packem_shared/ensureFile-DcAODM6a.mjs +1 -0
  46. package/dist/packem_shared/ensureFile-wR8zBfXh.cjs +1 -0
  47. package/dist/packem_shared/ensureFileSync-BI1fIdNf.cjs +1 -0
  48. package/dist/packem_shared/ensureFileSync-CzPN6ucX.mjs +1 -0
  49. package/dist/packem_shared/ensureLink-BaZLXxgx.mjs +1 -0
  50. package/dist/packem_shared/ensureLink-DCPuU0Za.cjs +1 -0
  51. package/dist/packem_shared/ensureLinkSync-9C2JL-Sl.mjs +1 -0
  52. package/dist/packem_shared/ensureLinkSync-CuRZmQlV.cjs +1 -0
  53. package/dist/packem_shared/ensureSymlink-BH6wbylb.mjs +1 -0
  54. package/dist/packem_shared/ensureSymlink-J83jhdfA.cjs +1 -0
  55. package/dist/packem_shared/ensureSymlinkSync-CZSPodAm.mjs +1 -0
  56. package/dist/packem_shared/ensureSymlinkSync-VNtMTaV8.cjs +1 -0
  57. package/dist/packem_shared/findUp-C5aWsLuD.cjs +1 -0
  58. package/dist/packem_shared/findUp-CMGMYNty.mjs +1 -0
  59. package/dist/packem_shared/findUpSync-QP_ZEsJN.mjs +1 -0
  60. package/dist/packem_shared/findUpSync-U1lTgv4y.cjs +1 -0
  61. package/dist/packem_shared/get-file-info-type-CaWGXRjY.mjs +1 -0
  62. package/dist/packem_shared/get-file-info-type-DDbpRlDl.cjs +1 -0
  63. package/dist/packem_shared/index-BSjF-5vj.mjs +1 -0
  64. package/dist/packem_shared/index-DPla58ce.cjs +1 -0
  65. package/dist/packem_shared/is-stats-identical-Bti7K05l.cjs +1 -0
  66. package/dist/packem_shared/is-stats-identical-CohsLtWy.mjs +1 -0
  67. package/dist/packem_shared/isAccessible-BQZd1_xn.cjs +1 -0
  68. package/dist/packem_shared/isAccessible-CL4eE5VL.mjs +1 -0
  69. package/dist/packem_shared/isAccessibleSync-BP5N8k_-.cjs +1 -0
  70. package/dist/packem_shared/isAccessibleSync-_HU_ppdG.mjs +1 -0
  71. package/dist/packem_shared/move--o4NZLpD.mjs +1 -0
  72. package/dist/packem_shared/move-DwG6APiG.cjs +1 -0
  73. package/dist/packem_shared/parseJson-B_GwHpKj.cjs +6 -0
  74. package/dist/packem_shared/parseJson-Bqic0nN8.mjs +6 -0
  75. package/dist/packem_shared/readFile-BvefDyr_.cjs +1 -0
  76. package/dist/packem_shared/readFile-Cix_ijtX.mjs +1 -0
  77. package/dist/packem_shared/readFileSync-B0O-8BH0.mjs +1 -0
  78. package/dist/packem_shared/readFileSync-Ct8Ql4Vs.cjs +1 -0
  79. package/dist/packem_shared/readJson-BLvd2Bsj.mjs +1 -0
  80. package/dist/packem_shared/readJson-cP5ArpPg.cjs +1 -0
  81. package/dist/packem_shared/readJsonSync-B6h6A3Un.cjs +1 -0
  82. package/dist/packem_shared/readJsonSync-Br5dHGAI.mjs +1 -0
  83. package/dist/packem_shared/readYaml-BOYTR5D1.mjs +1 -0
  84. package/dist/packem_shared/readYaml-BzMFDsYe.cjs +1 -0
  85. package/dist/packem_shared/readYamlSync-BbK0khJu.cjs +1 -0
  86. package/dist/packem_shared/readYamlSync-md9g88k7.mjs +1 -0
  87. package/dist/packem_shared/remove-CtnFqEpd.mjs +1 -0
  88. package/dist/packem_shared/remove-DPCf2Qdb.cjs +1 -0
  89. package/dist/packem_shared/removeSync-Cyriz7r8.cjs +1 -0
  90. package/dist/packem_shared/removeSync-DI-IjqVp.mjs +1 -0
  91. package/dist/packem_shared/resolve-symlink-target-BofZSDIc.mjs +1 -0
  92. package/dist/packem_shared/resolve-symlink-target-zilkQ_AU.cjs +1 -0
  93. package/dist/packem_shared/stripJsonComments-Cp5SNAB7.mjs +1 -0
  94. package/dist/packem_shared/stripJsonComments-CvZSDnYT.cjs +1 -0
  95. package/dist/packem_shared/to-uint-8-array-2-3EvGd7.cjs +1 -0
  96. package/dist/packem_shared/to-uint-8-array-DwgaTasY.mjs +1 -0
  97. package/dist/packem_shared/{types-BaMGfHdp.d.ts → types-XsSUZ9oS.d.cts} +1 -1
  98. package/dist/packem_shared/{types-BaMGfHdp.d.mts → types-XsSUZ9oS.d.mts} +1 -1
  99. package/dist/packem_shared/{types-BaMGfHdp.d.cts → types-XsSUZ9oS.d.ts} +1 -1
  100. package/dist/packem_shared/walk-BZTXbT87.mjs +1 -0
  101. package/dist/packem_shared/walk-DyN_HVFW.cjs +1 -0
  102. package/dist/packem_shared/walk-include-C9pVST87.mjs +1 -0
  103. package/dist/packem_shared/walk-include-DkK-WJl4.cjs +1 -0
  104. package/dist/packem_shared/walkSync-BHlEzV_m.mjs +1 -0
  105. package/dist/packem_shared/walkSync-Bqi7L2yG.cjs +1 -0
  106. package/dist/packem_shared/writeFile-COOAkvOE.mjs +1 -0
  107. package/dist/packem_shared/writeFile-CjgQEfur.cjs +1 -0
  108. package/dist/packem_shared/writeFileSync-CQuRHo9n.cjs +1 -0
  109. package/dist/packem_shared/writeFileSync-rhu-y_zx.mjs +1 -0
  110. package/dist/packem_shared/writeJson-BYT4WInm.mjs +4 -0
  111. package/dist/packem_shared/writeJson-CJIciZ_Q.cjs +4 -0
  112. package/dist/packem_shared/writeJsonSync-BIsrhRbV.cjs +4 -0
  113. package/dist/packem_shared/writeJsonSync-CLlXOFDm.mjs +4 -0
  114. package/dist/packem_shared/writeYaml-CjzVd0K-.mjs +1 -0
  115. package/dist/packem_shared/writeYaml-VmX1VKhN.cjs +1 -0
  116. package/dist/packem_shared/writeYamlSync-D9A9Ixe1.mjs +1 -0
  117. package/dist/packem_shared/writeYamlSync-DYsM6XBi.cjs +1 -0
  118. package/dist/size.cjs +1 -118
  119. package/dist/size.mjs +1 -109
  120. package/dist/utils.cjs +1 -19
  121. package/dist/utils.d.cts +1 -1
  122. package/dist/utils.d.mts +1 -1
  123. package/dist/utils.d.ts +1 -1
  124. package/dist/utils.mjs +1 -6
  125. package/dist/yaml.cjs +1 -15
  126. package/dist/yaml.d.cts +1 -1
  127. package/dist/yaml.d.mts +1 -1
  128. package/dist/yaml.d.ts +1 -1
  129. package/dist/yaml.mjs +1 -4
  130. package/package.json +1 -1
  131. package/dist/packem_shared/AlreadyExistsError-DpxtwQot.cjs +0 -34
  132. package/dist/packem_shared/AlreadyExistsError-GK7J9fVA.mjs +0 -32
  133. package/dist/packem_shared/DirectoryError-D8FHcAqu.cjs +0 -34
  134. package/dist/packem_shared/DirectoryError-DByTWE7t.mjs +0 -32
  135. package/dist/packem_shared/F_OK-CWSqQIdF.cjs +0 -17
  136. package/dist/packem_shared/F_OK-JER1LjUr.mjs +0 -8
  137. package/dist/packem_shared/JSONError-5-wHnrxX.cjs +0 -34
  138. package/dist/packem_shared/JSONError-CaKt7MhC.mjs +0 -32
  139. package/dist/packem_shared/NotEmptyError-BCS_5pPt.cjs +0 -34
  140. package/dist/packem_shared/NotEmptyError-DCXooh5l.mjs +0 -32
  141. package/dist/packem_shared/NotFoundError-B_1nPl3K.cjs +0 -34
  142. package/dist/packem_shared/NotFoundError-CUdcC61I.mjs +0 -32
  143. package/dist/packem_shared/PermissionError-CqGMI9qC.mjs +0 -32
  144. package/dist/packem_shared/PermissionError-QFMKgk2l.cjs +0 -34
  145. package/dist/packem_shared/WalkError-B4-yr8Kk.cjs +0 -31
  146. package/dist/packem_shared/WalkError-DvEBTTaj.mjs +0 -29
  147. package/dist/packem_shared/assertValidFileContents-CRVvyM6b.cjs +0 -11
  148. package/dist/packem_shared/assertValidFileContents-Ox-ScfeK.mjs +0 -9
  149. package/dist/packem_shared/assertValidFileOrDirectoryPath-BMbgA-eI.cjs +0 -11
  150. package/dist/packem_shared/assertValidFileOrDirectoryPath-BWWgA1wj.mjs +0 -9
  151. package/dist/packem_shared/collect-3Paj1Vqw.mjs +0 -16
  152. package/dist/packem_shared/collect-DnfQeSOL.cjs +0 -18
  153. package/dist/packem_shared/collectSync-D4vym4QD.cjs +0 -18
  154. package/dist/packem_shared/collectSync-DwJLL8SD.mjs +0 -16
  155. package/dist/packem_shared/emptyDir-DcCfiNcf.cjs +0 -22
  156. package/dist/packem_shared/emptyDir-Dw5xSBox.mjs +0 -20
  157. package/dist/packem_shared/emptyDirSync-BWA4n6TB.cjs +0 -21
  158. package/dist/packem_shared/emptyDirSync-DMAaCiC_.mjs +0 -19
  159. package/dist/packem_shared/ensureDir-BOfUZlxG.cjs +0 -35
  160. package/dist/packem_shared/ensureDir-BnA_fY1A.mjs +0 -33
  161. package/dist/packem_shared/ensureDirSync-DHmWi3CF.cjs +0 -35
  162. package/dist/packem_shared/ensureDirSync-Dm4az3YF.mjs +0 -33
  163. package/dist/packem_shared/ensureFile-BKrJMHfr.mjs +0 -27
  164. package/dist/packem_shared/ensureFile-CeGryLJI.cjs +0 -29
  165. package/dist/packem_shared/ensureFileSync-B7THM1sN.cjs +0 -29
  166. package/dist/packem_shared/ensureFileSync-BnhFBXaR.mjs +0 -27
  167. package/dist/packem_shared/ensureLink-ChsWDTK5.mjs +0 -34
  168. package/dist/packem_shared/ensureLink-CrxLNmHE.cjs +0 -36
  169. package/dist/packem_shared/ensureLinkSync-CG-DTUoV.mjs +0 -34
  170. package/dist/packem_shared/ensureLinkSync-D8uMqLh4.cjs +0 -36
  171. package/dist/packem_shared/ensureSymlink-BwJ_QhzJ.mjs +0 -52
  172. package/dist/packem_shared/ensureSymlink-D_ieOVYa.cjs +0 -54
  173. package/dist/packem_shared/ensureSymlinkSync-BamG29QK.mjs +0 -56
  174. package/dist/packem_shared/ensureSymlinkSync-DTMvUYZD.cjs +0 -58
  175. package/dist/packem_shared/findUp-D5W-MTpT.mjs +0 -63
  176. package/dist/packem_shared/findUp-DVIYN2wV.cjs +0 -65
  177. package/dist/packem_shared/findUpSync-BOiVyUOx.cjs +0 -65
  178. package/dist/packem_shared/findUpSync-DL3NPCYg.mjs +0 -63
  179. package/dist/packem_shared/get-file-info-type-BlryFnpp.cjs +0 -18
  180. package/dist/packem_shared/get-file-info-type-ButUVD6d.mjs +0 -16
  181. package/dist/packem_shared/index-BVZL6YMm.cjs +0 -110
  182. package/dist/packem_shared/index-r9Pk9gBe.mjs +0 -108
  183. package/dist/packem_shared/is-stats-identical-BfdEfO6i.cjs +0 -7
  184. package/dist/packem_shared/is-stats-identical-ByTYZ2Aw.mjs +0 -5
  185. package/dist/packem_shared/isAccessible-Bonsm1Ez.mjs +0 -20
  186. package/dist/packem_shared/isAccessible-ZNVGsSb7.cjs +0 -22
  187. package/dist/packem_shared/isAccessibleSync-3gnUWUwX.mjs +0 -20
  188. package/dist/packem_shared/isAccessibleSync-VWjQa-US.cjs +0 -22
  189. package/dist/packem_shared/move-DgF7Ul9L.mjs +0 -114
  190. package/dist/packem_shared/move-Dh925GL9.cjs +0 -121
  191. package/dist/packem_shared/parseJson-BA7Xrggq.mjs +0 -248
  192. package/dist/packem_shared/parseJson-LgPGI5ic.cjs +0 -250
  193. package/dist/packem_shared/readFile-b7UBVv17.mjs +0 -46
  194. package/dist/packem_shared/readFile-iFUhZHnh.cjs +0 -48
  195. package/dist/packem_shared/readFileSync-B3NTOR-W.cjs +0 -33
  196. package/dist/packem_shared/readFileSync-CkEJBqZB.mjs +0 -31
  197. package/dist/packem_shared/readJson-CEBHyuYq.cjs +0 -27
  198. package/dist/packem_shared/readJson-Ce9b06cu.mjs +0 -25
  199. package/dist/packem_shared/readJsonSync-B22hej0y.cjs +0 -27
  200. package/dist/packem_shared/readJsonSync-CkUI9_z5.mjs +0 -25
  201. package/dist/packem_shared/readYaml-C5MSs2GE.mjs +0 -13
  202. package/dist/packem_shared/readYaml-sR4bqUel.cjs +0 -15
  203. package/dist/packem_shared/readYamlSync-C3oOzxiN.cjs +0 -15
  204. package/dist/packem_shared/readYamlSync-CPjA-DLv.mjs +0 -13
  205. package/dist/packem_shared/remove-B2nxUObP.mjs +0 -18
  206. package/dist/packem_shared/remove-BpDiVPns.cjs +0 -20
  207. package/dist/packem_shared/removeSync-BosXW624.cjs +0 -20
  208. package/dist/packem_shared/removeSync-C87yepDI.mjs +0 -18
  209. package/dist/packem_shared/resolve-symlink-target-BbpEHdU2.mjs +0 -18
  210. package/dist/packem_shared/resolve-symlink-target-DImIddt6.cjs +0 -20
  211. package/dist/packem_shared/stripJsonComments-B66nRaTZ.mjs +0 -21
  212. package/dist/packem_shared/stripJsonComments-eDrcJvBT.cjs +0 -23
  213. package/dist/packem_shared/to-uint-8-array-B4CjMOD3.mjs +0 -21
  214. package/dist/packem_shared/to-uint-8-array-BaTEyX3D.cjs +0 -23
  215. package/dist/packem_shared/walk-CI3ygmrw.cjs +0 -100
  216. package/dist/packem_shared/walk-D7YA43g8.mjs +0 -98
  217. package/dist/packem_shared/walk-include-CMUSRa86.mjs +0 -20
  218. package/dist/packem_shared/walk-include-yUdRrF16.cjs +0 -23
  219. package/dist/packem_shared/walkSync-DLTsnwuJ.mjs +0 -103
  220. package/dist/packem_shared/walkSync-oXkmn9ZA.cjs +0 -105
  221. package/dist/packem_shared/writeFile-BZ4JBQxc.mjs +0 -58
  222. package/dist/packem_shared/writeFile-DgCFRCe5.cjs +0 -60
  223. package/dist/packem_shared/writeFileSync-Ctw5pNQH.mjs +0 -58
  224. package/dist/packem_shared/writeFileSync-DzXhx1pF.cjs +0 -60
  225. package/dist/packem_shared/writeJson-Bh4sU1Ly.cjs +0 -33
  226. package/dist/packem_shared/writeJson-axO_14yL.mjs +0 -31
  227. package/dist/packem_shared/writeJsonSync-CzngmuKb.mjs +0 -31
  228. package/dist/packem_shared/writeJsonSync-HFdHjunl.cjs +0 -33
  229. package/dist/packem_shared/writeYaml-3XQT2qtb.cjs +0 -29
  230. package/dist/packem_shared/writeYaml-BSFEuWp2.mjs +0 -27
  231. package/dist/packem_shared/writeYamlSync-B6VcXXIb.mjs +0 -27
  232. package/dist/packem_shared/writeYamlSync-BZR3If9v.cjs +0 -29
@@ -1,60 +0,0 @@
1
- 'use strict';
2
-
3
- const promises = require('node:fs/promises');
4
- const path = require('@visulima/path');
5
- const utils = require('@visulima/path/utils');
6
- const F_OK = require('./F_OK-CWSqQIdF.cjs');
7
- const isAccessible = require('./isAccessible-ZNVGsSb7.cjs');
8
- const assertValidFileContents = require('./assertValidFileContents-CRVvyM6b.cjs');
9
- const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
10
- const toUint8Array = require('./to-uint-8-array-BaTEyX3D.cjs');
11
-
12
- var __defProp = Object.defineProperty;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
- const writeFile = /* @__PURE__ */ __name(async (path$1, content, options) => {
15
- options = {
16
- encoding: "utf8",
17
- flag: "w",
18
- overwrite: true,
19
- recursive: true,
20
- ...options
21
- };
22
- assertValidFileOrDirectoryPath(path$1);
23
- assertValidFileContents(content);
24
- path$1 = utils.toPath(path$1);
25
- const temporaryPath = `${path$1}.tmp`;
26
- try {
27
- const pathExists = await isAccessible(path$1, F_OK.F_OK);
28
- if (!pathExists && options.recursive) {
29
- const directory = path.dirname(path$1);
30
- if (!await isAccessible(directory, F_OK.F_OK)) {
31
- await promises.mkdir(directory, { recursive: true });
32
- }
33
- }
34
- let stat;
35
- await promises.writeFile(temporaryPath, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
36
- if (pathExists && !options.overwrite) {
37
- stat = await promises.stat(path$1);
38
- if (options.chown === void 0) {
39
- options.chown = { gid: stat.gid, uid: stat.uid };
40
- }
41
- await promises.rename(path$1, `${path$1}.bak`);
42
- }
43
- if (options.chown) {
44
- try {
45
- await promises.chown(temporaryPath, options.chown.uid, options.chown.gid);
46
- } catch {
47
- }
48
- }
49
- await promises.chmod(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
50
- await promises.rename(temporaryPath, path$1);
51
- } catch (error) {
52
- throw new Error(`Failed to write file at: ${path$1} - ${error.message}`, { cause: error });
53
- } finally {
54
- if (await isAccessible(temporaryPath)) {
55
- await promises.unlink(`${path$1}.tmp`);
56
- }
57
- }
58
- }, "writeFile");
59
-
60
- module.exports = writeFile;
@@ -1,58 +0,0 @@
1
- import { mkdirSync, writeFileSync as writeFileSync$1, statSync, renameSync, chownSync, chmodSync, unlinkSync } from 'node:fs';
2
- import { dirname } from '@visulima/path';
3
- import { toPath } from '@visulima/path/utils';
4
- import { F_OK } from './F_OK-JER1LjUr.mjs';
5
- import isAccessibleSync from './isAccessibleSync-3gnUWUwX.mjs';
6
- import assertValidFileContents from './assertValidFileContents-Ox-ScfeK.mjs';
7
- import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
8
- import { t as toUint8Array } from './to-uint-8-array-B4CjMOD3.mjs';
9
-
10
- var __defProp = Object.defineProperty;
11
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- const writeFileSync = /* @__PURE__ */ __name((path, content, options) => {
13
- options = {
14
- encoding: "utf8",
15
- flag: "w",
16
- overwrite: true,
17
- recursive: true,
18
- ...options
19
- };
20
- assertValidFileOrDirectoryPath(path);
21
- assertValidFileContents(content);
22
- path = toPath(path);
23
- const temporaryPath = `${path}.tmp`;
24
- try {
25
- const pathExists = isAccessibleSync(path, F_OK);
26
- if (!pathExists && options.recursive) {
27
- const directory = dirname(path);
28
- if (!isAccessibleSync(directory, F_OK)) {
29
- mkdirSync(directory, { recursive: true });
30
- }
31
- }
32
- let stat;
33
- writeFileSync$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
34
- if (pathExists && !options.overwrite) {
35
- stat = statSync(path);
36
- if (options.chown === void 0) {
37
- options.chown = { gid: stat.gid, uid: stat.uid };
38
- }
39
- renameSync(path, `${path}.bak`);
40
- }
41
- if (options.chown) {
42
- try {
43
- chownSync(temporaryPath, options.chown.uid, options.chown.gid);
44
- } catch {
45
- }
46
- }
47
- chmodSync(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
48
- renameSync(temporaryPath, path);
49
- } catch (error) {
50
- throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
51
- } finally {
52
- if (isAccessibleSync(temporaryPath)) {
53
- unlinkSync(`${path}.tmp`);
54
- }
55
- }
56
- }, "writeFileSync");
57
-
58
- export { writeFileSync as default };
@@ -1,60 +0,0 @@
1
- 'use strict';
2
-
3
- const node_fs = require('node:fs');
4
- const path = require('@visulima/path');
5
- const utils = require('@visulima/path/utils');
6
- const F_OK = require('./F_OK-CWSqQIdF.cjs');
7
- const isAccessibleSync = require('./isAccessibleSync-VWjQa-US.cjs');
8
- const assertValidFileContents = require('./assertValidFileContents-CRVvyM6b.cjs');
9
- const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
10
- const toUint8Array = require('./to-uint-8-array-BaTEyX3D.cjs');
11
-
12
- var __defProp = Object.defineProperty;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
- const writeFileSync = /* @__PURE__ */ __name((path$1, content, options) => {
15
- options = {
16
- encoding: "utf8",
17
- flag: "w",
18
- overwrite: true,
19
- recursive: true,
20
- ...options
21
- };
22
- assertValidFileOrDirectoryPath(path$1);
23
- assertValidFileContents(content);
24
- path$1 = utils.toPath(path$1);
25
- const temporaryPath = `${path$1}.tmp`;
26
- try {
27
- const pathExists = isAccessibleSync(path$1, F_OK.F_OK);
28
- if (!pathExists && options.recursive) {
29
- const directory = path.dirname(path$1);
30
- if (!isAccessibleSync(directory, F_OK.F_OK)) {
31
- node_fs.mkdirSync(directory, { recursive: true });
32
- }
33
- }
34
- let stat;
35
- node_fs.writeFileSync(temporaryPath, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
36
- if (pathExists && !options.overwrite) {
37
- stat = node_fs.statSync(path$1);
38
- if (options.chown === void 0) {
39
- options.chown = { gid: stat.gid, uid: stat.uid };
40
- }
41
- node_fs.renameSync(path$1, `${path$1}.bak`);
42
- }
43
- if (options.chown) {
44
- try {
45
- node_fs.chownSync(temporaryPath, options.chown.uid, options.chown.gid);
46
- } catch {
47
- }
48
- }
49
- node_fs.chmodSync(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
50
- node_fs.renameSync(temporaryPath, path$1);
51
- } catch (error) {
52
- throw new Error(`Failed to write file at: ${path$1} - ${error.message}`, { cause: error });
53
- } finally {
54
- if (isAccessibleSync(temporaryPath)) {
55
- node_fs.unlinkSync(`${path$1}.tmp`);
56
- }
57
- }
58
- }, "writeFileSync");
59
-
60
- module.exports = writeFileSync;
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- const promises = require('node:fs/promises');
4
- const index = require('./index-BVZL6YMm.cjs');
5
- const F_OK = require('./F_OK-CWSqQIdF.cjs');
6
- const isAccessible = require('./isAccessible-ZNVGsSb7.cjs');
7
- const writeFile = require('./writeFile-DgCFRCe5.cjs');
8
-
9
- var __defProp = Object.defineProperty;
10
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- const writeJson = /* @__PURE__ */ __name(async (path, data, options = {}) => {
12
- const { detectIndent, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
13
- let indent = indentOption;
14
- let trailingNewline = "\n";
15
- if (await isAccessible(path, F_OK.R_OK)) {
16
- try {
17
- const file = await promises.readFile(path, "utf8");
18
- if (detectIndent) {
19
- const { indent: dIndent } = index.detectIndent(file);
20
- indent = dIndent;
21
- }
22
- trailingNewline = file.endsWith("\n") ? "\n" : "";
23
- } catch (error) {
24
- if (error.code !== "ENOENT") {
25
- throw error;
26
- }
27
- }
28
- }
29
- const json = stringify(data, replacer, indent);
30
- await writeFile(path, `${json}${trailingNewline}`, writeOptions);
31
- }, "writeJson");
32
-
33
- module.exports = writeJson;
@@ -1,31 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { d as detectIndent } from './index-r9Pk9gBe.mjs';
3
- import { R_OK } from './F_OK-JER1LjUr.mjs';
4
- import isAccessible from './isAccessible-Bonsm1Ez.mjs';
5
- import writeFile from './writeFile-BZ4JBQxc.mjs';
6
-
7
- var __defProp = Object.defineProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- const writeJson = /* @__PURE__ */ __name(async (path, data, options = {}) => {
10
- const { detectIndent: detectIndent$1, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
11
- let indent = indentOption;
12
- let trailingNewline = "\n";
13
- if (await isAccessible(path, R_OK)) {
14
- try {
15
- const file = await readFile(path, "utf8");
16
- if (detectIndent$1) {
17
- const { indent: dIndent } = detectIndent(file);
18
- indent = dIndent;
19
- }
20
- trailingNewline = file.endsWith("\n") ? "\n" : "";
21
- } catch (error) {
22
- if (error.code !== "ENOENT") {
23
- throw error;
24
- }
25
- }
26
- }
27
- const json = stringify(data, replacer, indent);
28
- await writeFile(path, `${json}${trailingNewline}`, writeOptions);
29
- }, "writeJson");
30
-
31
- export { writeJson as default };
@@ -1,31 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { d as detectIndent } from './index-r9Pk9gBe.mjs';
3
- import { R_OK } from './F_OK-JER1LjUr.mjs';
4
- import isAccessibleSync from './isAccessibleSync-3gnUWUwX.mjs';
5
- import writeFileSync from './writeFileSync-Ctw5pNQH.mjs';
6
-
7
- var __defProp = Object.defineProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- const writeJsonSync = /* @__PURE__ */ __name((path, data, options = {}) => {
10
- const { detectIndent: detectIndent$1, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
11
- let indent = indentOption;
12
- let trailingNewline = "\n";
13
- if (isAccessibleSync(path, R_OK)) {
14
- try {
15
- const file = readFileSync(path, "utf8");
16
- if (detectIndent$1) {
17
- const { indent: dIndent } = detectIndent(file);
18
- indent = dIndent;
19
- }
20
- trailingNewline = file.endsWith("\n") ? "\n" : "";
21
- } catch (error) {
22
- if (error.code !== "ENOENT") {
23
- throw error;
24
- }
25
- }
26
- }
27
- const json = stringify(data, replacer, indent);
28
- writeFileSync(path, `${json}${trailingNewline}`, writeOptions);
29
- }, "writeJsonSync");
30
-
31
- export { writeJsonSync as default };
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- const node_fs = require('node:fs');
4
- const index = require('./index-BVZL6YMm.cjs');
5
- const F_OK = require('./F_OK-CWSqQIdF.cjs');
6
- const isAccessibleSync = require('./isAccessibleSync-VWjQa-US.cjs');
7
- const writeFileSync = require('./writeFileSync-DzXhx1pF.cjs');
8
-
9
- var __defProp = Object.defineProperty;
10
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- const writeJsonSync = /* @__PURE__ */ __name((path, data, options = {}) => {
12
- const { detectIndent, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
13
- let indent = indentOption;
14
- let trailingNewline = "\n";
15
- if (isAccessibleSync(path, F_OK.R_OK)) {
16
- try {
17
- const file = node_fs.readFileSync(path, "utf8");
18
- if (detectIndent) {
19
- const { indent: dIndent } = index.detectIndent(file);
20
- indent = dIndent;
21
- }
22
- trailingNewline = file.endsWith("\n") ? "\n" : "";
23
- } catch (error) {
24
- if (error.code !== "ENOENT") {
25
- throw error;
26
- }
27
- }
28
- }
29
- const json = stringify(data, replacer, indent);
30
- writeFileSync(path, `${json}${trailingNewline}`, writeOptions);
31
- }, "writeJsonSync");
32
-
33
- module.exports = writeJsonSync;
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- const yaml = require('yaml');
4
- const writeFile = require('./writeFile-DgCFRCe5.cjs');
5
-
6
- var __defProp = Object.defineProperty;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- async function writeYaml(path, data, replacer, options) {
9
- let stringifyOptions;
10
- let effectiveReplacer;
11
- let space;
12
- if (typeof replacer === "object" && replacer !== null && !Array.isArray(replacer) && typeof replacer !== "function") {
13
- stringifyOptions = replacer;
14
- effectiveReplacer = stringifyOptions.replacer;
15
- space = stringifyOptions.space;
16
- } else if (typeof options === "object" && options !== null) {
17
- stringifyOptions = options;
18
- effectiveReplacer = replacer;
19
- space = stringifyOptions.space ?? (typeof options === "number" || typeof options === "string" ? options : void 0);
20
- } else {
21
- effectiveReplacer = replacer;
22
- space = options;
23
- }
24
- const content = yaml.stringify(data, effectiveReplacer, space ?? stringifyOptions);
25
- await writeFile(path, content, stringifyOptions);
26
- }
27
- __name(writeYaml, "writeYaml");
28
-
29
- module.exports = writeYaml;
@@ -1,27 +0,0 @@
1
- import { stringify } from 'yaml';
2
- import writeFile from './writeFile-BZ4JBQxc.mjs';
3
-
4
- var __defProp = Object.defineProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- async function writeYaml(path, data, replacer, options) {
7
- let stringifyOptions;
8
- let effectiveReplacer;
9
- let space;
10
- if (typeof replacer === "object" && replacer !== null && !Array.isArray(replacer) && typeof replacer !== "function") {
11
- stringifyOptions = replacer;
12
- effectiveReplacer = stringifyOptions.replacer;
13
- space = stringifyOptions.space;
14
- } else if (typeof options === "object" && options !== null) {
15
- stringifyOptions = options;
16
- effectiveReplacer = replacer;
17
- space = stringifyOptions.space ?? (typeof options === "number" || typeof options === "string" ? options : void 0);
18
- } else {
19
- effectiveReplacer = replacer;
20
- space = options;
21
- }
22
- const content = stringify(data, effectiveReplacer, space ?? stringifyOptions);
23
- await writeFile(path, content, stringifyOptions);
24
- }
25
- __name(writeYaml, "writeYaml");
26
-
27
- export { writeYaml as default };
@@ -1,27 +0,0 @@
1
- import { stringify } from 'yaml';
2
- import writeFileSync from './writeFileSync-Ctw5pNQH.mjs';
3
-
4
- var __defProp = Object.defineProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- function writeYamlSync(path, data, replacer, options) {
7
- let stringifyOptions;
8
- let effectiveReplacer;
9
- let space;
10
- if (typeof replacer === "object" && replacer !== null && !Array.isArray(replacer) && typeof replacer !== "function") {
11
- stringifyOptions = replacer;
12
- effectiveReplacer = stringifyOptions.replacer;
13
- space = stringifyOptions.space;
14
- } else if (typeof options === "object" && options !== null) {
15
- stringifyOptions = options;
16
- effectiveReplacer = replacer;
17
- space = stringifyOptions.space ?? (typeof options === "number" || typeof options === "string" ? options : void 0);
18
- } else {
19
- effectiveReplacer = replacer;
20
- space = options;
21
- }
22
- const content = stringify(data, effectiveReplacer, space ?? stringifyOptions);
23
- writeFileSync(path, content, stringifyOptions);
24
- }
25
- __name(writeYamlSync, "writeYamlSync");
26
-
27
- export { writeYamlSync as default };
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- const yaml = require('yaml');
4
- const writeFileSync = require('./writeFileSync-DzXhx1pF.cjs');
5
-
6
- var __defProp = Object.defineProperty;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- function writeYamlSync(path, data, replacer, options) {
9
- let stringifyOptions;
10
- let effectiveReplacer;
11
- let space;
12
- if (typeof replacer === "object" && replacer !== null && !Array.isArray(replacer) && typeof replacer !== "function") {
13
- stringifyOptions = replacer;
14
- effectiveReplacer = stringifyOptions.replacer;
15
- space = stringifyOptions.space;
16
- } else if (typeof options === "object" && options !== null) {
17
- stringifyOptions = options;
18
- effectiveReplacer = replacer;
19
- space = stringifyOptions.space ?? (typeof options === "number" || typeof options === "string" ? options : void 0);
20
- } else {
21
- effectiveReplacer = replacer;
22
- space = options;
23
- }
24
- const content = yaml.stringify(data, effectiveReplacer, space ?? stringifyOptions);
25
- writeFileSync(path, content, stringifyOptions);
26
- }
27
- __name(writeYamlSync, "writeYamlSync");
28
-
29
- module.exports = writeYamlSync;