@holoscript/std 7.0.0 → 7.0.1

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 (132) hide show
  1. package/README.md +8 -0
  2. package/dist/chunk-DGUM43GV.js +11 -0
  3. package/dist/{chunk-PFX2JM4X.js → chunk-FAMOLKH3.js} +2 -1
  4. package/dist/{chunk-PFX2JM4X.js.map → chunk-FAMOLKH3.js.map} +1 -1
  5. package/dist/{chunk-DZHAVOCH.js → chunk-SOKH6FJ7.js} +31 -6
  6. package/dist/chunk-SOKH6FJ7.js.map +1 -0
  7. package/dist/collections.cjs +1 -0
  8. package/dist/collections.cjs.map +1 -1
  9. package/dist/collections.js +2 -2
  10. package/dist/fs/fs.d.ts.map +1 -1
  11. package/dist/fs/index.cjs +221 -8510
  12. package/dist/fs/index.cjs.map +1 -1
  13. package/dist/fs/index.js +832 -118
  14. package/dist/fs/index.js.map +1 -1
  15. package/dist/fs/sandbox.d.ts +49 -0
  16. package/dist/fs/sandbox.d.ts.map +1 -0
  17. package/dist/index.cjs +3494 -12672
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +0 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +17 -7
  22. package/dist/index.js.map +1 -1
  23. package/dist/math.cjs +18 -3
  24. package/dist/math.cjs.map +1 -1
  25. package/dist/math.js +2 -2
  26. package/dist/string.js +1 -1
  27. package/dist/time.js +1 -1
  28. package/dist/traits/EconomicPrimitives.js +1 -1
  29. package/dist/traits/EconomicTraits.js +1 -1
  30. package/dist/types.d.ts.map +1 -1
  31. package/package.json +19 -9
  32. package/dist/__tests__/EconomicPrimitives.test.d.ts +0 -2
  33. package/dist/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
  34. package/dist/__tests__/EconomicTraits.test.d.ts +0 -2
  35. package/dist/__tests__/EconomicTraits.test.d.ts.map +0 -1
  36. package/dist/__tests__/SimulationLabPrimitives.test.d.ts +0 -2
  37. package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +0 -1
  38. package/dist/__tests__/collections.test.d.ts +0 -2
  39. package/dist/__tests__/collections.test.d.ts.map +0 -1
  40. package/dist/__tests__/events.test.d.ts +0 -2
  41. package/dist/__tests__/events.test.d.ts.map +0 -1
  42. package/dist/__tests__/index.test.d.ts +0 -2
  43. package/dist/__tests__/index.test.d.ts.map +0 -1
  44. package/dist/__tests__/materials.test.d.ts +0 -2
  45. package/dist/__tests__/materials.test.d.ts.map +0 -1
  46. package/dist/__tests__/math.test.d.ts +0 -2
  47. package/dist/__tests__/math.test.d.ts.map +0 -1
  48. package/dist/__tests__/physics.test.d.ts +0 -2
  49. package/dist/__tests__/physics.test.d.ts.map +0 -1
  50. package/dist/__tests__/spatial.test.d.ts +0 -2
  51. package/dist/__tests__/spatial.test.d.ts.map +0 -1
  52. package/dist/__tests__/standard-library-fundamentals.test.d.ts +0 -2
  53. package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +0 -1
  54. package/dist/__tests__/string-and-time-utilities.test.d.ts +0 -2
  55. package/dist/__tests__/string-and-time-utilities.test.d.ts.map +0 -1
  56. package/dist/__tests__/string-decoupled.test.d.ts +0 -2
  57. package/dist/__tests__/string-decoupled.test.d.ts.map +0 -1
  58. package/dist/__tests__/string.test.d.ts +0 -2
  59. package/dist/__tests__/string.test.d.ts.map +0 -1
  60. package/dist/__tests__/time.test.d.ts +0 -2
  61. package/dist/__tests__/time.test.d.ts.map +0 -1
  62. package/dist/chunk-DZHAVOCH.js.map +0 -1
  63. package/dist/chunk-PR4QN5HX.js +0 -43
  64. package/dist/chunk-XBA4ARST.js +0 -9313
  65. package/dist/chunk-XBA4ARST.js.map +0 -1
  66. package/dist/fs/__tests__/file-watch-system.test.d.ts +0 -2
  67. package/dist/fs/__tests__/file-watch-system.test.d.ts.map +0 -1
  68. package/dist/fs/__tests__/path-utilities.test.d.ts +0 -2
  69. package/dist/fs/__tests__/path-utilities.test.d.ts.map +0 -1
  70. package/dist/fs/__tests__/path.test.d.ts +0 -2
  71. package/dist/fs/__tests__/path.test.d.ts.map +0 -1
  72. package/dist/string.basic.test.d.ts +0 -5
  73. package/dist/string.basic.test.d.ts.map +0 -1
  74. package/dist/string.test.d.ts +0 -5
  75. package/dist/string.test.d.ts.map +0 -1
  76. package/dist/traits/__tests__/ARTraits.test.d.ts +0 -2
  77. package/dist/traits/__tests__/ARTraits.test.d.ts.map +0 -1
  78. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +0 -2
  79. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
  80. package/dist/traits/__tests__/EconomicTraits.test.d.ts +0 -2
  81. package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +0 -1
  82. package/error-utf8.log +0 -6
  83. package/error.log +0 -0
  84. package/src/__tests__/EconomicPrimitives.test.ts +0 -690
  85. package/src/__tests__/EconomicTraits.test.ts +0 -425
  86. package/src/__tests__/SimulationLabPrimitives.test.ts +0 -415
  87. package/src/__tests__/collections.test.ts +0 -182
  88. package/src/__tests__/events.test.ts +0 -135
  89. package/src/__tests__/index.test.ts +0 -14
  90. package/src/__tests__/materials.test.ts +0 -84
  91. package/src/__tests__/math.test.ts +0 -246
  92. package/src/__tests__/physics.test.ts +0 -83
  93. package/src/__tests__/spatial.test.ts +0 -333
  94. package/src/__tests__/standard-library-fundamentals.test.ts +0 -1318
  95. package/src/__tests__/string-and-time-utilities.test.ts +0 -1070
  96. package/src/__tests__/string-decoupled.test.ts +0 -13
  97. package/src/__tests__/string.test.ts +0 -164
  98. package/src/__tests__/time.test.ts +0 -110
  99. package/src/collections.ts +0 -850
  100. package/src/events.ts +0 -88
  101. package/src/fs/__tests__/file-watch-system.test.ts +0 -675
  102. package/src/fs/__tests__/path-utilities.test.ts +0 -375
  103. package/src/fs/__tests__/path.test.ts +0 -287
  104. package/src/fs/fs.ts +0 -692
  105. package/src/fs/index.ts +0 -194
  106. package/src/fs/path.ts +0 -310
  107. package/src/fs/watch.ts +0 -413
  108. package/src/index.ts +0 -476
  109. package/src/materials.ts +0 -109
  110. package/src/math.ts +0 -674
  111. package/src/physics.ts +0 -141
  112. package/src/spatial.ts +0 -320
  113. package/src/string.basic.test.ts +0 -14
  114. package/src/string.test.ts +0 -335
  115. package/src/string.ts +0 -531
  116. package/src/time.ts +0 -621
  117. package/src/traits/ARTraits.ts +0 -103
  118. package/src/traits/EconomicPrimitives.ts +0 -755
  119. package/src/traits/EconomicTraits.ts +0 -552
  120. package/src/traits/IoTTraits.ts +0 -102
  121. package/src/traits/SimulationLabPrimitives.ts +0 -650
  122. package/src/traits/SimulationLabTraits.ts +0 -191
  123. package/src/traits/VRRTraits.ts +0 -326
  124. package/src/traits/__tests__/ARTraits.test.ts +0 -8
  125. package/src/traits/__tests__/EconomicPrimitives.test.ts +0 -14
  126. package/src/traits/__tests__/EconomicTraits.test.ts +0 -16
  127. package/src/types.ts +0 -418
  128. package/std_error.log +0 -5
  129. package/tsconfig.json +0 -18
  130. package/tsup.config.ts +0 -20
  131. package/vitest.config.ts +0 -10
  132. /package/dist/{chunk-PR4QN5HX.js.map → chunk-DGUM43GV.js.map} +0 -0
