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