@holoscript/std 6.0.3 → 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 (128) hide show
  1. package/README.md +8 -0
  2. package/dist/chunk-DGUM43GV.js +11 -0
  3. package/dist/chunk-DGUM43GV.js.map +1 -0
  4. package/dist/{chunk-PFX2JM4X.js → chunk-FAMOLKH3.js} +2 -1
  5. package/dist/{chunk-PFX2JM4X.js.map → chunk-FAMOLKH3.js.map} +1 -1
  6. package/dist/{chunk-7HVUYGPS.js → chunk-SOKH6FJ7.js} +37 -5
  7. package/dist/chunk-SOKH6FJ7.js.map +1 -0
  8. package/dist/{chunk-W2Q3LUCM.js → chunk-XJIFG7G3.js} +3 -3
  9. package/dist/chunk-XJIFG7G3.js.map +1 -0
  10. package/dist/collections.cjs +1 -0
  11. package/dist/collections.cjs.map +1 -1
  12. package/dist/collections.js +2 -1
  13. package/dist/fs/fs.d.ts +288 -0
  14. package/dist/fs/fs.d.ts.map +1 -0
  15. package/dist/fs/index.cjs +1049 -0
  16. package/dist/fs/index.cjs.map +1 -0
  17. package/dist/fs/index.d.ts +51 -0
  18. package/dist/fs/index.d.ts.map +1 -0
  19. package/dist/fs/index.js +918 -0
  20. package/dist/fs/index.js.map +1 -0
  21. package/dist/fs/path.d.ts +135 -0
  22. package/dist/fs/path.d.ts.map +1 -0
  23. package/dist/fs/sandbox.d.ts +49 -0
  24. package/dist/fs/sandbox.d.ts.map +1 -0
  25. package/dist/fs/watch.d.ts +133 -0
  26. package/dist/fs/watch.d.ts.map +1 -0
  27. package/dist/index.cjs +54 -7
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +19 -4
  30. package/dist/index.js.map +1 -1
  31. package/dist/math.cjs +21 -2
  32. package/dist/math.cjs.map +1 -1
  33. package/dist/math.js +2 -1
  34. package/dist/string.cjs +2 -2
  35. package/dist/string.cjs.map +1 -1
  36. package/dist/string.js +2 -1
  37. package/dist/time.js +1 -0
  38. package/dist/traits/EconomicPrimitives.js +1 -0
  39. package/dist/traits/EconomicTraits.js +1 -0
  40. package/dist/traits/VRRTraits.d.ts +2 -2
  41. package/dist/types.d.ts.map +1 -1
  42. package/package.json +24 -9
  43. package/CHANGELOG.md +0 -7
  44. package/dist/__tests__/EconomicPrimitives.test.d.ts +0 -2
  45. package/dist/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
  46. package/dist/__tests__/EconomicTraits.test.d.ts +0 -2
  47. package/dist/__tests__/EconomicTraits.test.d.ts.map +0 -1
  48. package/dist/__tests__/SimulationLabPrimitives.test.d.ts +0 -2
  49. package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +0 -1
  50. package/dist/__tests__/collections.test.d.ts +0 -2
  51. package/dist/__tests__/collections.test.d.ts.map +0 -1
  52. package/dist/__tests__/events.test.d.ts +0 -2
  53. package/dist/__tests__/events.test.d.ts.map +0 -1
  54. package/dist/__tests__/index.test.d.ts +0 -2
  55. package/dist/__tests__/index.test.d.ts.map +0 -1
  56. package/dist/__tests__/materials.test.d.ts +0 -2
  57. package/dist/__tests__/materials.test.d.ts.map +0 -1
  58. package/dist/__tests__/math.test.d.ts +0 -2
  59. package/dist/__tests__/math.test.d.ts.map +0 -1
  60. package/dist/__tests__/physics.test.d.ts +0 -2
  61. package/dist/__tests__/physics.test.d.ts.map +0 -1
  62. package/dist/__tests__/spatial.test.d.ts +0 -2
  63. package/dist/__tests__/spatial.test.d.ts.map +0 -1
  64. package/dist/__tests__/standard-library-fundamentals.test.d.ts +0 -2
  65. package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +0 -1
  66. package/dist/__tests__/string-and-time-utilities.test.d.ts +0 -2
  67. package/dist/__tests__/string-and-time-utilities.test.d.ts.map +0 -1
  68. package/dist/__tests__/string-decoupled.test.d.ts +0 -2
  69. package/dist/__tests__/string-decoupled.test.d.ts.map +0 -1
  70. package/dist/__tests__/string.test.d.ts +0 -2
  71. package/dist/__tests__/string.test.d.ts.map +0 -1
  72. package/dist/__tests__/time.test.d.ts +0 -2
  73. package/dist/__tests__/time.test.d.ts.map +0 -1
  74. package/dist/chunk-7HVUYGPS.js.map +0 -1
  75. package/dist/chunk-W2Q3LUCM.js.map +0 -1
  76. package/dist/string.basic.test.d.ts +0 -5
  77. package/dist/string.basic.test.d.ts.map +0 -1
  78. package/dist/string.test.d.ts +0 -5
  79. package/dist/string.test.d.ts.map +0 -1
  80. package/dist/traits/__tests__/ARTraits.test.d.ts +0 -2
  81. package/dist/traits/__tests__/ARTraits.test.d.ts.map +0 -1
  82. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +0 -2
  83. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
  84. package/dist/traits/__tests__/EconomicTraits.test.d.ts +0 -2
  85. package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +0 -1
  86. package/error-utf8.log +0 -6
  87. package/error.log +0 -0
  88. package/src/__tests__/EconomicPrimitives.test.ts +0 -690
  89. package/src/__tests__/EconomicTraits.test.ts +0 -425
  90. package/src/__tests__/SimulationLabPrimitives.test.ts +0 -415
  91. package/src/__tests__/collections.test.ts +0 -182
  92. package/src/__tests__/events.test.ts +0 -135
  93. package/src/__tests__/index.test.ts +0 -14
  94. package/src/__tests__/materials.test.ts +0 -84
  95. package/src/__tests__/math.test.ts +0 -246
  96. package/src/__tests__/physics.test.ts +0 -83
  97. package/src/__tests__/spatial.test.ts +0 -333
  98. package/src/__tests__/standard-library-fundamentals.test.ts +0 -1301
  99. package/src/__tests__/string-and-time-utilities.test.ts +0 -1070
  100. package/src/__tests__/string-decoupled.test.ts +0 -14
  101. package/src/__tests__/string.test.ts +0 -164
  102. package/src/__tests__/time.test.ts +0 -110
  103. package/src/collections.ts +0 -850
  104. package/src/events.ts +0 -88
  105. package/src/index.ts +0 -474
  106. package/src/materials.ts +0 -109
  107. package/src/math.ts +0 -674
  108. package/src/physics.ts +0 -141
  109. package/src/spatial.ts +0 -320
  110. package/src/string.basic.test.ts +0 -14
  111. package/src/string.test.ts +0 -335
  112. package/src/string.ts +0 -531
  113. package/src/time.ts +0 -621
  114. package/src/traits/ARTraits.ts +0 -103
  115. package/src/traits/EconomicPrimitives.ts +0 -755
  116. package/src/traits/EconomicTraits.ts +0 -552
  117. package/src/traits/IoTTraits.ts +0 -102
  118. package/src/traits/SimulationLabPrimitives.ts +0 -650
  119. package/src/traits/SimulationLabTraits.ts +0 -191
  120. package/src/traits/VRRTraits.ts +0 -326
  121. package/src/traits/__tests__/ARTraits.test.ts +0 -14
  122. package/src/traits/__tests__/EconomicPrimitives.test.ts +0 -14
  123. package/src/traits/__tests__/EconomicTraits.test.ts +0 -14
  124. package/src/types.ts +0 -411
  125. package/std_error.log +0 -5
  126. package/tsconfig.json +0 -18
  127. package/tsup.config.ts +0 -17
  128. package/vitest.config.ts +0 -10
