sandlot 0.1.4 → 0.2.0

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 (115) hide show
  1. package/dist/browser/bundler.d.ts +68 -0
  2. package/dist/browser/bundler.d.ts.map +1 -0
  3. package/dist/browser/executor.d.ts +46 -0
  4. package/dist/browser/executor.d.ts.map +1 -0
  5. package/dist/browser/index.d.ts +9 -0
  6. package/dist/browser/index.d.ts.map +1 -0
  7. package/dist/browser/index.js +2692 -0
  8. package/dist/browser/preset.d.ts +63 -0
  9. package/dist/browser/preset.d.ts.map +1 -0
  10. package/dist/commands/index.d.ts +20 -11
  11. package/dist/commands/index.d.ts.map +1 -1
  12. package/dist/commands/types.d.ts +31 -132
  13. package/dist/commands/types.d.ts.map +1 -1
  14. package/dist/core/bundler-utils.d.ts +142 -0
  15. package/dist/core/bundler-utils.d.ts.map +1 -0
  16. package/dist/core/esm-types-resolver.d.ts +125 -0
  17. package/dist/core/esm-types-resolver.d.ts.map +1 -0
  18. package/dist/core/executor.d.ts +35 -0
  19. package/dist/core/executor.d.ts.map +1 -0
  20. package/dist/{fs.d.ts → core/fs.d.ts} +27 -29
  21. package/dist/core/fs.d.ts.map +1 -0
  22. package/dist/core/sandbox.d.ts +30 -0
  23. package/dist/core/sandbox.d.ts.map +1 -0
  24. package/dist/core/sandlot.d.ts +30 -0
  25. package/dist/core/sandlot.d.ts.map +1 -0
  26. package/dist/core/shared-module-registry.d.ts +46 -0
  27. package/dist/core/shared-module-registry.d.ts.map +1 -0
  28. package/dist/core/typechecker.d.ts +60 -0
  29. package/dist/core/typechecker.d.ts.map +1 -0
  30. package/dist/index.d.ts +11 -16
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1399 -2010
  33. package/dist/node/bundler.d.ts +48 -0
  34. package/dist/node/bundler.d.ts.map +1 -0
  35. package/dist/node/executor.d.ts +48 -0
  36. package/dist/node/executor.d.ts.map +1 -0
  37. package/dist/node/index.d.ts +9 -0
  38. package/dist/node/index.d.ts.map +1 -0
  39. package/dist/node/index.js +2646 -0
  40. package/dist/node/preset.d.ts +62 -0
  41. package/dist/node/preset.d.ts.map +1 -0
  42. package/dist/types.d.ts +525 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/package.json +16 -6
  45. package/src/browser/bundler.ts +294 -0
  46. package/src/browser/executor.ts +71 -0
  47. package/src/browser/index.ts +57 -0
  48. package/src/browser/preset.ts +179 -0
  49. package/src/commands/index.ts +526 -43
  50. package/src/commands/types.ts +82 -146
  51. package/src/core/bundler-utils.ts +630 -0
  52. package/src/core/esm-types-resolver.ts +432 -0
  53. package/src/core/executor.ts +161 -0
  54. package/src/{fs.ts → core/fs.ts} +59 -37
  55. package/src/core/sandbox.ts +621 -0
  56. package/src/core/sandlot.ts +77 -0
  57. package/src/core/shared-module-registry.ts +138 -0
  58. package/src/core/typechecker.ts +607 -0
  59. package/src/index.ts +104 -139
  60. package/src/node/bundler.ts +194 -0
  61. package/src/node/executor.ts +87 -0
  62. package/src/node/index.ts +39 -0
  63. package/src/node/preset.ts +178 -0
  64. package/src/types.ts +668 -0
  65. package/README.md +0 -243
  66. package/dist/build-emitter.d.ts +0 -47
  67. package/dist/build-emitter.d.ts.map +0 -1
  68. package/dist/builder.d.ts +0 -370
  69. package/dist/builder.d.ts.map +0 -1
  70. package/dist/bundler.d.ts +0 -152
  71. package/dist/bundler.d.ts.map +0 -1
  72. package/dist/commands/compile.d.ts +0 -13
  73. package/dist/commands/compile.d.ts.map +0 -1
  74. package/dist/commands/packages.d.ts +0 -17
  75. package/dist/commands/packages.d.ts.map +0 -1
  76. package/dist/commands/run.d.ts +0 -40
  77. package/dist/commands/run.d.ts.map +0 -1
  78. package/dist/commands.d.ts +0 -179
  79. package/dist/commands.d.ts.map +0 -1
  80. package/dist/fs.d.ts.map +0 -1
  81. package/dist/internal.d.ts +0 -79
  82. package/dist/internal.d.ts.map +0 -1
  83. package/dist/internal.js +0 -1942
  84. package/dist/loader.d.ts +0 -164
  85. package/dist/loader.d.ts.map +0 -1
  86. package/dist/packages.d.ts +0 -199
  87. package/dist/packages.d.ts.map +0 -1
  88. package/dist/runner.d.ts +0 -314
  89. package/dist/runner.d.ts.map +0 -1
  90. package/dist/sandbox-manager.d.ts +0 -261
  91. package/dist/sandbox-manager.d.ts.map +0 -1
  92. package/dist/sandbox.d.ts +0 -267
  93. package/dist/sandbox.d.ts.map +0 -1
  94. package/dist/shared-modules.d.ts +0 -148
  95. package/dist/shared-modules.d.ts.map +0 -1
  96. package/dist/shared-resources.d.ts +0 -102
  97. package/dist/shared-resources.d.ts.map +0 -1
  98. package/dist/ts-libs.d.ts +0 -85
  99. package/dist/ts-libs.d.ts.map +0 -1
  100. package/dist/typechecker.d.ts +0 -127
  101. package/dist/typechecker.d.ts.map +0 -1
  102. package/src/build-emitter.ts +0 -64
  103. package/src/builder.ts +0 -498
  104. package/src/bundler.ts +0 -575
  105. package/src/commands/compile.ts +0 -236
  106. package/src/commands/packages.ts +0 -154
  107. package/src/commands/run.ts +0 -245
  108. package/src/internal.ts +0 -119
  109. package/src/loader.ts +0 -229
  110. package/src/packages.ts +0 -936
  111. package/src/sandbox.ts +0 -398
  112. package/src/shared-modules.ts +0 -280
  113. package/src/shared-resources.ts +0 -166
  114. package/src/ts-libs.ts +0 -218
  115. package/src/typechecker.ts +0 -635
