@visulima/fs 5.0.0-alpha.8 → 5.0.0-alpha.9

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 (121) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE.md +155 -1
  3. package/dist/eol.d.ts +6 -35
  4. package/dist/error.d.ts +43 -7
  5. package/dist/glob-parent.d.ts +5 -0
  6. package/dist/glob-parent.js +90 -0
  7. package/dist/glob.d.ts +5 -0
  8. package/dist/glob.js +2 -0
  9. package/dist/index.d.ts +81 -36
  10. package/dist/index.js +12 -7
  11. package/dist/ini.d.ts +10 -0
  12. package/dist/ini.js +4 -0
  13. package/dist/is-glob.d.ts +5 -0
  14. package/dist/is-glob.js +9 -0
  15. package/dist/json5.d.ts +12 -0
  16. package/dist/json5.js +4 -0
  17. package/dist/jsonc.d.ts +10 -0
  18. package/dist/jsonc.js +4 -0
  19. package/dist/match.d.ts +5 -0
  20. package/dist/match.js +15 -0
  21. package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +5 -0
  22. package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +12 -0
  23. package/dist/packem_shared/{emptyDir-Df4Tfjtk.js → emptyDir-DnwENOaV.js} +3 -1
  24. package/dist/packem_shared/{emptyDirSync-BD8-1Ytl.js → emptyDirSync-6WiHBo8a.js} +3 -1
  25. package/dist/packem_shared/glob-DY8l7izD.js +5 -0
  26. package/dist/packem_shared/glob-sync.d-B83kqwUd.d.ts +4 -0
  27. package/dist/packem_shared/globSync-5P2KJf_g.js +5 -0
  28. package/dist/packem_shared/index-C8W8sfzP.js +830 -0
  29. package/dist/packem_shared/index-bhgnhm4u.js +167 -0
  30. package/dist/packem_shared/index-xe4o3cYi.js +1784 -0
  31. package/dist/packem_shared/{parseJson-BedVi91S.js → indexToLineColumn-BUb0GPKl-BF770uX7.js} +1 -62
  32. package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +251 -0
  33. package/dist/packem_shared/{isFsCaseSensitive-D-ayleCy.js → isFsCaseSensitive-DunL7Iry.js} +6 -6
  34. package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +10 -0
  35. package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +72 -0
  36. package/dist/packem_shared/parseJson-BIp89Xjo.js +63 -0
  37. package/dist/packem_shared/readIni-CJ2xfpjB.js +10 -0
  38. package/dist/packem_shared/readIniSync-9LUjaSSp.js +10 -0
  39. package/dist/packem_shared/{readJson-D0G0ndHL.js → readJson-C_rwm-wq.js} +1 -1
  40. package/dist/packem_shared/readJson5-mBoTZppy.js +15 -0
  41. package/dist/packem_shared/readJson5Sync-8WS2yUok.js +15 -0
  42. package/dist/packem_shared/{readJsonSync-B7oicPaL.js → readJsonSync-BMEmCcJ6.js} +1 -1
  43. package/dist/packem_shared/readJsonc-j-OS-APg.js +28 -0
  44. package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +16 -0
  45. package/dist/packem_shared/readToml-B2MHaSes.js +9 -0
  46. package/dist/packem_shared/readTomlSync-DNbK8NEb.js +9 -0
  47. package/dist/packem_shared/{remove-CNkjFFkQ.js → remove-C8_gl3jF.js} +2 -1
  48. package/dist/packem_shared/{removeSync-AnawYpPv.js → removeSync-BJR_wTwN.js} +2 -1
  49. package/dist/packem_shared/types.d-dP-lAGNn.d.ts +145 -0
  50. package/dist/packem_shared/writeIni-i55QrL8y.js +65 -0
  51. package/dist/packem_shared/writeIniSync-CLqJE5t3.js +64 -0
  52. package/dist/packem_shared/writeJson5-vVmHUQOd.js +53 -0
  53. package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +53 -0
  54. package/dist/packem_shared/writeJsonc-BufH_oC5.js +60 -0
  55. package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +59 -0
  56. package/dist/packem_shared/writeToml-DgTW_-7F.js +8 -0
  57. package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +8 -0
  58. package/dist/size.d.ts +10 -254
  59. package/dist/toml.d.ts +9 -0
  60. package/dist/toml.js +4 -0
  61. package/dist/utils.d.ts +15 -6
  62. package/dist/utils.js +1 -1
  63. package/dist/yaml.d.ts +14 -5
  64. package/package.json +57 -3
  65. package/dist/constants.d.ts +0 -42
  66. package/dist/ensure/ensure-dir-sync.d.ts +0 -14
  67. package/dist/ensure/ensure-dir.d.ts +0 -14
  68. package/dist/ensure/ensure-file-sync.d.ts +0 -15
  69. package/dist/ensure/ensure-file.d.ts +0 -27
  70. package/dist/ensure/ensure-link-sync.d.ts +0 -16
  71. package/dist/ensure/ensure-link.d.ts +0 -16
  72. package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
  73. package/dist/ensure/ensure-symlink.d.ts +0 -23
  74. package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
  75. package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
  76. package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
  77. package/dist/error/already-exists-error.d.ts +0 -39
  78. package/dist/error/directory-error.d.ts +0 -47
  79. package/dist/error/json-error.d.ts +0 -52
  80. package/dist/error/not-empty-error.d.ts +0 -51
  81. package/dist/error/not-found-error.d.ts +0 -44
  82. package/dist/error/permission-error.d.ts +0 -45
  83. package/dist/error/walk-error.d.ts +0 -51
  84. package/dist/find/collect-sync.d.ts +0 -31
  85. package/dist/find/collect.d.ts +0 -35
  86. package/dist/find/find-up-sync.d.ts +0 -42
  87. package/dist/find/find-up.d.ts +0 -46
  88. package/dist/find/utils/glob-to-regexp.d.ts +0 -2
  89. package/dist/find/utils/walk-include.d.ts +0 -2
  90. package/dist/find/walk-sync.d.ts +0 -34
  91. package/dist/find/walk.d.ts +0 -37
  92. package/dist/is-accessible-sync.d.ts +0 -3
  93. package/dist/is-accessible.d.ts +0 -29
  94. package/dist/move/index.d.ts +0 -68
  95. package/dist/move/types.d.ts +0 -36
  96. package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
  97. package/dist/move/utils/internal-move-file.d.ts +0 -3
  98. package/dist/move/utils/validate-same-directory.d.ts +0 -2
  99. package/dist/read/read-file-sync.d.ts +0 -37
  100. package/dist/read/read-file.d.ts +0 -41
  101. package/dist/read/read-json-sync.d.ts +0 -5
  102. package/dist/read/read-json.d.ts +0 -5
  103. package/dist/read/read-yaml-sync.d.ts +0 -4
  104. package/dist/read/read-yaml.d.ts +0 -4
  105. package/dist/remove/empty-dir-sync.d.ts +0 -23
  106. package/dist/remove/empty-dir.d.ts +0 -28
  107. package/dist/remove/remove-sync.d.ts +0 -27
  108. package/dist/remove/remove.d.ts +0 -32
  109. package/dist/sanitize.d.ts +0 -31
  110. package/dist/types.d.ts +0 -304
  111. package/dist/utils/assert-valid-file-contents.d.ts +0 -27
  112. package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
  113. package/dist/utils/parse-json.d.ts +0 -5
  114. package/dist/utils/strip-json-comments.d.ts +0 -44
  115. package/dist/write/utils/to-uint-8-array.d.ts +0 -2
  116. package/dist/write/write-file-sync.d.ts +0 -30
  117. package/dist/write/write-file.d.ts +0 -30
  118. package/dist/write/write-json-sync.d.ts +0 -29
  119. package/dist/write/write-json.d.ts +0 -30
  120. package/dist/write/write-yaml-sync.d.ts +0 -4
  121. package/dist/write/write-yaml.d.ts +0 -4