package/dist/fs/index.js CHANGED
@@ -1,105 +1,819 @@
1
1
  import {
2
- FileWatcher,
3
- PathBuilder,
4
- addSuffix,
5
- appendLine,
6
- appendLineSync,
7
- appendText,
8
- appendTextSync,
9
- basename,
10
- changeExtension,
11
- chdir,
12
- commonBase,
13
- copy,
14
- copySync,
15
- createTempDir,
16
- createTempFile,
17
- cwd,
18
- delimiter,
19
- dirSize,
20
- dirname,
21
- ensureDir,
22
- ensureDirSync,
23
- ensureFile,
24
- ensureFileSync,
25
- exists,
26
- existsSync,
27
- expandHome,
28
- extname,
29
- fileSize,
30
- fileSizeSync,
31
- format,
32
- formatSize,
33
- glob,
34
- globSync,
35
- hasExtension,
36
- homeDir,
37
- isAbsolute,
38
- isChildOf,
39
- isDirectory,
40
- isDirectorySync,
41
- isFile,
42
- isFileSync,
43
- isLinux,
44
- isMacOS,
45
- isWindows,
46
- join,
47
- listDirs,
48
- listDirsSync,
49
- listFiles,
50
- listFilesSync,
51
- matchesPattern,
52
- mkdir,
53
- mkdirSync,
54
- move,
55
- moveSync,
56
- normalize,
57
- parent,
58
- parse,
59
- path,
60
- readBytes,
61
- readBytesSync,
62
- readDir,
63
- readDirSync,
64
- readJson,
65
- readJsonSync,
66
- readLines,
67
- readLinesSync,
68
- readText,
69
- readTextSync,
70
- relative,
71
- remove,
72
- removeExtension,
73
- removeSync,
74
- resolve,
75
- sanitize,
76
- segments,
77
- sep,
78
- stat,
79
- statSync,
80
- tempDir,
81
- toPosix,
82
- toWindows,
83
- walk,
84
- watch,
85
- watchBatched,
86
- watchCallback,
87
- watchDebounced,
88
- watchDirs,
89
- watchEvents,
90
- watchFile,
91
- watchFileTypes,
92
- watchFiles,
93
- watchFiltered,
94
- watchOnce,
95
- writeBytes,
96
- writeBytesSync,
97
- writeJson,
98
- writeJsonSync,
99
- writeText,
100
- writeTextSync
101
- } from "../chunk-XBA4ARST.js";
102
- import "../chunk-PR4QN5HX.js";
2
+ __require
3
+ } from "../chunk-DGUM43GV.js";
4
+
5
+ // src/fs/fs.ts
6
+ import * as fs from "fs";
7
+ import * as fsPromises from "fs/promises";
8
+ import * as nodePath from "path";
9
+ import { glob as globAsync } from "glob";
10
+
11
+ // src/fs/sandbox.ts
12
+ import { resolve, isAbsolute, relative } from "path";
13
+ var SANDBOX_ROOT_ENV = "HOLOSCRIPT_FS_SANDBOX_ROOT";
14
+ var PathBoundaryError = class extends Error {
15
+ code = "ERR_PATH_BOUNDARY";
16
+ attemptedPath;
17
+ sandboxRoot;
18
+ constructor(attemptedPath, sandboxRoot) {
19
+ super(
20
+ `[@holoscript/std/fs] path "${attemptedPath}" resolves outside sandbox root "${sandboxRoot}"`
21
+ );
22
+ this.name = "PathBoundaryError";
23
+ this.attemptedPath = attemptedPath;
24
+ this.sandboxRoot = sandboxRoot;
25
+ }
26
+ };
27
+ function getSandboxRoot() {
28
+ const raw = process.env[SANDBOX_ROOT_ENV];
29
+ if (!raw || raw.trim() === "") return null;
30
+ return resolve(raw.trim());
31
+ }
32
+ function enforcePathBoundary(path2) {
33
+ const root = getSandboxRoot();
34
+ if (root === null) return path2;
35
+ if (typeof path2 !== "string") {
36
+ throw new TypeError(`[@holoscript/std/fs] path must be a string, got ${typeof path2}`);
37
+ }
38
+ const absolute = isAbsolute(path2) ? resolve(path2) : resolve(root, path2);
39
+ const rel = relative(root, absolute);
40
+ if (rel === "" || !rel.startsWith("..") && !isAbsolute(rel)) {
41
+ return absolute;
42
+ }
43
+ throw new PathBoundaryError(path2, root);
44
+ }
45
+
46
+ // src/fs/fs.ts
47
+ async function readText(path2, encoding = "utf-8") {
48
+ path2 = enforcePathBoundary(path2);
49
+ return fsPromises.readFile(path2, { encoding });
50
+ }
51
+ function readTextSync(path2, encoding = "utf-8") {
52
+ path2 = enforcePathBoundary(path2);
53
+ return fs.readFileSync(path2, { encoding });
54
+ }
55
+ async function readBytes(path2) {
56
+ path2 = enforcePathBoundary(path2);
57
+ return fsPromises.readFile(path2);
58
+ }
59
+ function readBytesSync(path2) {
60
+ path2 = enforcePathBoundary(path2);
61
+ return fs.readFileSync(path2);
62
+ }
63
+ async function readJson(path2) {
64
+ const text = await readText(path2);
65
+ return JSON.parse(text);
66
+ }
67
+ function readJsonSync(path2) {
68
+ const text = readTextSync(path2);
69
+ return JSON.parse(text);
70
+ }
71
+ async function readLines(path2, encoding = "utf-8") {
72
+ const text = await readText(path2, encoding);
73
+ return text.split(/\r?\n/);
74
+ }
75
+ function readLinesSync(path2, encoding = "utf-8") {
76
+ const text = readTextSync(path2, encoding);
77
+ return text.split(/\r?\n/);
78
+ }
79
+ async function writeText(path2, content, options = {}) {
80
+ path2 = enforcePathBoundary(path2);
81
+ const { encoding = "utf-8", mode, flag = options.append ? "a" : "w" } = options;
82
+ await ensureDir(nodePath.dirname(path2));
83
+ await fsPromises.writeFile(path2, content, { encoding, mode, flag });
84
+ }
85
+ function writeTextSync(path2, content, options = {}) {
86
+ path2 = enforcePathBoundary(path2);
87
+ const { encoding = "utf-8", mode, flag = options.append ? "a" : "w" } = options;
88
+ ensureDirSync(nodePath.dirname(path2));
89
+ fs.writeFileSync(path2, content, { encoding, mode, flag });
90
+ }
91
+ async function writeBytes(path2, content, options = {}) {
92
+ path2 = enforcePathBoundary(path2);
93
+ const { mode, flag = options.append ? "a" : "w" } = options;
94
+ await ensureDir(nodePath.dirname(path2));
95
+ await fsPromises.writeFile(path2, content, { mode, flag });
96
+ }
97
+ function writeBytesSync(path2, content, options = {}) {
98
+ path2 = enforcePathBoundary(path2);
99
+ const { mode, flag = options.append ? "a" : "w" } = options;
100
+ ensureDirSync(nodePath.dirname(path2));
101
+ fs.writeFileSync(path2, content, { mode, flag });
102
+ }
103
+ async function writeJson(path2, data, options = {}) {
104
+ const { pretty = true, ...writeOpts } = options;
105
+ const text = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
106
+ await writeText(path2, text, writeOpts);
107
+ }
108
+ function writeJsonSync(path2, data, options = {}) {
109
+ const { pretty = true, ...writeOpts } = options;
110
+ const text = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
111
+ writeTextSync(path2, text, writeOpts);
112
+ }
113
+ async function appendText(path2, content, encoding = "utf-8") {
114
+ await writeText(path2, content, { encoding, append: true });
115
+ }
116
+ function appendTextSync(path2, content, encoding = "utf-8") {
117
+ writeTextSync(path2, content, { encoding, append: true });
118
+ }
119
+ async function appendLine(path2, line, encoding = "utf-8") {
120
+ await appendText(path2, line + "\n", encoding);
121
+ }
122
+ function appendLineSync(path2, line, encoding = "utf-8") {
123
+ appendTextSync(path2, line + "\n", encoding);
124
+ }
125
+ async function exists(path2) {
126
+ path2 = enforcePathBoundary(path2);
127
+ try {
128
+ await fsPromises.access(path2);
129
+ return true;
130
+ } catch {
131
+ return false;
132
+ }
133
+ }
134
+ function existsSync2(path2) {
135
+ path2 = enforcePathBoundary(path2);
136
+ return fs.existsSync(path2);
137
+ }
138
+ async function isFile(path2) {
139
+ path2 = enforcePathBoundary(path2);
140
+ try {
141
+ const stats = await fsPromises.stat(path2);
142
+ return stats.isFile();
143
+ } catch {
144
+ return false;
145
+ }
146
+ }
147
+ function isFileSync(path2) {
148
+ path2 = enforcePathBoundary(path2);
149
+ try {
150
+ return fs.statSync(path2).isFile();
151
+ } catch {
152
+ return false;
153
+ }
154
+ }
155
+ async function isDirectory(path2) {
156
+ path2 = enforcePathBoundary(path2);
157
+ try {
158
+ const stats = await fsPromises.stat(path2);
159
+ return stats.isDirectory();
160
+ } catch {
161
+ return false;
162
+ }
163
+ }
164
+ function isDirectorySync(path2) {
165
+ path2 = enforcePathBoundary(path2);
166
+ try {
167
+ return fs.statSync(path2).isDirectory();
168
+ } catch {
169
+ return false;
170
+ }
171
+ }
172
+ async function stat2(path2) {
173
+ path2 = enforcePathBoundary(path2);
174
+ const stats = await fsPromises.stat(path2);
175
+ return {
176
+ size: stats.size,
177
+ isFile: stats.isFile(),
178
+ isDirectory: stats.isDirectory(),
179
+ isSymlink: stats.isSymbolicLink(),
180
+ createdAt: stats.birthtime,
181
+ modifiedAt: stats.mtime,
182
+ accessedAt: stats.atime,
183
+ mode: stats.mode
184
+ };
185
+ }
186
+ function statSync2(path2) {
187
+ path2 = enforcePathBoundary(path2);
188
+ const stats = fs.statSync(path2);
189
+ return {
190
+ size: stats.size,
191
+ isFile: stats.isFile(),
192
+ isDirectory: stats.isDirectory(),
193
+ isSymlink: stats.isSymbolicLink(),
194
+ createdAt: stats.birthtime,
195
+ modifiedAt: stats.mtime,
196
+ accessedAt: stats.atime,
197
+ mode: stats.mode
198
+ };
199
+ }
200
+ async function mkdir2(path2, recursive = true) {
201
+ path2 = enforcePathBoundary(path2);
202
+ await fsPromises.mkdir(path2, { recursive });
203
+ }
204
+ function mkdirSync2(path2, recursive = true) {
205
+ path2 = enforcePathBoundary(path2);
206
+ fs.mkdirSync(path2, { recursive });
207
+ }
208
+ async function ensureDir(path2) {
209
+ if (!await exists(path2)) {
210
+ await mkdir2(path2, true);
211
+ }
212
+ }
213
+ function ensureDirSync(path2) {
214
+ if (!existsSync2(path2)) {
215
+ mkdirSync2(path2, true);
216
+ }
217
+ }
218
+ async function ensureFile(path2) {
219
+ path2 = enforcePathBoundary(path2);
220
+ if (!await exists(path2)) {
221
+ await ensureDir(nodePath.dirname(path2));
222
+ await writeText(path2, "");
223
+ }
224
+ }
225
+ function ensureFileSync(path2) {
226
+ path2 = enforcePathBoundary(path2);
227
+ if (!existsSync2(path2)) {
228
+ ensureDirSync(nodePath.dirname(path2));
229
+ writeTextSync(path2, "");
230
+ }
231
+ }
232
+ async function remove(path2, recursive = true) {
233
+ path2 = enforcePathBoundary(path2);
234
+ await fsPromises.rm(path2, { recursive, force: true });
235
+ }
236
+ function removeSync(path2, recursive = true) {
237
+ path2 = enforcePathBoundary(path2);
238
+ fs.rmSync(path2, { recursive, force: true });
239
+ }
240
+ async function copy(src, dest, options = {}) {
241
+ src = enforcePathBoundary(src);
242
+ dest = enforcePathBoundary(dest);
243
+ const { overwrite = true, recursive = true, filter } = options;
244
+ if (filter && !filter(src)) return;
245
+ const srcStat = await stat2(src);
246
+ if (srcStat.isDirectory) {
247
+ await ensureDir(dest);
248
+ if (recursive) {
249
+ const entries = await readDir(src);
250
+ for (const entry of entries) {
251
+ await copy(entry.path, nodePath.join(dest, entry.name), options);
252
+ }
253
+ }
254
+ } else {
255
+ if (!overwrite && await exists(dest)) {
256
+ return;
257
+ }
258
+ await ensureDir(nodePath.dirname(dest));
259
+ await fsPromises.copyFile(src, dest);
260
+ }
261
+ }
262
+ function copySync(src, dest, options = {}) {
263
+ src = enforcePathBoundary(src);
264
+ dest = enforcePathBoundary(dest);
265
+ const { overwrite = true, recursive = true, filter } = options;
266
+ if (filter && !filter(src)) return;
267
+ const srcStat = statSync2(src);
268
+ if (srcStat.isDirectory) {
269
+ ensureDirSync(dest);
270
+ if (recursive) {
271
+ const entries = readDirSync(src);
272
+ for (const entry of entries) {
273
+ copySync(entry.path, nodePath.join(dest, entry.name), options);
274
+ }
275
+ }
276
+ } else {
277
+ if (!overwrite && existsSync2(dest)) {
278
+ return;
279
+ }
280
+ ensureDirSync(nodePath.dirname(dest));
281
+ fs.copyFileSync(src, dest);
282
+ }
283
+ }
284
+ async function move(src, dest, overwrite = true) {
285
+ src = enforcePathBoundary(src);
286
+ dest = enforcePathBoundary(dest);
287
+ if (!overwrite && await exists(dest)) {
288
+ throw new Error(`Destination already exists: ${dest}`);
289
+ }
290
+ await ensureDir(nodePath.dirname(dest));
291
+ await fsPromises.rename(src, dest);
292
+ }
293
+ function moveSync(src, dest, overwrite = true) {
294
+ src = enforcePathBoundary(src);
295
+ dest = enforcePathBoundary(dest);
296
+ if (!overwrite && existsSync2(dest)) {
297
+ throw new Error(`Destination already exists: ${dest}`);
298
+ }
299
+ ensureDirSync(nodePath.dirname(dest));
300
+ fs.renameSync(src, dest);
301
+ }
302
+ async function readDir(path2) {
303
+ path2 = enforcePathBoundary(path2);
304
+ const entries = await fsPromises.readdir(path2, { withFileTypes: true });
305
+ return entries.map((entry) => ({
306
+ name: entry.name,
307
+ path: nodePath.join(path2, entry.name),
308
+ isFile: entry.isFile(),
309
+ isDirectory: entry.isDirectory(),
310
+ isSymlink: entry.isSymbolicLink()
311
+ }));
312
+ }
313
+ function readDirSync(path2) {
314
+ path2 = enforcePathBoundary(path2);
315
+ const entries = fs.readdirSync(path2, { withFileTypes: true });
316
+ return entries.map((entry) => ({
317
+ name: entry.name,
318
+ path: nodePath.join(path2, entry.name),
319
+ isFile: entry.isFile(),
320
+ isDirectory: entry.isDirectory(),
321
+ isSymlink: entry.isSymbolicLink()
322
+ }));
323
+ }
324
+ async function listFiles(path2) {
325
+ const entries = await readDir(path2);
326
+ return entries.filter((e) => e.isFile).map((e) => e.name);
327
+ }
328
+ function listFilesSync(path2) {
329
+ const entries = readDirSync(path2);
330
+ return entries.filter((e) => e.isFile).map((e) => e.name);
331
+ }
332
+ async function listDirs(path2) {
333
+ const entries = await readDir(path2);
334
+ return entries.filter((e) => e.isDirectory).map((e) => e.name);
335
+ }
336
+ function listDirsSync(path2) {
337
+ const entries = readDirSync(path2);
338
+ return entries.filter((e) => e.isDirectory).map((e) => e.name);
339
+ }
340
+ async function* walk(path2, options = {}) {
341
+ const { depth = Infinity, followSymlinks = false } = options;
342
+ async function* walkDir(dir, currentDepth) {
343
+ if (currentDepth > depth) return;
344
+ const entries = await readDir(dir);
345
+ for (const entry of entries) {
346
+ yield entry;
347
+ if (entry.isDirectory || followSymlinks && entry.isSymlink) {
348
+ yield* walkDir(entry.path, currentDepth + 1);
349
+ }
350
+ }
351
+ }
352
+ yield* walkDir(path2, 0);
353
+ }
354
+ async function glob(pattern, options = {}) {
355
+ const { cwd: cwd2 = process.cwd(), ignore = [] } = options;
356
+ return globAsync(pattern, { cwd: cwd2, ignore, absolute: true });
357
+ }
358
+ function globSync(pattern, options = {}) {
359
+ const { cwd: cwd2 = process.cwd(), ignore = [] } = options;
360
+ return globAsync.sync(pattern, { cwd: cwd2, ignore, absolute: true });
361
+ }
362
+ function tempDir() {
363
+ return __require("os").tmpdir();
364
+ }
365
+ async function createTempFile(prefix = "tmp-", suffix = "", dir) {
366
+ const tempDirectory = dir || tempDir();
367
+ const filename = `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}${suffix}`;
368
+ const filePath = nodePath.join(tempDirectory, filename);
369
+ await writeText(filePath, "");
370
+ return {
371
+ path: filePath,
372
+ cleanup: async () => {
373
+ await remove(filePath);
374
+ }
375
+ };
376
+ }
377
+ async function createTempDir(prefix = "tmp-") {
378
+ const tempDirectory = tempDir();
379
+ const dirname4 = `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`;
380
+ const dirPath = nodePath.join(tempDirectory, dirname4);
381
+ await mkdir2(dirPath);
382
+ return {
383
+ path: dirPath,
384
+ cleanup: async () => {
385
+ await remove(dirPath, true);
386
+ }
387
+ };
388
+ }
389
+ async function fileSize(path2) {
390
+ const stats = await stat2(path2);
391
+ return stats.size;
392
+ }
393
+ function fileSizeSync(path2) {
394
+ const stats = statSync2(path2);
395
+ return stats.size;
396
+ }
397
+ async function dirSize(path2) {
398
+ let total = 0;
399
+ for await (const entry of walk(path2)) {
400
+ if (entry.isFile) {
401
+ total += await fileSize(entry.path);
402
+ }
403
+ }
404
+ return total;
405
+ }
406
+ function formatSize(bytes, decimals = 2) {
407
+ if (bytes === 0) return "0 B";
408
+ const k = 1024;
409
+ const sizes = ["B", "KB", "MB", "GB", "TB", "PB"];
410
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
411
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + " " + sizes[i];
412
+ }
413
+
414
+ // src/fs/path.ts
415
+ import * as nodePath2 from "path";
416
+ var sep2 = nodePath2.sep;
417
+ var delimiter2 = nodePath2.delimiter;
418
+ function join3(...paths) {
419
+ return nodePath2.join(...paths);
420
+ }
421
+ function resolve3(...paths) {
422
+ return nodePath2.resolve(...paths);
423
+ }
424
+ function relative3(from, to) {
425
+ return nodePath2.relative(from, to);
426
+ }
427
+ function normalize2(p) {
428
+ return nodePath2.normalize(p);
429
+ }
430
+ function isAbsolute3(p) {
431
+ return nodePath2.isAbsolute(p);
432
+ }
433
+ function dirname3(p) {
434
+ return nodePath2.dirname(p);
435
+ }
436
+ function basename2(p, ext) {
437
+ return nodePath2.basename(p, ext);
438
+ }
439
+ function extname2(p) {
440
+ return nodePath2.extname(p);
441
+ }
442
+ function parse2(p) {
443
+ return nodePath2.parse(p);
444
+ }
445
+ function format2(pathObject) {
446
+ return nodePath2.format(pathObject);
447
+ }
448
+ function toPosix(p) {
449
+ return p.replace(/\\/g, "/");
450
+ }
451
+ function toWindows(p) {
452
+ return p.replace(/\//g, "\\");
453
+ }
454
+ function parent(p) {
455
+ return dirname3(p);
456
+ }
457
+ function segments(p) {
458
+ const normalized = normalize2(p);
459
+ return normalized.split(sep2).filter((s) => s.length > 0);
460
+ }
461
+ function hasExtension(p, ext) {
462
+ const pathExt = extname2(p).toLowerCase();
463
+ const checkExt = ext.startsWith(".") ? ext.toLowerCase() : `.${ext.toLowerCase()}`;
464
+ return pathExt === checkExt;
465
+ }
466
+ function changeExtension(p, newExt) {
467
+ const parsed = parse2(p);
468
+ const ext = newExt.startsWith(".") ? newExt : `.${newExt}`;
469
+ return join3(parsed.dir, `${parsed.name}${ext}`);
470
+ }
471
+ function removeExtension(p) {
472
+ const parsed = parse2(p);
473
+ return join3(parsed.dir, parsed.name);
474
+ }
475
+ function addSuffix(p, suffix) {
476
+ const parsed = parse2(p);
477
+ return join3(parsed.dir, `${parsed.name}${suffix}${parsed.ext}`);
478
+ }
479
+ function isChildOf(child, parent2) {
480
+ const childResolved = resolve3(child);
481
+ const parentResolved = resolve3(parent2);
482
+ const rel = relative3(parentResolved, childResolved);
483
+ return !rel.startsWith("..") && !isAbsolute3(rel);
484
+ }
485
+ function commonBase(...paths) {
486
+ if (paths.length === 0) return "";
487
+ if (paths.length === 1) return dirname3(paths[0]);
488
+ const resolvedPaths = paths.map((p) => resolve3(p));
489
+ const segmentsList = resolvedPaths.map((p) => segments(p));
490
+ const minLength = Math.min(...segmentsList.map((s) => s.length));
491
+ const common = [];
492
+ for (let i = 0; i < minLength; i++) {
493
+ const segment = segmentsList[0][i];
494
+ if (segmentsList.every((s) => s[i] === segment)) {
495
+ common.push(segment);
496
+ } else {
497
+ break;
498
+ }
499
+ }
500
+ if (common.length === 0) return "";
501
+ if (resolvedPaths[0].startsWith("/")) {
502
+ return "/" + common.join("/");
503
+ }
504
+ return common.join(sep2);
505
+ }
506
+ function expandHome(p) {
507
+ if (p.startsWith("~")) {
508
+ const home = process.env.HOME || process.env.USERPROFILE || "";
509
+ return join3(home, p.slice(1));
510
+ }
511
+ return p;
512
+ }
513
+ function sanitize(filename) {
514
+ return filename.replace(/[<>:"/\\|?*\x00-\x1F]/g, "_").replace(/^\.+/, "_").replace(/\.+$/, "_").slice(0, 255);
515
+ }
516
+ function matchesPattern(filename, pattern) {
517
+ const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
518
+ return new RegExp(`^${regexPattern}$`).test(filename);
519
+ }
520
+ var PathBuilder = class _PathBuilder {
521
+ path;
522
+ constructor(base = process.cwd()) {
523
+ this.path = resolve3(base);
524
+ }
525
+ static from(base) {
526
+ return new _PathBuilder(base);
527
+ }
528
+ static cwd() {
529
+ return new _PathBuilder(process.cwd());
530
+ }
531
+ join(...segments2) {
532
+ this.path = join3(this.path, ...segments2);
533
+ return this;
534
+ }
535
+ parent() {
536
+ this.path = dirname3(this.path);
537
+ return this;
538
+ }
539
+ sibling(name) {
540
+ this.path = join3(dirname3(this.path), name);
541
+ return this;
542
+ }
543
+ withExtension(ext) {
544
+ this.path = changeExtension(this.path, ext);
545
+ return this;
546
+ }
547
+ withSuffix(suffix) {
548
+ this.path = addSuffix(this.path, suffix);
549
+ return this;
550
+ }
551
+ normalize() {
552
+ this.path = normalize2(this.path);
553
+ return this;
554
+ }
555
+ toString() {
556
+ return this.path;
557
+ }
558
+ get value() {
559
+ return this.path;
560
+ }
561
+ get dirname() {
562
+ return dirname3(this.path);
563
+ }
564
+ get basename() {
565
+ return basename2(this.path);
566
+ }
567
+ get extname() {
568
+ return extname2(this.path);
569
+ }
570
+ get name() {
571
+ return parse2(this.path).name;
572
+ }
573
+ };
574
+ function path(base) {
575
+ return new PathBuilder(base);
576
+ }
577
+
578
+ // src/fs/watch.ts
579
+ import chokidar from "chokidar";
580
+ import { EventEmitter } from "events";
581
+ var FileWatcher = class extends EventEmitter {
582
+ watcher = null;
583
+ paths;
584
+ options;
585
+ debounceTimers = /* @__PURE__ */ new Map();
586
+ constructor(paths, options = {}) {
587
+ super();
588
+ this.paths = Array.isArray(paths) ? paths : [paths];
589
+ this.options = {
590
+ ignored: options.ignored || ["**/node_modules/**", "**/.git/**"],
591
+ usePolling: options.usePolling || false,
592
+ interval: options.interval || 100,
593
+ emitInitial: options.emitInitial ?? true,
594
+ followSymlinks: options.followSymlinks ?? true,
595
+ depth: options.depth,
596
+ persistent: options.persistent ?? true,
597
+ debounce: options.debounce || 0
598
+ };
599
+ }
600
+ /**
601
+ * Start watching
602
+ */
603
+ start() {
604
+ if (this.watcher) {
605
+ return this;
606
+ }
607
+ const chokidarOpts = {
608
+ ignored: this.options.ignored,
609
+ persistent: this.options.persistent,
610
+ followSymlinks: this.options.followSymlinks,
611
+ depth: this.options.depth,
612
+ usePolling: this.options.usePolling,
613
+ interval: this.options.interval,
614
+ ignoreInitial: !this.options.emitInitial
615
+ };
616
+ this.watcher = chokidar.watch(this.paths, chokidarOpts);
617
+ this.watcher.on("add", (path2, stats) => this.handleEvent("add", path2, stats));
618
+ this.watcher.on("change", (path2, stats) => this.handleEvent("change", path2, stats));
619
+ this.watcher.on("unlink", (path2) => this.handleEvent("unlink", path2));
620
+ this.watcher.on("addDir", (path2, stats) => this.handleEvent("addDir", path2, stats));
621
+ this.watcher.on("unlinkDir", (path2) => this.handleEvent("unlinkDir", path2));
622
+ this.watcher.on("error", (error) => this.emit("error", error));
623
+ this.watcher.on("ready", () => this.emit("ready"));
624
+ return this;
625
+ }
626
+ /**
627
+ * Stop watching
628
+ */
629
+ async stop() {
630
+ if (this.watcher) {
631
+ await this.watcher.close();
632
+ this.watcher = null;
633
+ }
634
+ for (const timer of this.debounceTimers.values()) {
635
+ clearTimeout(timer);
636
+ }
637
+ this.debounceTimers.clear();
638
+ }
639
+ /**
640
+ * Add paths to watch
641
+ */
642
+ add(paths) {
643
+ const pathsArray = Array.isArray(paths) ? paths : [paths];
644
+ this.paths.push(...pathsArray);
645
+ this.watcher?.add(pathsArray);
646
+ return this;
647
+ }
648
+ /**
649
+ * Remove paths from watch
650
+ */
651
+ unwatch(paths) {
652
+ const pathsArray = Array.isArray(paths) ? paths : [paths];
653
+ this.paths = this.paths.filter((p) => !pathsArray.includes(p));
654
+ this.watcher?.unwatch(pathsArray);
655
+ return this;
656
+ }
657
+ /**
658
+ * Get watched paths
659
+ */
660
+ getWatched() {
661
+ return this.watcher?.getWatched() || {};
662
+ }
663
+ /**
664
+ * Check if watcher is ready
665
+ */
666
+ get isReady() {
667
+ return this.watcher !== null;
668
+ }
669
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
670
+ on(event, listener) {
671
+ return super.on(event, listener);
672
+ }
673
+ handleEvent(type, path2, stats) {
674
+ const event = {
675
+ type,
676
+ path: path2,
677
+ stats: stats ? {
678
+ size: stats.size,
679
+ mtime: stats.mtime
680
+ } : void 0
681
+ };
682
+ if (this.options.debounce && this.options.debounce > 0) {
683
+ if (this.debounceTimers.has(path2)) {
684
+ clearTimeout(this.debounceTimers.get(path2));
685
+ }
686
+ this.debounceTimers.set(
687
+ path2,
688
+ setTimeout(() => {
689
+ this.debounceTimers.delete(path2);
690
+ this.emitEvent(event);
691
+ }, this.options.debounce)
692
+ );
693
+ } else {
694
+ this.emitEvent(event);
695
+ }
696
+ }
697
+ emitEvent(event) {
698
+ this.emit(event.type, event);
699
+ this.emit("all", event);
700
+ }
701
+ };
702
+ function watch(paths, options) {
703
+ return new FileWatcher(paths, options).start();
704
+ }
705
+ function watchCallback(paths, callback, options) {
706
+ const watcher = watch(paths, options);
707
+ watcher.on("all", async (event) => {
708
+ try {
709
+ await callback(event);
710
+ } catch (error) {
711
+ watcher.emit("error", error);
712
+ }
713
+ });
714
+ return watcher;
715
+ }
716
+ function watchFileTypes(dir, extensions, callback, options) {
717
+ const patterns = extensions.map((ext) => {
718
+ const e = ext.startsWith(".") ? ext : `.${ext}`;
719
+ return `${dir}/**/*${e}`;
720
+ });
721
+ return watchCallback(patterns, callback, options);
722
+ }
723
+ function watchFile(path2, callback, options) {
724
+ return watchCallback(path2, callback, { ...options, depth: 0 });
725
+ }
726
+ function watchDebounced(paths, callback, debounceMs = 300, options) {
727
+ return watchCallback(paths, callback, { ...options, debounce: debounceMs });
728
+ }
729
+ async function watchOnce(paths, options) {
730
+ return new Promise((resolve4, reject) => {
731
+ const watcher = watch(paths, { ...options, emitInitial: false });
732
+ const cleanup = async () => {
733
+ await watcher.stop();
734
+ };
735
+ watcher.on("all", async (event) => {
736
+ await cleanup();
737
+ resolve4(event);
738
+ });
739
+ watcher.on("error", async (error) => {
740
+ await cleanup();
741
+ reject(error);
742
+ });
743
+ });
744
+ }
745
+ function watchBatched(paths, callback, batchMs = 100, options) {
746
+ const watcher = watch(paths, options);
747
+ let batch = [];
748
+ let timer = null;
749
+ const flush = async () => {
750
+ if (batch.length > 0) {
751
+ const events = [...batch];
752
+ batch = [];
753
+ try {
754
+ await callback(events);
755
+ } catch (error) {
756
+ watcher.emit("error", error);
757
+ }
758
+ }
759
+ };
760
+ watcher.on("all", (event) => {
761
+ batch.push(event);
762
+ if (timer) {
763
+ clearTimeout(timer);
764
+ }
765
+ timer = setTimeout(flush, batchMs);
766
+ });
767
+ const originalStop = watcher.stop.bind(watcher);
768
+ watcher.stop = async () => {
769
+ if (timer) {
770
+ clearTimeout(timer);
771
+ }
772
+ await flush();
773
+ await originalStop();
774
+ };
775
+ return watcher;
776
+ }
777
+ function watchFiltered(paths, filter, callback, options) {
778
+ return watchCallback(
779
+ paths,
780
+ async (event) => {
781
+ if (filter(event)) {
782
+ await callback(event);
783
+ }
784
+ },
785
+ options
786
+ );
787
+ }
788
+ function watchEvents(paths, eventTypes, callback, options) {
789
+ return watchFiltered(paths, (event) => eventTypes.includes(event.type), callback, options);
790
+ }
791
+ function watchFiles(paths, callback, options) {
792
+ return watchEvents(paths, ["add", "change", "unlink"], callback, options);
793
+ }
794
+ function watchDirs(paths, callback, options) {
795
+ return watchEvents(paths, ["addDir", "unlinkDir"], callback, options);
796
+ }
797
+
798
+ // src/fs/index.ts
799
+ function cwd() {
800
+ return process.cwd();
801
+ }
802
+ function chdir(path2) {
803
+ process.chdir(path2);
804
+ }
805
+ function homeDir() {
806
+ return __require("os").homedir();
807
+ }
808
+ function isWindows() {
809
+ return process.platform === "win32";
810
+ }
811
+ function isMacOS() {
812
+ return process.platform === "darwin";
813
+ }
814
+ function isLinux() {
815
+ return process.platform === "linux";
816
+ }
103
817
  export {
104
818
  FileWatcher,
105
819
  PathBuilder,
@@ -108,7 +822,7 @@ export {
108
822
  appendLineSync,
109
823
  appendText,
110
824
  appendTextSync,
111
- basename,
825
+ basename2 as basename,
112
826
  changeExtension,
113
827
  chdir,
114
828
  commonBase,
@@ -117,26 +831,26 @@ export {
117
831
  createTempDir,
118
832
  createTempFile,
119
833
  cwd,
120
- delimiter,
834
+ delimiter2 as delimiter,
121
835
  dirSize,
122
- dirname,
836
+ dirname3 as dirname,
123
837
  ensureDir,
124
838
  ensureDirSync,
125
839
  ensureFile,
126
840
  ensureFileSync,
127
841
  exists,
128
- existsSync,
842
+ existsSync2 as existsSync,
129
843
  expandHome,
130
- extname,
844
+ extname2 as extname,
131
845
  fileSize,
132
846
  fileSizeSync,
133
- format,
847
+ format2 as format,
134
848
  formatSize,
135
849
  glob,
136
850
  globSync,
137
851
  hasExtension,
138
852
  homeDir,
139
- isAbsolute,
853
+ isAbsolute3 as isAbsolute,
140
854
  isChildOf,
141
855
  isDirectory,
142
856
  isDirectorySync,
@@ -145,19 +859,19 @@ export {
145
859
  isLinux,
146
860
  isMacOS,
147
861
  isWindows,
148
- join,
862
+ join3 as join,
149
863
  listDirs,
150
864
  listDirsSync,
151
865
  listFiles,
152
866
  listFilesSync,
153
867
  matchesPattern,
154
- mkdir,
155
- mkdirSync,
868
+ mkdir2 as mkdir,
869
+ mkdirSync2 as mkdirSync,
156
870
  move,
157
871
  moveSync,
158
- normalize,
872
+ normalize2 as normalize,
159
873
  parent,
160
- parse,
874
+ parse2 as parse,
161
875
  path,
162
876
  readBytes,
163
877
  readBytesSync,
@@ -169,16 +883,16 @@ export {
169
883
  readLinesSync,
170
884
  readText,
171
885
  readTextSync,
172
- relative,
886
+ relative3 as relative,
173
887
  remove,
174
888
  removeExtension,
175
889
  removeSync,
176
- resolve,
890
+ resolve3 as resolve,
177
891
  sanitize,
178
892
  segments,
179
- sep,
180
- stat,
181
- statSync,
893
+ sep2 as sep,
894
+ stat2 as stat,
895
+ statSync2 as statSync,
182
896
  tempDir,
183
897
  toPosix,
184
898
  toWindows,