@@ -1,5 +1,4 @@
1
1
  import type {
2
- IFileSystem,
3
2
  FsEntry,
4
3
  FsStat,
5
4
  MkdirOptions,
@@ -8,32 +7,30 @@ import type {
8
7
  FileContent,
9
8
  InitialFiles,
10
9
  FileInit,
10
+ IFileSystem,
11
11
  } from "just-bash/browser";
12
12
 
13
13
  /**
14
- * Supported buffer encodings
14
+ * Supported buffer encodings (matches just-bash)
15
15
  */
16
16
  type BufferEncoding = "utf8" | "utf-8" | "ascii" | "binary" | "base64" | "hex" | "latin1";
17
17
 
18
18
  /**
19
- * Options for reading files
19
+ * Options for reading files (matches just-bash)
20
20
  */
21
21
  interface ReadFileOptions {
22
22
  encoding?: BufferEncoding | null;
23
23
  }
24
24
 
25
25
  /**
26
- * Options for writing files.
27
- * Note: In this browser-based filesystem, content is stored as-is.
28
- * The encoding option is accepted for API compatibility but not used.
26
+ * Options for writing files (matches just-bash)
29
27
  */
30
28
  interface WriteFileOptions {
31
- /** Accepted for API compatibility but not used - content is stored as-is */
32
29
  encoding?: BufferEncoding;
33
30
  }
34
31
 
35
32
  /**
36
- * Directory entry with type information (similar to Node's Dirent)
33
+ * Directory entry with type information (matches just-bash DirentEntry)
37
34
  */
38
35
  interface DirentEntry {
39
36
  name: string;
@@ -69,7 +66,7 @@ export interface FilesystemOptions {
69
66
  * const fs = Filesystem.create({ initialFiles: { '/src/index.ts': 'export const x = 1;' } });
70
67
  *
71
68
  * // Use filesystem
72
- * await fs.writeFile('/src/app.ts', 'console.log("hello")');
69
+ * fs.writeFile('/src/app.ts', 'console.log("hello")');
73
70
  *
74
71
  * // Export for persistence
75
72
  * const files = fs.getFiles();
@@ -80,7 +77,7 @@ export interface FilesystemOptions {
80
77
  * const fs2 = Filesystem.create({ initialFiles: saved });
81
78
  * ```
82
79
  */
83
- export class Filesystem implements IFileSystem {
80
+ export class Filesystem {
84
81
  private entries: Map<string, FsEntry>;
85
82
  private maxSizeBytes: number;
86
83
 
@@ -153,7 +150,7 @@ export class Filesystem implements IFileSystem {
153
150
  */
154
151
  getFiles(): Record<string, string> {
155
152
  const files: Record<string, string> = {};
156
-
153
+
157
154
  for (const [path, entry] of this.entries) {
158
155
  if (entry.type === "file") {
159
156
  if (typeof entry.content === "string") {
@@ -165,7 +162,7 @@ export class Filesystem implements IFileSystem {
165
162
  }
166
163
  }
167
164
  }
168
-
165
+
169
166
  return files;
170
167
  }
171
168
 
@@ -189,10 +186,10 @@ export class Filesystem implements IFileSystem {
189
186
 
190
187
  // ============ IFileSystem Implementation ============
191
188
 
192
- async readFile(
189
+ readFile(
193
190
  path: string,
194
191
  options?: ReadFileOptions | BufferEncoding
195
- ): Promise<string> {
192
+ ): string {
196
193
  const normalizedPath = this.normalizePath(path);
197
194
  const entry = this.resolveSymlinks(normalizedPath);
198
195
 
@@ -213,7 +210,7 @@ export class Filesystem implements IFileSystem {
213
210
  return this.decodeBuffer(content, encoding);
214
211
  }
215
212
 
216
- async readFileBuffer(path: string): Promise<Uint8Array> {
213
+ readFileBuffer(path: string): Uint8Array {
217
214
  const normalizedPath = this.normalizePath(path);
218
215
  const entry = this.resolveSymlinks(normalizedPath);
219
216
 
@@ -233,11 +230,11 @@ export class Filesystem implements IFileSystem {
233
230
  return new TextEncoder().encode(content);
234
231
  }
235
232
 
236
- async writeFile(
233
+ writeFile(
237
234
  path: string,
238
235
  content: FileContent,
239
236
  _options?: WriteFileOptions | BufferEncoding
240
- ): Promise<void> {
237
+ ): void {
241
238
  const normalizedPath = this.normalizePath(path);
242
239
  this.checkSizeLimit(content);
243
240
  this.ensureParentDirs(normalizedPath);
@@ -255,16 +252,16 @@ export class Filesystem implements IFileSystem {
255
252
  });
256
253
  }
257
254
 
258
- async appendFile(
255
+ appendFile(
259
256
  path: string,
260
257
  content: FileContent,
261
258
  options?: WriteFileOptions | BufferEncoding
262
- ): Promise<void> {
259
+ ): void {
263
260
  const normalizedPath = this.normalizePath(path);
264
261
  let existing: string | Uint8Array = "";
265
262
 
266
263
  try {
267
- existing = await this.readFile(normalizedPath);
264
+ existing = this.readFile(normalizedPath);
268
265
  } catch {
269
266
  // File doesn't exist, will be created
270
267
  }
@@ -277,15 +274,15 @@ export class Filesystem implements IFileSystem {
277
274
  typeof content === "string" ? new TextEncoder().encode(content) : content
278
275
  );
279
276
 
280
- await this.writeFile(normalizedPath, newContent, options);
277
+ this.writeFile(normalizedPath, newContent, options);
281
278
  }
282
279
 
283
- async exists(path: string): Promise<boolean> {
280
+ exists(path: string): boolean {
284
281
  const normalizedPath = this.normalizePath(path);
285
282
  return this.entries.has(normalizedPath);
286
283
  }
287
284
 
288
- async stat(path: string): Promise<FsStat> {
285
+ stat(path: string): FsStat {
289
286
  const normalizedPath = this.normalizePath(path);
290
287
  const entry = this.resolveSymlinks(normalizedPath);
291
288
 
@@ -296,7 +293,7 @@ export class Filesystem implements IFileSystem {
296
293
  return this.entryToStat(entry);
297
294
  }
298
295
 
299
- async lstat(path: string): Promise<FsStat> {
296
+ lstat(path: string): FsStat {
300
297
  const normalizedPath = this.normalizePath(path);
301
298
  const entry = this.entries.get(normalizedPath);
302
299
 
@@ -307,7 +304,7 @@ export class Filesystem implements IFileSystem {
307
304
  return this.entryToStat(entry);
308
305
  }
309
306
 
310
- async mkdir(path: string, options?: MkdirOptions): Promise<void> {
307
+ mkdir(path: string, options?: MkdirOptions): void {
311
308
  const normalizedPath = this.normalizePath(path);
312
309
 
313
310
  if (this.entries.has(normalizedPath)) {
@@ -333,7 +330,7 @@ export class Filesystem implements IFileSystem {
333
330
  });
334
331
  }
335
332
 
336
- async readdir(path: string): Promise<string[]> {
333
+ readdir(path: string): string[] {
337
334
  const normalizedPath = this.normalizePath(path);
338
335
  const entry = this.resolveSymlinks(normalizedPath);
339
336
 
@@ -360,7 +357,7 @@ export class Filesystem implements IFileSystem {
360
357
  return names.sort();
361
358
  }
362
359
 
363
- async readdirWithFileTypes(path: string): Promise<DirentEntry[]> {
360
+ readdirWithFileTypes(path: string): DirentEntry[] {
364
361
  const normalizedPath = this.normalizePath(path);
365
362
  const entry = this.resolveSymlinks(normalizedPath);
366
363
 
@@ -392,7 +389,7 @@ export class Filesystem implements IFileSystem {
392
389
  return dirents.sort((a, b) => a.name.localeCompare(b.name));
393
390
  }
394
391
 
395
- async rm(path: string, options?: RmOptions): Promise<void> {
392
+ rm(path: string, options?: RmOptions): void {
396
393
  const normalizedPath = this.normalizePath(path);
397
394
  const entry = this.entries.get(normalizedPath);
398
395
 
@@ -402,7 +399,7 @@ export class Filesystem implements IFileSystem {
402
399
  }
403
400
 
404
401
  if (entry.type === "directory") {
405
- const children = await this.readdir(normalizedPath);
402
+ const children = this.readdir(normalizedPath);
406
403
  if (children.length > 0 && !options?.recursive) {
407
404
  throw new Error(`ENOTEMPTY: directory not empty, rm '${path}'`);
408
405
  }
@@ -421,7 +418,7 @@ export class Filesystem implements IFileSystem {
421
418
  this.entries.delete(normalizedPath);
422
419
  }
423
420
 
424
- async cp(src: string, dest: string, options?: CpOptions): Promise<void> {
421
+ cp(src: string, dest: string, options?: CpOptions): void {
425
422
  const srcPath = this.normalizePath(src);
426
423
  const destPath = this.normalizePath(dest);
427
424
  const entry = this.entries.get(srcPath);
@@ -453,7 +450,7 @@ export class Filesystem implements IFileSystem {
453
450
  }
454
451
  }
455
452
 
456
- async mv(src: string, dest: string): Promise<void> {
453
+ mv(src: string, dest: string): void {
457
454
  const srcPath = this.normalizePath(src);
458
455
  const destPath = this.normalizePath(dest);
459
456
  const entry = this.entries.get(srcPath);
@@ -511,7 +508,7 @@ export class Filesystem implements IFileSystem {
511
508
  return [...this.entries.keys()].sort();
512
509
  }
513
510
 
514
- async chmod(path: string, mode: number): Promise<void> {
511
+ chmod(path: string, mode: number): void {
515
512
  const normalizedPath = this.normalizePath(path);
516
513
  const entry = this.entries.get(normalizedPath);
517
514
 
@@ -523,7 +520,7 @@ export class Filesystem implements IFileSystem {
523
520
  entry.mtime = new Date();
524
521
  }
525
522
 
526
- async symlink(target: string, linkPath: string): Promise<void> {
523
+ symlink(target: string, linkPath: string): void {
527
524
  const normalizedLinkPath = this.normalizePath(linkPath);
528
525
 
529
526
  if (this.entries.has(normalizedLinkPath)) {
@@ -540,7 +537,7 @@ export class Filesystem implements IFileSystem {
540
537
  });
541
538
  }
542
539
 
543
- async link(existingPath: string, newPath: string): Promise<void> {
540
+ link(existingPath: string, newPath: string): void {
544
541
  const srcPath = this.normalizePath(existingPath);
545
542
  const destPath = this.normalizePath(newPath);
546
543
 
@@ -566,7 +563,7 @@ export class Filesystem implements IFileSystem {
566
563
  });
567
564
  }
568
565
 
569
- async readlink(path: string): Promise<string> {
566
+ readlink(path: string): string {
570
567
  const normalizedPath = this.normalizePath(path);
571
568
  const entry = this.entries.get(normalizedPath);
572
569
 
@@ -580,7 +577,7 @@ export class Filesystem implements IFileSystem {
580
577
  return entry.target;
581
578
  }
582
579
 
583
- async realpath(path: string): Promise<string> {
580
+ realpath(path: string): string {
584
581
  const normalizedPath = this.normalizePath(path);
585
582
  const parts = normalizedPath.split("/").filter(Boolean);
586
583
  let resolved = "/";
@@ -617,7 +614,7 @@ export class Filesystem implements IFileSystem {
617
614
  return resolved;
618
615
  }
619
616
 
620
- async utimes(path: string, atime: Date, mtime: Date): Promise<void> {
617
+ utimes(path: string, atime: Date, mtime: Date): void {
621
618
  const normalizedPath = this.normalizePath(path);
622
619
  const entry = this.entries.get(normalizedPath);
623
620
 
@@ -807,3 +804,28 @@ export function createFilesystem(options?: FilesystemOptions): Filesystem {
807
804
  return Filesystem.create(options);
808
805
  }
809
806
 
807
+ export function wrapFilesystemForJustBash(fs: Filesystem): IFileSystem {
808
+ return {
809
+ readFile: async (path: string, options?: ReadFileOptions | BufferEncoding): Promise<string> => fs.readFile(path, options),
810
+ writeFile: async (path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void> => fs.writeFile(path, content, options),
811
+ appendFile: async (path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): Promise<void> => fs.appendFile(path, content, options),
812
+ exists: async (path: string): Promise<boolean> => fs.exists(path),
813
+ stat: async (path: string): Promise<FsStat> => fs.stat(path),
814
+ lstat: async (path: string): Promise<FsStat> => fs.lstat(path),
815
+ mkdir: async (path: string, options?: MkdirOptions): Promise<void> => fs.mkdir(path, options),
816
+ readdir: async (path: string): Promise<string[]> => fs.readdir(path),
817
+ readdirWithFileTypes: async (path: string): Promise<DirentEntry[]> => fs.readdirWithFileTypes(path),
818
+ rm: async (path: string, options?: RmOptions) => fs.rm(path, options),
819
+ cp: async (src: string, dest: string, options?: CpOptions): Promise<void> => fs.cp(src, dest, options),
820
+ mv: async (src: string, dest: string): Promise<void> => fs.mv(src, dest),
821
+ chmod: async (path: string, mode: number) => fs.chmod(path, mode),
822
+ symlink: async (target: string, linkPath: string): Promise<void> => fs.symlink(target, linkPath),
823
+ link: async (existingPath: string, newPath: string) => fs.link(existingPath, newPath),
824
+ readlink: async (path: string): Promise<string> => fs.readlink(path),
825
+ realpath: async (path: string): Promise<string> => fs.realpath(path),
826
+ utimes: async (path: string, atime: Date, mtime: Date): Promise<void> => fs.utimes(path, atime, mtime),
827
+ readFileBuffer: async (path: string): Promise<Uint8Array> => fs.readFileBuffer(path),
828
+ resolvePath: (base: string, path: string): string => fs.resolvePath(base, path),
829
+ getAllPaths: (): string[] => fs.getAllPaths(),
830
+ };
831
+ }