@@ -0,0 +1,145 @@
1
+ import { PathLike, Dirent } from 'node:fs';
2
+ import { GlobOptions as GlobOptions$1 } from 'tinyglobby';
3
+ import { DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, CreateNodeOptions, ToStringOptions } from './options';
4
+ declare const F_OK: number;
5
+ declare const R_OK: number;
6
+ declare const W_OK: number;
7
+ declare const X_OK: number;
8
+ declare const FIND_UP_STOP: symbol;
9
+ type ColorizeMethod = (value: string) => string;
10
+ type JsoncParseOptions = {
11
+ allowEmptyContent?: boolean;
12
+ allowTrailingComma?: boolean;
13
+ disallowComments?: boolean;
14
+ };
15
+ type JsoncFormattingOptions = {
16
+ eol?: string;
17
+ insertFinalNewline?: boolean;
18
+ insertSpaces?: boolean;
19
+ keepLines?: boolean;
20
+ tabSize?: number;
21
+ };
22
+ type IniEncodeOptions = {
23
+ align?: boolean;
24
+ bracketedArray?: boolean;
25
+ newline?: boolean;
26
+ platform?: string;
27
+ section?: string;
28
+ sort?: boolean;
29
+ whitespace?: boolean;
30
+ };
31
+ type Json5Replacer = (number | string)[] | ((this: unknown, key: string, value: unknown) => unknown) | null;
32
+ type GlobOptions = Omit<GlobOptions$1, "patterns">;
33
+ interface WalkOptions {
34
+ extensions?: string[];
35
+ followSymlinks?: boolean;
36
+ includeDirs?: boolean;
37
+ includeFiles?: boolean;
38
+ includeSymlinks?: boolean;
39
+ match?: (RegExp | string)[];
40
+ maxDepth?: number;
41
+ skip?: (RegExp | string)[];
42
+ }
43
+ interface WalkEntry extends Pick<Dirent, "isDirectory" | "isFile" | "isSymbolicLink" | "name"> {
44
+ path: string;
45
+ }
46
+ type CompressionType = "brotli" | "gzip" | "none";
47
+ type ReadFileEncoding = "ascii" | "base64" | "base64url" | "hex" | "latin1" | "ucs-2" | "ucs2" | "utf-8" | "utf-16le" | "utf8" | "utf16le";
48
+ type ReadFileOptions<C> = {
49
+ buffer?: boolean;
50
+ compression?: C;
51
+ encoding?: ReadFileEncoding;
52
+ flag?: number | string;
53
+ };
54
+ type ContentType<O = undefined> = O extends {
55
+ buffer: true;
56
+ } ? Buffer : string;
57
+ type JsonReviver = Parameters<(typeof JSON)["parse"]>["1"];
58
+ type CodeFrameLocation = {
59
+ column?: number;
60
+ line: number;
61
+ };
62
+ type CodeFrameOptions = {
63
+ color?: {
64
+ gutter?: ColorizeMethod;
65
+ marker?: ColorizeMethod;
66
+ message?: ColorizeMethod;
67
+ };
68
+ };
69
+ type ReadJsonOptions = CodeFrameOptions & {
70
+ beforeParse?: (source: string) => string;
71
+ };
72
+ type WriteFileOptions = {
73
+ chown?: {
74
+ gid: number;
75
+ uid: number;
76
+ };
77
+ encoding?: BufferEncoding | null;
78
+ flag?: string;
79
+ mode?: number;
80
+ overwrite?: boolean;
81
+ recursive?: boolean;
82
+ };
83
+ type JsonReplacer = (number | string)[] | ((this: unknown, key: string, value: unknown) => unknown) | null;
84
+ type YamlReplacer = JsonReplacer;
85
+ type WriteJsonOptions = WriteFileOptions & {
86
+ detectIndent?: boolean;
87
+ indent?: number | string;
88
+ replacer?: JsonReplacer;
89
+ stringify?: (data: unknown, replacer: JsonReplacer, space: number | string | undefined) => string;
90
+ };
91
+ type FindUpOptions = {
92
+ allowSymlinks?: boolean;
93
+ cwd?: URL | string;
94
+ stopAt?: URL | string;
95
+ type?: "directory" | "file";
96
+ };
97
+ type FindUpNameFnResult = PathLike | Promise<PathLike | typeof FIND_UP_STOP> | typeof FIND_UP_STOP | undefined;
98
+ type FindUpName = string[] | string | ((directory: string) => FindUpNameFnResult);
99
+ type FindUpNameSyncFnResult = PathLike | typeof FIND_UP_STOP | undefined;
100
+ type FindUpNameSync = string[] | string | ((directory: string) => FindUpNameSyncFnResult);
101
+ type RetryOptions = {
102
+ maxRetries?: number;
103
+ retryDelay?: number;
104
+ };
105
+ type ReadYamlOptions<C> = DocumentOptions & ParseOptions & ReadFileOptions<C> & SchemaOptions & ToJSOptions;
106
+ type YamlReviver = (key: unknown, value: unknown) => unknown;
107
+ type WriteYamlExtras = {
108
+ replacer?: JsonReplacer;
109
+ space?: number | string;
110
+ };
111
+ type WriteYamlOptions = CreateNodeOptions & DocumentOptions & ParseOptions & SchemaOptions & ToStringOptions & WriteFileOptions & WriteYamlExtras;
112
+ type ReadTomlOptions<C> = ReadFileOptions<C>;
113
+ type WriteTomlOptions = WriteFileOptions;
114
+ type ReadJsoncExtras = {
115
+ beforeParse?: (source: string) => string;
116
+ };
117
+ type ReadJsoncOptions<C> = CodeFrameOptions & JsoncParseOptions & ReadFileOptions<C> & ReadJsoncExtras;
118
+ type WriteJsoncOptions = WriteFileOptions & {
119
+ detectIndent?: boolean;
120
+ formattingOptions?: JsoncFormattingOptions;
121
+ indent?: number | string;
122
+ preserveComments?: boolean;
123
+ replacer?: JsonReplacer;
124
+ };
125
+ type Json5Reviver = (this: unknown, key: string, value: unknown) => unknown;
126
+ type ReadJson5Extras = {
127
+ beforeParse?: (source: string) => string;
128
+ };
129
+ type ReadJson5Options<C> = CodeFrameOptions & ReadFileOptions<C> & ReadJson5Extras;
130
+ type WriteJson5Options = WriteFileOptions & {
131
+ detectIndent?: boolean;
132
+ indent?: number | string;
133
+ quote?: string;
134
+ replacer?: Json5Replacer;
135
+ };
136
+ type ReadIniOptions<C> = ReadFileOptions<C> & {
137
+ bracketedArray?: boolean;
138
+ };
139
+ type IniLineEnding = "\n" | "\r\n";
140
+ type WriteIniExtras = {
141
+ eol?: IniLineEnding;
142
+ preserveStyle?: boolean;
143
+ };
144
+ type WriteIniOptions = IniEncodeOptions & WriteFileOptions & WriteIniExtras;
145
+ export { CodeFrameLocation as A, FIND_UP_STOP as B, CompressionType as C, F_OK as D, FindUpNameFnResult as E, FindUpName as F, GlobOptions as G, FindUpNameSyncFnResult as H, IniEncodeOptions as I, JsonReviver as J, R_OK as K, ReadFileEncoding as L, W_OK as M, ReadTomlOptions as R, WriteTomlOptions as W, X_OK as X, YamlReviver as Y, CodeFrameOptions as a, ReadJson5Options as b, Json5Reviver as c, WriteJson5Options as d, Json5Replacer as e, ReadJsoncOptions as f, WriteJsoncOptions as g, JsoncFormattingOptions as h, JsoncParseOptions as i, ReadIniOptions as j, WriteIniOptions as k, IniLineEnding as l, ReadYamlOptions as m, WriteYamlOptions as n, JsonReplacer as o, YamlReplacer as p, WalkOptions as q, FindUpOptions as r, FindUpNameSync as s, WalkEntry as t, ReadFileOptions as u, ContentType as v, ReadJsonOptions as w, RetryOptions as x, WriteFileOptions as y, WriteJsonOptions as z };
@@ -0,0 +1,65 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ readFile
22
+ } = __cjs_getBuiltinModule("node:fs/promises");
23
+ import { parse, stringify } from 'ini';
24
+ import { R_OK } from './F_OK-MldBaGxb.js';
25
+ import isAccessible from './isAccessible-DuVrTNFV.js';
26
+ import { d as detectIniStyle, m as mergeIniPreservingLines } from './ini-preserve-Dq_Q_Jgb.js';
27
+ import writeFile from './writeFile-B8HX0JIQ.js';
28
+
29
+ const writeIni = async (path, data, options = {}) => {
30
+ const { eol, preserveStyle = true, whitespace, ...rest } = options;
31
+ const { align, bracketedArray, newline, platform, section, sort, ...writeOptions } = rest;
32
+ let resolvedEol = eol;
33
+ let resolvedWhitespace = whitespace;
34
+ let existingText;
35
+ let oldData;
36
+ const accessible = preserveStyle ? await isAccessible(path, R_OK) : false;
37
+ if (accessible) {
38
+ try {
39
+ existingText = await readFile(path, "utf8");
40
+ oldData = parse(existingText, { bracketedArray: bracketedArray ?? true });
41
+ const detected = detectIniStyle(existingText);
42
+ resolvedEol ??= detected.eol;
43
+ resolvedWhitespace ??= detected.whitespace;
44
+ } catch (error) {
45
+ if (error.code !== "ENOENT") {
46
+ throw error;
47
+ }
48
+ }
49
+ }
50
+ const encodeOptions = { align, bracketedArray, newline, platform, section, sort, whitespace: resolvedWhitespace };
51
+ const freshStringify = (value, sectionName) => stringify(value, sectionName === void 0 ? encodeOptions : { ...encodeOptions, section: sectionName });
52
+ let output;
53
+ if (existingText !== void 0 && oldData) {
54
+ output = mergeIniPreservingLines(existingText, oldData, data, freshStringify, {
55
+ eol: resolvedEol ?? "\n"});
56
+ } else {
57
+ output = freshStringify(data, section);
58
+ if (resolvedEol === "\r\n") {
59
+ output = output.replaceAll(/\r?\n/g, "\r\n");
60
+ }
61
+ }
62
+ await writeFile(path, output, writeOptions);
63
+ };
64
+
65
+ export { writeIni as default };
@@ -0,0 +1,64 @@
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 { parse, stringify } from 'ini';
24
+ import { R_OK } from './F_OK-MldBaGxb.js';
25
+ import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
26
+ import { d as detectIniStyle, m as mergeIniPreservingLines } from './ini-preserve-Dq_Q_Jgb.js';
27
+ import writeFileSync from './writeFileSync-DB8vv8xR.js';
28
+
29
+ const writeIniSync = (path, data, options = {}) => {
30
+ const { eol, preserveStyle = true, whitespace, ...rest } = options;
31
+ const { align, bracketedArray, newline, platform, section, sort, ...writeOptions } = rest;
32
+ let resolvedEol = eol;
33
+ let resolvedWhitespace = whitespace;
34
+ let existingText;
35
+ let oldData;
36
+ if (preserveStyle && isAccessibleSync(path, R_OK)) {
37
+ try {
38
+ existingText = readFileSync(path, "utf8");
39
+ oldData = parse(existingText, { bracketedArray: bracketedArray ?? true });
40
+ const detected = detectIniStyle(existingText);
41
+ resolvedEol ??= detected.eol;
42
+ resolvedWhitespace ??= detected.whitespace;
43
+ } catch (error) {
44
+ if (error.code !== "ENOENT") {
45
+ throw error;
46
+ }
47
+ }
48
+ }
49
+ const encodeOptions = { align, bracketedArray, newline, platform, section, sort, whitespace: resolvedWhitespace };
50
+ const freshStringify = (value, sectionName) => stringify(value, sectionName === void 0 ? encodeOptions : { ...encodeOptions, section: sectionName });
51
+ let output;
52
+ if (existingText !== void 0 && oldData) {
53
+ output = mergeIniPreservingLines(existingText, oldData, data, freshStringify, {
54
+ eol: resolvedEol ?? "\n"});
55
+ } else {
56
+ output = freshStringify(data, section);
57
+ if (resolvedEol === "\r\n") {
58
+ output = output.replaceAll(/\r?\n/g, "\r\n");
59
+ }
60
+ }
61
+ writeFileSync(path, output, writeOptions);
62
+ };
63
+
64
+ export { writeIniSync as default };
@@ -0,0 +1,53 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ readFile
22
+ } = __cjs_getBuiltinModule("node:fs/promises");
23
+ import { d as detectIndent } from './index-CHM-in-V.js';
24
+ import JSON5 from 'json5';
25
+ import { R_OK } from './F_OK-MldBaGxb.js';
26
+ import isAccessible from './isAccessible-DuVrTNFV.js';
27
+ import writeFile from './writeFile-B8HX0JIQ.js';
28
+
29
+ const writeJson5 = async (path, data, options = {}) => {
30
+ const { detectIndent: detectIndent$1, indent: indentOption, quote, replacer, ...writeOptions } = { indent: " ", ...options };
31
+ let indent = indentOption;
32
+ let trailingNewline = "\n";
33
+ if (await isAccessible(path, R_OK)) {
34
+ try {
35
+ const file = await readFile(path, "utf8");
36
+ if (detectIndent$1) {
37
+ const { indent: detectedIndent } = detectIndent(file);
38
+ if (detectedIndent) {
39
+ indent = detectedIndent;
40
+ }
41
+ }
42
+ trailingNewline = file.endsWith("\n") ? "\n" : "";
43
+ } catch (error) {
44
+ if (error.code !== "ENOENT") {
45
+ throw error;
46
+ }
47
+ }
48
+ }
49
+ const output = JSON5.stringify(data, { quote, replacer, space: indent });
50
+ await writeFile(path, `${output}${trailingNewline}`, writeOptions);
51
+ };
52
+
53
+ export { writeJson5 as default };
@@ -0,0 +1,53 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ readFileSync
22
+ } = __cjs_getBuiltinModule("node:fs");
23
+ import { d as detectIndent } from './index-CHM-in-V.js';
24
+ import JSON5 from 'json5';
25
+ import { R_OK } from './F_OK-MldBaGxb.js';
26
+ import isAccessibleSync from './isAccessibleSync-DI8mM0fA.js';
27
+ import writeFileSync from './writeFileSync-DB8vv8xR.js';
28
+
29
+ const writeJson5Sync = (path, data, options = {}) => {
30
+ const { detectIndent: detectIndent$1, indent: indentOption, quote, replacer, ...writeOptions } = { indent: " ", ...options };
31
+ let indent = indentOption;
32
+ let trailingNewline = "\n";
33
+ if (isAccessibleSync(path, R_OK)) {
34
+ try {
35
+ const file = readFileSync(path, "utf8");
36
+ if (detectIndent$1) {
37
+ const { indent: detectedIndent } = detectIndent(file);
38
+ if (detectedIndent) {
39
+ indent = detectedIndent;
40
+ }
41
+ }
42
+ trailingNewline = file.endsWith("\n") ? "\n" : "";
43
+ } catch (error) {
44
+ if (error.code !== "ENOENT") {
45
+ throw error;
46
+ }
47
+ }
48
+ }
49
+ const output = JSON5.stringify(data, { quote, replacer, space: indent });
50
+ writeFileSync(path, `${output}${trailingNewline}`, writeOptions);
51
+ };
52
+
53
+ export { writeJson5Sync as default };
@@ -0,0 +1,60 @@
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 { b as buildJsoncOutput } from './jsonc-merge-C6jWcfWh.js';
27
+ import writeFile from './writeFile-B8HX0JIQ.js';
28
+
29
+ const readExisting = async (path, detectIndent$1, fallbackIndent) => {
30
+ let existingText;
31
+ let indent = fallbackIndent;
32
+ let trailingNewline = "\n";
33
+ const accessible = await isAccessible(path, R_OK);
34
+ if (!accessible) {
35
+ return { indent, trailingNewline };
36
+ }
37
+ try {
38
+ existingText = await readFile(path, "utf8");
39
+ if (detectIndent$1) {
40
+ const { indent: detectedIndent } = detectIndent(existingText);
41
+ if (detectedIndent) {
42
+ indent = detectedIndent;
43
+ }
44
+ }
45
+ trailingNewline = existingText.endsWith("\n") ? "\n" : "";
46
+ } catch (error) {
47
+ if (error.code !== "ENOENT") {
48
+ throw error;
49
+ }
50
+ }
51
+ return { existingText, indent, trailingNewline };
52
+ };
53
+ const writeJsonc = async (path, data, options = {}) => {
54
+ const { detectIndent, formattingOptions, indent: indentOption, preserveComments = true, replacer, ...writeOptions } = { indent: " ", ...options };
55
+ const { existingText, indent, trailingNewline } = await readExisting(path, detectIndent, indentOption);
56
+ const output = buildJsoncOutput(existingText, data, preserveComments, indent, trailingNewline, formattingOptions, replacer);
57
+ await writeFile(path, output, writeOptions);
58
+ };
59
+
60
+ export { writeJsonc as default };
@@ -0,0 +1,59 @@
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 { b as buildJsoncOutput } from './jsonc-merge-C6jWcfWh.js';
27
+ import writeFileSync from './writeFileSync-DB8vv8xR.js';
28
+
29
+ const readExistingSync = (path, detectIndent$1, fallbackIndent) => {
30
+ let existingText;
31
+ let indent = fallbackIndent;
32
+ let trailingNewline = "\n";
33
+ if (!isAccessibleSync(path, R_OK)) {
34
+ return { indent, trailingNewline };
35
+ }
36
+ try {
37
+ existingText = readFileSync(path, "utf8");
38
+ if (detectIndent$1) {
39
+ const { indent: detectedIndent } = detectIndent(existingText);
40
+ if (detectedIndent) {
41
+ indent = detectedIndent;
42
+ }
43
+ }
44
+ trailingNewline = existingText.endsWith("\n") ? "\n" : "";
45
+ } catch (error) {
46
+ if (error.code !== "ENOENT") {
47
+ throw error;
48
+ }
49
+ }
50
+ return { existingText, indent, trailingNewline };
51
+ };
52
+ const writeJsoncSync = (path, data, options = {}) => {
53
+ const { detectIndent, formattingOptions, indent: indentOption, preserveComments = true, replacer, ...writeOptions } = { indent: " ", ...options };
54
+ const { existingText, indent, trailingNewline } = readExistingSync(path, detectIndent, indentOption);
55
+ const output = buildJsoncOutput(existingText, data, preserveComments, indent, trailingNewline, formattingOptions, replacer);
56
+ writeFileSync(path, output, writeOptions);
57
+ };
58
+
59
+ export { writeJsoncSync as default };
@@ -0,0 +1,8 @@
1
+ import { stringify } from 'smol-toml';
2
+ import writeFile from './writeFile-B8HX0JIQ.js';
3
+
4
+ const writeToml = async (path, data, options) => {
5
+ await writeFile(path, stringify(data), options);
6
+ };
7
+
8
+ export { writeToml as default };
@@ -0,0 +1,8 @@
1
+ import { stringify } from 'smol-toml';
2
+ import writeFileSync from './writeFileSync-DB8vv8xR.js';
3
+
4
+ const writeTomlSync = (path, data, options) => {
5
+ writeFileSync(path, stringify(data), options);
6
+ };
7
+
8
+ export { writeTomlSync as default };