@@ -0,0 +1,918 @@
1
+ import {
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
+ }
817
+ export {
818
+ FileWatcher,
819
+ PathBuilder,
820
+ addSuffix,
821
+ appendLine,
822
+ appendLineSync,
823
+ appendText,
824
+ appendTextSync,
825
+ basename2 as basename,
826
+ changeExtension,
827
+ chdir,
828
+ commonBase,
829
+ copy,
830
+ copySync,
831
+ createTempDir,
832
+ createTempFile,
833
+ cwd,
834
+ delimiter2 as delimiter,
835
+ dirSize,
836
+ dirname3 as dirname,
837
+ ensureDir,
838
+ ensureDirSync,
839
+ ensureFile,
840
+ ensureFileSync,
841
+ exists,
842
+ existsSync2 as existsSync,
843
+ expandHome,
844
+ extname2 as extname,
845
+ fileSize,
846
+ fileSizeSync,
847
+ format2 as format,
848
+ formatSize,
849
+ glob,
850
+ globSync,
851
+ hasExtension,
852
+ homeDir,
853
+ isAbsolute3 as isAbsolute,
854
+ isChildOf,
855
+ isDirectory,
856
+ isDirectorySync,
857
+ isFile,
858
+ isFileSync,
859
+ isLinux,
860
+ isMacOS,
861
+ isWindows,
862
+ join3 as join,
863
+ listDirs,
864
+ listDirsSync,
865
+ listFiles,
866
+ listFilesSync,
867
+ matchesPattern,
868
+ mkdir2 as mkdir,
869
+ mkdirSync2 as mkdirSync,
870
+ move,
871
+ moveSync,
872
+ normalize2 as normalize,
873
+ parent,
874
+ parse2 as parse,
875
+ path,
876
+ readBytes,
877
+ readBytesSync,
878
+ readDir,
879
+ readDirSync,
880
+ readJson,
881
+ readJsonSync,
882
+ readLines,
883
+ readLinesSync,
884
+ readText,
885
+ readTextSync,
886
+ relative3 as relative,
887
+ remove,
888
+ removeExtension,
889
+ removeSync,
890
+ resolve3 as resolve,
891
+ sanitize,
892
+ segments,
893
+ sep2 as sep,
894
+ stat2 as stat,
895
+ statSync2 as statSync,
896
+ tempDir,
897
+ toPosix,
898
+ toWindows,
899
+ walk,
900
+ watch,
901
+ watchBatched,
902
+ watchCallback,
903
+ watchDebounced,
904
+ watchDirs,
905
+ watchEvents,
906
+ watchFile,
907
+ watchFileTypes,
908
+ watchFiles,
909
+ watchFiltered,
910
+ watchOnce,
911
+ writeBytes,
912
+ writeBytesSync,
913
+ writeJson,
914
+ writeJsonSync,
915
+ writeText,
916
+ writeTextSync
917
+ };
918
+ //# sourceMappingURL=index.js.map