sandlot 0.1.4 → 0.2.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.
- package/dist/browser/bundler.d.ts +68 -0
- package/dist/browser/bundler.d.ts.map +1 -0
- package/dist/browser/executor.d.ts +46 -0
- package/dist/browser/executor.d.ts.map +1 -0
- package/dist/browser/index.d.ts +9 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +2690 -0
- package/dist/browser/preset.d.ts +63 -0
- package/dist/browser/preset.d.ts.map +1 -0
- package/dist/commands/index.d.ts +20 -11
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/types.d.ts +37 -130
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/core/bundler-utils.d.ts +142 -0
- package/dist/core/bundler-utils.d.ts.map +1 -0
- package/dist/core/esm-types-resolver.d.ts +125 -0
- package/dist/core/esm-types-resolver.d.ts.map +1 -0
- package/dist/core/executor.d.ts +35 -0
- package/dist/core/executor.d.ts.map +1 -0
- package/dist/{fs.d.ts → core/fs.d.ts} +27 -29
- package/dist/core/fs.d.ts.map +1 -0
- package/dist/core/sandbox.d.ts +30 -0
- package/dist/core/sandbox.d.ts.map +1 -0
- package/dist/core/sandlot.d.ts +30 -0
- package/dist/core/sandlot.d.ts.map +1 -0
- package/dist/core/shared-module-registry.d.ts +46 -0
- package/dist/core/shared-module-registry.d.ts.map +1 -0
- package/dist/core/typechecker.d.ts +60 -0
- package/dist/core/typechecker.d.ts.map +1 -0
- package/dist/index.d.ts +11 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1398 -2010
- package/dist/node/bundler.d.ts +48 -0
- package/dist/node/bundler.d.ts.map +1 -0
- package/dist/node/executor.d.ts +48 -0
- package/dist/node/executor.d.ts.map +1 -0
- package/dist/node/index.d.ts +9 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +2644 -0
- package/dist/node/preset.d.ts +62 -0
- package/dist/node/preset.d.ts.map +1 -0
- package/dist/types.d.ts +528 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +16 -6
- package/src/browser/bundler.ts +294 -0
- package/src/browser/executor.ts +71 -0
- package/src/browser/index.ts +57 -0
- package/src/browser/preset.ts +179 -0
- package/src/commands/index.ts +498 -37
- package/src/commands/types.ts +117 -145
- package/src/core/bundler-utils.ts +630 -0
- package/src/core/esm-types-resolver.ts +432 -0
- package/src/core/executor.ts +161 -0
- package/src/{fs.ts → core/fs.ts} +59 -37
- package/src/core/sandbox.ts +624 -0
- package/src/core/sandlot.ts +77 -0
- package/src/core/shared-module-registry.ts +138 -0
- package/src/core/typechecker.ts +609 -0
- package/src/index.ts +106 -139
- package/src/node/bundler.ts +194 -0
- package/src/node/executor.ts +87 -0
- package/src/node/index.ts +39 -0
- package/src/node/preset.ts +178 -0
- package/src/types.ts +672 -0
- package/README.md +0 -243
- package/dist/build-emitter.d.ts +0 -47
- package/dist/build-emitter.d.ts.map +0 -1
- package/dist/builder.d.ts +0 -370
- package/dist/builder.d.ts.map +0 -1
- package/dist/bundler.d.ts +0 -152
- package/dist/bundler.d.ts.map +0 -1
- package/dist/commands/compile.d.ts +0 -13
- package/dist/commands/compile.d.ts.map +0 -1
- package/dist/commands/packages.d.ts +0 -17
- package/dist/commands/packages.d.ts.map +0 -1
- package/dist/commands/run.d.ts +0 -40
- package/dist/commands/run.d.ts.map +0 -1
- package/dist/commands.d.ts +0 -179
- package/dist/commands.d.ts.map +0 -1
- package/dist/fs.d.ts.map +0 -1
- package/dist/internal.d.ts +0 -79
- package/dist/internal.d.ts.map +0 -1
- package/dist/internal.js +0 -1942
- package/dist/loader.d.ts +0 -164
- package/dist/loader.d.ts.map +0 -1
- package/dist/packages.d.ts +0 -199
- package/dist/packages.d.ts.map +0 -1
- package/dist/runner.d.ts +0 -314
- package/dist/runner.d.ts.map +0 -1
- package/dist/sandbox-manager.d.ts +0 -261
- package/dist/sandbox-manager.d.ts.map +0 -1
- package/dist/sandbox.d.ts +0 -267
- package/dist/sandbox.d.ts.map +0 -1
- package/dist/shared-modules.d.ts +0 -148
- package/dist/shared-modules.d.ts.map +0 -1
- package/dist/shared-resources.d.ts +0 -102
- package/dist/shared-resources.d.ts.map +0 -1
- package/dist/ts-libs.d.ts +0 -85
- package/dist/ts-libs.d.ts.map +0 -1
- package/dist/typechecker.d.ts +0 -127
- package/dist/typechecker.d.ts.map +0 -1
- package/src/build-emitter.ts +0 -64
- package/src/builder.ts +0 -498
- package/src/bundler.ts +0 -575
- package/src/commands/compile.ts +0 -236
- package/src/commands/packages.ts +0 -154
- package/src/commands/run.ts +0 -245
- package/src/internal.ts +0 -119
- package/src/loader.ts +0 -229
- package/src/packages.ts +0 -936
- package/src/sandbox.ts +0 -398
- package/src/shared-modules.ts +0 -280
- package/src/shared-resources.ts +0 -166
- package/src/ts-libs.ts +0 -218
- package/src/typechecker.ts +0 -635
package/src/{fs.ts → core/fs.ts}
RENAMED
|
@@ -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 (
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
189
|
+
readFile(
|
|
193
190
|
path: string,
|
|
194
191
|
options?: ReadFileOptions | BufferEncoding
|
|
195
|
-
):
|
|
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
|
-
|
|
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
|
-
|
|
233
|
+
writeFile(
|
|
237
234
|
path: string,
|
|
238
235
|
content: FileContent,
|
|
239
236
|
_options?: WriteFileOptions | BufferEncoding
|
|
240
|
-
):
|
|
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
|
-
|
|
255
|
+
appendFile(
|
|
259
256
|
path: string,
|
|
260
257
|
content: FileContent,
|
|
261
258
|
options?: WriteFileOptions | BufferEncoding
|
|
262
|
-
):
|
|
259
|
+
): void {
|
|
263
260
|
const normalizedPath = this.normalizePath(path);
|
|
264
261
|
let existing: string | Uint8Array = "";
|
|
265
262
|
|
|
266
263
|
try {
|
|
267
|
-
existing =
|
|
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
|
-
|
|
277
|
+
this.writeFile(normalizedPath, newContent, options);
|
|
281
278
|
}
|
|
282
279
|
|
|
283
|
-
|
|
280
|
+
exists(path: string): boolean {
|
|
284
281
|
const normalizedPath = this.normalizePath(path);
|
|
285
282
|
return this.entries.has(normalizedPath);
|
|
286
283
|
}
|
|
287
284
|
|
|
288
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
}
|