sandlot 0.1.2 → 0.1.4
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/README.md +138 -408
- package/dist/build-emitter.d.ts +31 -13
- package/dist/build-emitter.d.ts.map +1 -1
- package/dist/builder.d.ts +370 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/bundler.d.ts +6 -2
- package/dist/bundler.d.ts.map +1 -1
- package/dist/commands/compile.d.ts +13 -0
- package/dist/commands/compile.d.ts.map +1 -0
- package/dist/commands/index.d.ts +17 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/packages.d.ts +17 -0
- package/dist/commands/packages.d.ts.map +1 -0
- package/dist/commands/run.d.ts +40 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/types.d.ts +141 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/fs.d.ts +53 -49
- package/dist/fs.d.ts.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +300 -511
- package/dist/internal.js +161 -171
- package/dist/runner.d.ts +314 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/sandbox-manager.d.ts +45 -21
- package/dist/sandbox-manager.d.ts.map +1 -1
- package/dist/sandbox.d.ts +144 -62
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/shared-modules.d.ts +22 -3
- package/dist/shared-modules.d.ts.map +1 -1
- package/dist/shared-resources.d.ts +0 -3
- package/dist/shared-resources.d.ts.map +1 -1
- package/dist/ts-libs.d.ts +7 -20
- package/dist/ts-libs.d.ts.map +1 -1
- package/dist/typechecker.d.ts +1 -1
- package/package.json +5 -5
- package/src/build-emitter.ts +32 -29
- package/src/builder.ts +498 -0
- package/src/bundler.ts +76 -55
- package/src/commands/compile.ts +236 -0
- package/src/commands/index.ts +51 -0
- package/src/commands/packages.ts +154 -0
- package/src/commands/run.ts +245 -0
- package/src/commands/types.ts +172 -0
- package/src/fs.ts +82 -221
- package/src/index.ts +17 -12
- package/src/sandbox.ts +219 -149
- package/src/shared-modules.ts +74 -4
- package/src/shared-resources.ts +0 -3
- package/src/ts-libs.ts +19 -121
- package/src/typechecker.ts +1 -1
- package/dist/react.d.ts +0 -159
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js +0 -149
- package/src/commands.ts +0 -733
- package/src/sandbox-manager.ts +0 -409
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import { Bash, defineCommand } from "just-bash/browser";
|
|
2
|
-
import {
|
|
3
|
-
import { type
|
|
1
|
+
import { Bash, defineCommand, type BashOptions } from "just-bash/browser";
|
|
2
|
+
import { Filesystem } from "./fs";
|
|
3
|
+
import { type BuildOutput, type ValidateFn } from "./commands";
|
|
4
4
|
import { type SharedResources } from "./shared-resources";
|
|
5
|
+
/**
|
|
6
|
+
* Options that can be passed through to the just-bash Bash constructor.
|
|
7
|
+
* Excludes options that sandlot controls internally (fs, customCommands, files, cwd).
|
|
8
|
+
* The working directory is always root (/).
|
|
9
|
+
*/
|
|
10
|
+
export type SandboxBashOptions = Omit<BashOptions, 'fs' | 'customCommands' | 'files' | 'cwd'>;
|
|
5
11
|
/**
|
|
6
12
|
* Options for creating a sandbox environment
|
|
7
13
|
*/
|
|
8
14
|
export interface SandboxOptions {
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
16
|
+
* Initial files to populate the filesystem with.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const sandbox = await createSandbox({
|
|
21
|
+
* initialFiles: {
|
|
22
|
+
* '/src/index.ts': 'export const x = 1;',
|
|
23
|
+
* '/tsconfig.json': JSON.stringify({ compilerOptions: { strict: true } }),
|
|
24
|
+
* },
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
initialFiles?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum filesystem size in bytes (default: 50MB)
|
|
11
31
|
*/
|
|
12
|
-
|
|
32
|
+
maxFilesystemSize?: number;
|
|
13
33
|
/**
|
|
14
34
|
* Path to tsconfig.json in the virtual filesystem.
|
|
15
35
|
* Default: "/tsconfig.json"
|
|
@@ -25,10 +45,12 @@ export interface SandboxOptions {
|
|
|
25
45
|
resources?: SharedResources;
|
|
26
46
|
/**
|
|
27
47
|
* Callback invoked when a build succeeds.
|
|
28
|
-
* Receives the
|
|
29
|
-
*
|
|
48
|
+
* Receives the build output with the bundle and loaded module.
|
|
49
|
+
*
|
|
50
|
+
* For agent workflows, prefer using `createBuilder()` which handles
|
|
51
|
+
* build capture automatically.
|
|
30
52
|
*/
|
|
31
|
-
onBuild?: (result:
|
|
53
|
+
onBuild?: (result: BuildOutput) => void | Promise<void>;
|
|
32
54
|
/**
|
|
33
55
|
* Additional custom commands to add to the bash environment
|
|
34
56
|
*/
|
|
@@ -41,6 +63,9 @@ export interface SandboxOptions {
|
|
|
41
63
|
* This solves the "multiple React instances" problem by allowing dynamic
|
|
42
64
|
* components to share the same React instance as the host application.
|
|
43
65
|
*
|
|
66
|
+
* Type definitions are automatically installed for these modules so that
|
|
67
|
+
* TypeScript can typecheck code that imports them.
|
|
68
|
+
*
|
|
44
69
|
* @example
|
|
45
70
|
* ```ts
|
|
46
71
|
* // Host setup
|
|
@@ -53,73 +78,140 @@ export interface SandboxOptions {
|
|
|
53
78
|
* 'react-dom/client': ReactDOM,
|
|
54
79
|
* });
|
|
55
80
|
*
|
|
56
|
-
* // Create sandbox with shared modules
|
|
57
|
-
* const sandbox = await
|
|
81
|
+
* // Create sandbox with shared modules (types auto-installed)
|
|
82
|
+
* const sandbox = await createSandbox({
|
|
58
83
|
* sharedModules: ['react', 'react-dom/client'],
|
|
59
84
|
* });
|
|
60
85
|
* ```
|
|
61
86
|
*/
|
|
62
87
|
sharedModules?: string[];
|
|
88
|
+
/**
|
|
89
|
+
* Options passed through to the just-bash Bash constructor.
|
|
90
|
+
* Use this to configure environment variables, execution limits,
|
|
91
|
+
* network access, logging, and other bash-level settings.
|
|
92
|
+
*
|
|
93
|
+
* Note: `fs`, `customCommands`, `files`, and `cwd` are controlled by sandlot
|
|
94
|
+
* and cannot be overridden here. The working directory is always root (/).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const sandbox = await createSandbox({
|
|
99
|
+
* bashOptions: {
|
|
100
|
+
* env: { NODE_ENV: 'development' },
|
|
101
|
+
* executionLimits: { maxCommandCount: 1000 },
|
|
102
|
+
* },
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
bashOptions?: SandboxBashOptions;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Sandbox state that can be serialized for persistence.
|
|
110
|
+
*/
|
|
111
|
+
export interface SandboxState {
|
|
112
|
+
/**
|
|
113
|
+
* All files in the filesystem as path -> content mapping.
|
|
114
|
+
* Can be passed as `initialFiles` when creating a new sandbox.
|
|
115
|
+
*/
|
|
116
|
+
files: Record<string, string>;
|
|
63
117
|
}
|
|
64
118
|
/**
|
|
65
119
|
* The sandbox environment containing the filesystem and bash shell
|
|
66
120
|
*/
|
|
67
121
|
export interface Sandbox {
|
|
68
122
|
/**
|
|
69
|
-
* The virtual filesystem
|
|
123
|
+
* The virtual filesystem
|
|
70
124
|
*/
|
|
71
|
-
fs:
|
|
125
|
+
fs: Filesystem;
|
|
72
126
|
/**
|
|
73
127
|
* The just-bash shell environment
|
|
74
128
|
*/
|
|
75
129
|
bash: Bash;
|
|
76
130
|
/**
|
|
77
|
-
*
|
|
131
|
+
* The last successful build output, or null if no build has succeeded yet.
|
|
132
|
+
*
|
|
133
|
+
* This is updated automatically whenever a `build` command succeeds.
|
|
134
|
+
* Contains both the bundle and the loaded (and validated, if applicable) module.
|
|
78
135
|
*
|
|
79
136
|
* @example
|
|
80
137
|
* ```ts
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* await
|
|
84
|
-
*
|
|
138
|
+
* // Agent loop pattern
|
|
139
|
+
* while (!sandbox.lastBuild) {
|
|
140
|
+
* const response = await agent.step();
|
|
141
|
+
* await sandbox.bash.exec(response.command);
|
|
142
|
+
* }
|
|
143
|
+
* // Build succeeded, sandbox.lastBuild contains bundle + module
|
|
144
|
+
* const App = sandbox.lastBuild.module.App;
|
|
85
145
|
* ```
|
|
86
146
|
*/
|
|
87
|
-
|
|
147
|
+
lastBuild: BuildOutput | null;
|
|
88
148
|
/**
|
|
89
|
-
*
|
|
149
|
+
* Get the current sandbox state for persistence.
|
|
90
150
|
*
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
151
|
+
* Returns a serializable object containing all files that can be
|
|
152
|
+
* JSON-serialized and used to restore the sandbox later.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* // Save sandbox state
|
|
157
|
+
* const state = sandbox.getState();
|
|
158
|
+
* localStorage.setItem('my-project', JSON.stringify(state));
|
|
159
|
+
*
|
|
160
|
+
* // Later, restore the sandbox
|
|
161
|
+
* const saved = JSON.parse(localStorage.getItem('my-project'));
|
|
162
|
+
* const sandbox2 = await createSandbox({ initialFiles: saved.files });
|
|
163
|
+
* ```
|
|
96
164
|
*/
|
|
97
|
-
|
|
165
|
+
getState(): SandboxState;
|
|
98
166
|
/**
|
|
99
167
|
* Subscribe to build events. Called whenever a build succeeds.
|
|
100
168
|
* Returns an unsubscribe function.
|
|
101
169
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
170
|
+
* For agent workflows, prefer using `createBuilder()` which handles
|
|
171
|
+
* build capture automatically. Use `onBuild` directly when you need
|
|
172
|
+
* more control over the subscription lifecycle.
|
|
104
173
|
*
|
|
105
174
|
* @example
|
|
106
175
|
* ```ts
|
|
107
|
-
* let
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* onBuild: (result) => {
|
|
111
|
-
* bundle = result;
|
|
112
|
-
* console.log('Built:', result.code.length, 'bytes');
|
|
113
|
-
* },
|
|
176
|
+
* let lastBuild: BuildOutput | null = null;
|
|
177
|
+
* const unsubscribe = sandbox.onBuild((result) => {
|
|
178
|
+
* lastBuild = result;
|
|
114
179
|
* });
|
|
115
180
|
*
|
|
116
|
-
*
|
|
181
|
+
* await sandbox.bash.exec('build /src/index.ts');
|
|
182
|
+
* unsubscribe();
|
|
183
|
+
*
|
|
184
|
+
* if (lastBuild) {
|
|
185
|
+
* const App = lastBuild.module.App as React.ComponentType;
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
onBuild(callback: (result: BuildOutput) => void | Promise<void>): () => void;
|
|
190
|
+
/**
|
|
191
|
+
* Set a validation function for the build command.
|
|
192
|
+
*
|
|
193
|
+
* When set, the build command will run this function after loading
|
|
194
|
+
* the module. If validation throws, the build fails and the agent
|
|
195
|
+
* sees the error. If validation passes, the validated module is
|
|
196
|
+
* available in the build output.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* sandbox.setValidation((mod) => {
|
|
201
|
+
* if (!mod.App) throw new Error("Must export App component");
|
|
202
|
+
* return { App: mod.App as React.ComponentType };
|
|
203
|
+
* });
|
|
117
204
|
*
|
|
118
|
-
* //
|
|
119
|
-
*
|
|
205
|
+
* // Now build will fail if App is missing
|
|
206
|
+
* await sandbox.bash.exec('build /src/index.ts');
|
|
120
207
|
* ```
|
|
121
208
|
*/
|
|
122
|
-
|
|
209
|
+
setValidation(fn: ValidateFn): void;
|
|
210
|
+
/**
|
|
211
|
+
* Clear the validation function.
|
|
212
|
+
* After calling this, builds will not perform validation.
|
|
213
|
+
*/
|
|
214
|
+
clearValidation(): void;
|
|
123
215
|
}
|
|
124
216
|
/**
|
|
125
217
|
* Create an in-browser agent sandbox with a virtual filesystem, TypeScript
|
|
@@ -128,9 +220,12 @@ export interface Sandbox {
|
|
|
128
220
|
* The sandbox provides a just-bash shell with custom commands:
|
|
129
221
|
* - `tsc [entry]` - Type check the project
|
|
130
222
|
* - `build [entry] [options]` - Build the project (runs typecheck first)
|
|
223
|
+
* - `install <pkg>` - Install npm packages
|
|
224
|
+
* - `uninstall <pkg>` - Remove packages
|
|
225
|
+
* - `list` - List installed packages
|
|
226
|
+
* - `run <entry>` - Run a script
|
|
131
227
|
*
|
|
132
228
|
* Build options:
|
|
133
|
-
* - `--output, -o <path>` - Output path (default: /dist/bundle.js)
|
|
134
229
|
* - `--format, -f <esm|iife|cjs>` - Output format (default: esm)
|
|
135
230
|
* - `--minify, -m` - Enable minification
|
|
136
231
|
* - `--skip-typecheck, -s` - Skip type checking
|
|
@@ -140,18 +235,14 @@ export interface Sandbox {
|
|
|
140
235
|
* let bundleResult: BundleResult | null = null;
|
|
141
236
|
*
|
|
142
237
|
* const sandbox = await createSandbox({
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* compilerOptions: { target: "ES2020", strict: true }
|
|
149
|
-
* }),
|
|
150
|
-
* },
|
|
238
|
+
* initialFiles: {
|
|
239
|
+
* '/src/index.ts': 'export const hello = "world";',
|
|
240
|
+
* '/tsconfig.json': JSON.stringify({
|
|
241
|
+
* compilerOptions: { target: 'ES2020', strict: true }
|
|
242
|
+
* }),
|
|
151
243
|
* },
|
|
152
244
|
* onBuild: (result) => {
|
|
153
245
|
* bundleResult = result;
|
|
154
|
-
* // Could also: dynamically import, halt agent, etc.
|
|
155
246
|
* },
|
|
156
247
|
* });
|
|
157
248
|
*
|
|
@@ -159,27 +250,18 @@ export interface Sandbox {
|
|
|
159
250
|
* await sandbox.bash.exec('echo "console.log(1);" > /src/index.ts');
|
|
160
251
|
*
|
|
161
252
|
* // Type check
|
|
162
|
-
* const tscResult = await sandbox.bash.exec(
|
|
253
|
+
* const tscResult = await sandbox.bash.exec('tsc /src/index.ts');
|
|
163
254
|
* console.log(tscResult.stdout);
|
|
164
255
|
*
|
|
165
256
|
* // Build (includes typecheck, triggers onBuild callback)
|
|
166
|
-
* const buildResult = await sandbox.bash.exec(
|
|
257
|
+
* const buildResult = await sandbox.bash.exec('build /src/index.ts');
|
|
167
258
|
* console.log(buildResult.stdout);
|
|
168
259
|
* console.log(bundleResult?.code); // The compiled bundle
|
|
169
260
|
*
|
|
170
|
-
* // Save
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* // Clean up
|
|
174
|
-
* sandbox.close();
|
|
261
|
+
* // Save state for later
|
|
262
|
+
* const state = sandbox.getState();
|
|
263
|
+
* localStorage.setItem('my-project', JSON.stringify(state));
|
|
175
264
|
* ```
|
|
176
265
|
*/
|
|
177
266
|
export declare function createSandbox(options?: SandboxOptions): Promise<Sandbox>;
|
|
178
|
-
/**
|
|
179
|
-
* Create an in-memory sandbox (no IndexedDB persistence).
|
|
180
|
-
* Useful for testing or temporary workspaces.
|
|
181
|
-
*/
|
|
182
|
-
export declare function createInMemorySandbox(options?: Omit<SandboxOptions, "fsOptions"> & {
|
|
183
|
-
initialFiles?: Record<string, string>;
|
|
184
|
-
}): Promise<Sandbox>;
|
|
185
267
|
//# sourceMappingURL=sandbox.d.ts.map
|
package/dist/sandbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAA0B,MAAM,MAAM,CAAC;AAE1D,OAAO,EAA2C,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC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sBG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC;IAE7E;;;;;;;;;;;;;;;;;;OAkBG;IACH,aAAa,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CAAC;IAEpC;;;OAGG;IACH,eAAe,IAAI,IAAI,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAsB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CA8GlF"}
|
package/dist/shared-modules.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* });
|
|
22
22
|
*
|
|
23
23
|
* // Now create sandbox with sharedModules option
|
|
24
|
-
* const sandbox = await
|
|
24
|
+
* const sandbox = await createSandbox({
|
|
25
25
|
* sharedModules: ['react', 'react-dom/client'],
|
|
26
26
|
* });
|
|
27
27
|
* ```
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
*/
|
|
34
34
|
export declare class SharedModuleRegistry {
|
|
35
35
|
private modules;
|
|
36
|
+
private exportNames;
|
|
36
37
|
constructor();
|
|
37
38
|
/**
|
|
38
|
-
* Register a module to be shared with dynamic bundles
|
|
39
|
+
* Register a module to be shared with dynamic bundles.
|
|
40
|
+
* Automatically introspects the module to discover its exports.
|
|
39
41
|
*
|
|
40
42
|
* @param moduleId - The import specifier (e.g., 'react', 'react-dom/client')
|
|
41
43
|
* @param module - The module's exports object
|
|
@@ -43,7 +45,8 @@ export declare class SharedModuleRegistry {
|
|
|
43
45
|
*/
|
|
44
46
|
register(moduleId: string, module: unknown): this;
|
|
45
47
|
/**
|
|
46
|
-
* Register multiple modules at once
|
|
48
|
+
* Register multiple modules at once.
|
|
49
|
+
* Automatically introspects each module to discover its exports.
|
|
47
50
|
*
|
|
48
51
|
* @param modules - Object mapping module IDs to their exports
|
|
49
52
|
* @returns this for chaining
|
|
@@ -74,6 +77,14 @@ export declare class SharedModuleRegistry {
|
|
|
74
77
|
* Get list of all registered module IDs
|
|
75
78
|
*/
|
|
76
79
|
list(): string[];
|
|
80
|
+
/**
|
|
81
|
+
* Get the export names for a registered module.
|
|
82
|
+
* These were discovered by introspecting the module at registration time.
|
|
83
|
+
*
|
|
84
|
+
* @param moduleId - The import specifier
|
|
85
|
+
* @returns Array of export names, or empty array if not registered
|
|
86
|
+
*/
|
|
87
|
+
getExportNames(moduleId: string): string[];
|
|
77
88
|
/**
|
|
78
89
|
* Clear all registrations
|
|
79
90
|
*/
|
|
@@ -121,6 +132,14 @@ export declare function unregisterSharedModule(moduleId: string): boolean;
|
|
|
121
132
|
* Clear all shared modules from the default registry.
|
|
122
133
|
*/
|
|
123
134
|
export declare function clearSharedModules(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Get the export names for a registered shared module.
|
|
137
|
+
* Used by the bundler to generate proper re-export statements.
|
|
138
|
+
*
|
|
139
|
+
* @param moduleId - The import specifier
|
|
140
|
+
* @returns Array of export names, or empty array if not registered
|
|
141
|
+
*/
|
|
142
|
+
export declare function getSharedModuleExports(moduleId: string): string[];
|
|
124
143
|
/**
|
|
125
144
|
* Generate the runtime code that dynamic bundles use to access shared modules.
|
|
126
145
|
* This is injected into bundles when they import from shared modules.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-modules.d.ts","sourceRoot":"","sources":["../src/shared-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,OAAO,CAA8B;;
|
|
1
|
+
{"version":3,"file":"shared-modules.d.ts","sourceRoot":"","sources":["../src/shared-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH;;;;GAIG;AACH,qBAAa,oBAAoB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|
|
6
6
|
* - esbuild WASM (~10MB) - singleton bundler initialization
|
|
7
7
|
* - Types cache - avoids redundant network fetches when multiple sandboxes
|
|
8
8
|
* install the same packages
|
|
9
|
-
*
|
|
10
|
-
* This module consolidates what was previously scattered across
|
|
11
|
-
* sandbox.ts and sandbox-manager.ts into a single source of truth.
|
|
12
9
|
*/
|
|
13
10
|
import { type TypesCache } from "./packages";
|
|
14
11
|
export type { TypesCache } from "./packages";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-resources.d.ts","sourceRoot":"","sources":["../src/shared-resources.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shared-resources.d.ts","sourceRoot":"","sources":["../src/shared-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAGjE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE9B;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;OAIG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,eAAe,CAAC,CAqB1B;AAWD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,eAAe,CAAC,CAapE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C"}
|
package/dist/ts-libs.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* TypeScript standard library fetcher and cache.
|
|
3
3
|
*
|
|
4
4
|
* Fetches TypeScript's lib.*.d.ts files from jsDelivr CDN and caches
|
|
5
|
-
* them in
|
|
6
|
-
*
|
|
5
|
+
* them in memory. These files provide types for built-in JavaScript APIs
|
|
6
|
+
* (Array, Number, String) and browser APIs (console, window, document).
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Default libs for browser environment with ES2020 target.
|
|
@@ -46,21 +46,15 @@ export declare function fetchLibFile(name: string): Promise<string>;
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function fetchAllLibs(libs: string[]): Promise<Map<string, string>>;
|
|
48
48
|
/**
|
|
49
|
-
* LibCache provides
|
|
49
|
+
* LibCache provides in-memory caching for TypeScript lib files.
|
|
50
50
|
*
|
|
51
51
|
* Usage:
|
|
52
52
|
* ```ts
|
|
53
|
-
* const cache =
|
|
53
|
+
* const cache = new LibCache();
|
|
54
54
|
* const libs = await cache.getOrFetch(getDefaultBrowserLibs());
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
57
|
export declare class LibCache {
|
|
58
|
-
private db;
|
|
59
|
-
private constructor();
|
|
60
|
-
/**
|
|
61
|
-
* Create and initialize a LibCache instance.
|
|
62
|
-
*/
|
|
63
|
-
static create(): Promise<LibCache>;
|
|
64
58
|
/**
|
|
65
59
|
* Get cached libs if available, otherwise fetch from CDN and cache.
|
|
66
60
|
*
|
|
@@ -71,25 +65,18 @@ export declare class LibCache {
|
|
|
71
65
|
/**
|
|
72
66
|
* Get cached libs if available.
|
|
73
67
|
*/
|
|
74
|
-
get():
|
|
68
|
+
get(): Map<string, string> | null;
|
|
75
69
|
/**
|
|
76
70
|
* Store libs in the cache.
|
|
77
71
|
*/
|
|
78
|
-
set(libs: Map<string, string>):
|
|
72
|
+
set(libs: Map<string, string>): void;
|
|
79
73
|
/**
|
|
80
74
|
* Clear all cached libs.
|
|
81
75
|
*/
|
|
82
|
-
clear():
|
|
83
|
-
/**
|
|
84
|
-
* Close the database connection.
|
|
85
|
-
*/
|
|
86
|
-
close(): void;
|
|
76
|
+
clear(): void;
|
|
87
77
|
}
|
|
88
78
|
/**
|
|
89
79
|
* Convenience function to fetch and cache libs in one call.
|
|
90
|
-
* Creates a temporary LibCache, fetches libs, and returns the result.
|
|
91
|
-
*
|
|
92
|
-
* For repeated use, prefer creating a LibCache instance directly.
|
|
93
80
|
*
|
|
94
81
|
* @param libs - Lib names to fetch (defaults to getDefaultBrowserLibs())
|
|
95
82
|
* @returns Map of lib name to content
|
package/dist/ts-libs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-libs.d.ts","sourceRoot":"","sources":["../src/ts-libs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"ts-libs.d.ts","sourceRoot":"","sources":["../src/ts-libs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAY5D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG9D;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAUhE;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA6C/E;AAQD;;;;;;;;GAQG;AACH,qBAAa,QAAQ;IACnB;;;;;OAKG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAuB9D;;OAEG;IACH,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAIjC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAIpC;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,GAAE,MAAM,EAA4B,GACvC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAG9B"}
|
package/dist/typechecker.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sandlot",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "TypeScript sandbox with esbuild bundling and type checking for browser and server",
|
|
5
5
|
"author": "blindmansion",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"typescript": "^5.9.3"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"
|
|
47
|
+
"esbuild": ">=0.20.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
|
-
"
|
|
50
|
+
"esbuild": {
|
|
51
51
|
"optional": true
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/bun": "latest",
|
|
56
56
|
"@types/react": "^19",
|
|
57
|
-
"
|
|
57
|
+
"esbuild": "^0.27.2"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/src/build-emitter.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Build event emitter for sandbox environments.
|
|
3
3
|
*
|
|
4
|
-
* Simple typed event emitter for build results.
|
|
5
|
-
*
|
|
4
|
+
* Simple typed event emitter for successful build results.
|
|
5
|
+
* Used internally by the sandbox to notify listeners when a build succeeds.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { BuildOutput } from "./commands/types";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Simple typed event emitter for build results.
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
|
+
* Only emits on successful builds—build failures are communicated via
|
|
14
|
+
* the bash command's exit code and stderr.
|
|
15
|
+
*
|
|
16
|
+
* For most use cases, prefer using `createBuilder()` which handles
|
|
17
|
+
* build result capture automatically.
|
|
13
18
|
*/
|
|
14
19
|
export class BuildEmitter {
|
|
15
|
-
private listeners = new Set<(result:
|
|
16
|
-
private lastResult: BundleResult | null = null;
|
|
20
|
+
private listeners = new Set<(result: BuildOutput) => void | Promise<void>>();
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
|
-
* Emit a build result to all listeners
|
|
23
|
+
* Emit a build result to all listeners.
|
|
24
|
+
* Called internally when a build command succeeds.
|
|
20
25
|
*/
|
|
21
|
-
emit = async (result:
|
|
22
|
-
this.lastResult = result;
|
|
26
|
+
emit = async (result: BuildOutput): Promise<void> => {
|
|
23
27
|
const promises: Promise<void>[] = [];
|
|
24
28
|
for (const listener of this.listeners) {
|
|
25
29
|
const ret = listener(result);
|
|
@@ -32,30 +36,29 @@ export class BuildEmitter {
|
|
|
32
36
|
|
|
33
37
|
/**
|
|
34
38
|
* Subscribe to build events. Returns an unsubscribe function.
|
|
39
|
+
*
|
|
40
|
+
* The callback is invoked each time a build succeeds, receiving
|
|
41
|
+
* the BuildOutput with the bundle and loaded module.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* let lastBuild: BuildOutput | null = null;
|
|
46
|
+
* const unsubscribe = sandbox.onBuild((result) => {
|
|
47
|
+
* lastBuild = result;
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* await sandbox.bash.exec('build /src/index.ts');
|
|
51
|
+
* unsubscribe();
|
|
52
|
+
*
|
|
53
|
+
* if (lastBuild) {
|
|
54
|
+
* const App = lastBuild.module.App as React.ComponentType;
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
35
57
|
*/
|
|
36
|
-
on(callback: (result:
|
|
58
|
+
on(callback: (result: BuildOutput) => void | Promise<void>): () => void {
|
|
37
59
|
this.listeners.add(callback);
|
|
38
60
|
return () => {
|
|
39
61
|
this.listeners.delete(callback);
|
|
40
62
|
};
|
|
41
63
|
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Get the last build result, or wait for the next one if none exists.
|
|
45
|
-
* Clears the cached result after returning, so subsequent calls wait for new builds.
|
|
46
|
-
*/
|
|
47
|
-
waitFor(): Promise<BundleResult> {
|
|
48
|
-
if (this.lastResult) {
|
|
49
|
-
const result = this.lastResult;
|
|
50
|
-
this.lastResult = null;
|
|
51
|
-
return Promise.resolve(result);
|
|
52
|
-
}
|
|
53
|
-
return new Promise((resolve) => {
|
|
54
|
-
const unsub = this.on((result) => {
|
|
55
|
-
unsub();
|
|
56
|
-
this.lastResult = null;
|
|
57
|
-
resolve(result);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
64
|
}
|