sandlot 0.1.3 → 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.
- 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 +2692 -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 +31 -132
- 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 +1405 -2049
- 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 +2646 -0
- package/dist/node/preset.d.ts +62 -0
- package/dist/node/preset.d.ts.map +1 -0
- package/dist/types.d.ts +525 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +27 -8
- 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 +526 -43
- package/src/commands/types.ts +82 -146
- 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 +621 -0
- package/src/core/sandlot.ts +77 -0
- package/src/core/shared-module-registry.ts +138 -0
- package/src/core/typechecker.ts +607 -0
- package/src/index.ts +104 -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 +668 -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 -148
- 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 -1976
- 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 -98
- 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 -542
- 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 -396
- package/src/shared-modules.ts +0 -280
- package/src/shared-resources.ts +0 -166
- package/src/ts-libs.ts +0 -320
- package/src/typechecker.ts +0 -635
package/src/commands/types.ts
CHANGED
|
@@ -1,172 +1,108 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Types and utilities for sandbox bash commands.
|
|
2
|
+
* Types and utilities for v2 sandbox bash commands.
|
|
3
|
+
*
|
|
4
|
+
* Commands wrap the sandbox's direct methods to provide a shell interface.
|
|
5
|
+
* This ensures consistency between `sandbox.build()` and `sandbox.exec('sandlot build')`.
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
import type {
|
|
9
|
+
Filesystem,
|
|
10
|
+
InstallResult,
|
|
11
|
+
UninstallResult,
|
|
12
|
+
BuildResult,
|
|
13
|
+
TypecheckResult,
|
|
14
|
+
SandboxBuildOptions,
|
|
15
|
+
SandboxTypecheckOptions,
|
|
16
|
+
RunOptions,
|
|
17
|
+
RunResult,
|
|
18
|
+
BundleError,
|
|
19
|
+
Diagnostic,
|
|
20
|
+
} from "../types";
|
|
8
21
|
|
|
9
22
|
/**
|
|
10
|
-
*
|
|
23
|
+
* Reference to sandbox methods that commands can call.
|
|
24
|
+
*
|
|
25
|
+
* Commands receive this interface rather than raw dependencies,
|
|
26
|
+
* ensuring they use the same logic as direct API calls.
|
|
11
27
|
*/
|
|
12
|
-
export interface
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
bundle: BundleResult;
|
|
28
|
+
export interface SandboxRef {
|
|
29
|
+
/** The virtual filesystem */
|
|
30
|
+
readonly fs: Filesystem;
|
|
17
31
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
* If validation was provided, this is the validated module.
|
|
21
|
-
*/
|
|
22
|
-
module: Record<string, unknown>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Validation function type for module validation.
|
|
27
|
-
* Takes the raw module exports and returns validated exports (or throws).
|
|
28
|
-
*/
|
|
29
|
-
export type ValidateFn = (module: Record<string, unknown>) => Record<string, unknown>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Dependencies required by command factories
|
|
33
|
-
*/
|
|
34
|
-
export interface CommandDeps {
|
|
35
|
-
/**
|
|
36
|
-
* The virtual filesystem to operate on
|
|
37
|
-
*/
|
|
38
|
-
fs: IFileSystem;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Pre-loaded TypeScript lib files for type checking
|
|
42
|
-
*/
|
|
43
|
-
libFiles: Map<string, string>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Path to tsconfig.json in the virtual filesystem
|
|
47
|
-
*/
|
|
48
|
-
tsconfigPath: string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Callback invoked when a build succeeds (after loading and validation).
|
|
52
|
-
*/
|
|
53
|
-
onBuild?: (result: BuildOutput) => void | Promise<void>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Getter for the current validation function.
|
|
57
|
-
* Called during build to check if validation should be performed.
|
|
58
|
-
*/
|
|
59
|
-
getValidation?: () => ValidateFn | null;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Cache for package type definitions.
|
|
63
|
-
* When provided, avoids redundant network fetches for packages
|
|
64
|
-
* that have already been installed in other sandboxes.
|
|
65
|
-
*/
|
|
66
|
-
typesCache?: TypesCache;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Options for the `run` command
|
|
70
|
-
*/
|
|
71
|
-
runOptions?: RunOptions;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Module IDs that should be resolved from the host's SharedModuleRegistry
|
|
75
|
-
* instead of esm.sh CDN. The host must have registered these modules.
|
|
76
|
-
*
|
|
77
|
-
* Example: ['react', 'react-dom/client']
|
|
78
|
-
*/
|
|
79
|
-
sharedModules?: string[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Runtime context passed to the `main()` function when code is executed.
|
|
84
|
-
* This provides sandboxed code with access to sandbox capabilities.
|
|
85
|
-
*/
|
|
86
|
-
export interface RunContext {
|
|
87
|
-
/**
|
|
88
|
-
* The virtual filesystem - read/write files within the sandbox
|
|
89
|
-
*/
|
|
90
|
-
fs: IFileSystem;
|
|
32
|
+
/** Install a package */
|
|
33
|
+
install(packageSpec: string): Promise<InstallResult>;
|
|
91
34
|
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
*/
|
|
95
|
-
env: Record<string, string>;
|
|
35
|
+
/** Uninstall a package */
|
|
36
|
+
uninstall(packageName: string): Promise<UninstallResult>;
|
|
96
37
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
args: string[];
|
|
38
|
+
/** Build the project */
|
|
39
|
+
build(options?: SandboxBuildOptions): Promise<BuildResult>;
|
|
101
40
|
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
*/
|
|
105
|
-
log: (...args: unknown[]) => void;
|
|
41
|
+
/** Type check the project */
|
|
42
|
+
typecheck(options?: SandboxTypecheckOptions): Promise<TypecheckResult>;
|
|
106
43
|
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
*/
|
|
110
|
-
error: (...args: unknown[]) => void;
|
|
44
|
+
/** Run code (build + execute) */
|
|
45
|
+
run(options?: RunOptions): Promise<RunResult>;
|
|
111
46
|
}
|
|
112
47
|
|
|
113
48
|
/**
|
|
114
|
-
*
|
|
49
|
+
* Format a file size in bytes to a human-readable string
|
|
115
50
|
*/
|
|
116
|
-
export
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
env?: Record<string, string>;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Maximum execution time in milliseconds (default: 30000 = 30s)
|
|
124
|
-
* Set to 0 to disable timeout.
|
|
125
|
-
*/
|
|
126
|
-
timeout?: number;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Whether to skip type checking before running (default: false)
|
|
130
|
-
*/
|
|
131
|
-
skipTypecheck?: boolean;
|
|
51
|
+
export function formatSize(bytes: number): string {
|
|
52
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
53
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
54
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
132
55
|
}
|
|
133
56
|
|
|
134
57
|
/**
|
|
135
|
-
*
|
|
58
|
+
* Format diagnostics for shell output
|
|
136
59
|
*/
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*/
|
|
151
|
-
executionTimeMs: number;
|
|
60
|
+
export function formatDiagnostics(diagnostics: Diagnostic[]): string {
|
|
61
|
+
if (diagnostics.length === 0) return "";
|
|
62
|
+
|
|
63
|
+
return diagnostics
|
|
64
|
+
.map((d) => {
|
|
65
|
+
const severity = d.severity.toUpperCase();
|
|
66
|
+
if (d.file) {
|
|
67
|
+
const loc = `${d.file}${d.line ? `:${d.line}` : ""}${d.column ? `:${d.column}` : ""}`;
|
|
68
|
+
return `${severity}: ${loc}: ${d.message}`;
|
|
69
|
+
}
|
|
70
|
+
return `${severity}: ${d.message}`;
|
|
71
|
+
})
|
|
72
|
+
.join("\n");
|
|
152
73
|
}
|
|
153
74
|
|
|
154
75
|
/**
|
|
155
|
-
* Format
|
|
76
|
+
* Format bundle errors for shell output
|
|
156
77
|
*/
|
|
157
|
-
export function
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const loc =
|
|
167
|
-
|
|
78
|
+
export function formatBundleErrors(errors: BundleError[]): string {
|
|
79
|
+
if (errors.length === 0) return "";
|
|
80
|
+
|
|
81
|
+
return errors
|
|
82
|
+
.map((e) => {
|
|
83
|
+
let output = "";
|
|
84
|
+
|
|
85
|
+
// Location header
|
|
86
|
+
if (e.location) {
|
|
87
|
+
const loc = `${e.location.file}:${e.location.line}${e.location.column ? `:${e.location.column}` : ""}`;
|
|
88
|
+
output += `ERROR: ${loc}: ${e.text}`;
|
|
89
|
+
|
|
90
|
+
// Show source line if available
|
|
91
|
+
if (e.location.lineText) {
|
|
92
|
+
output += `\n ${e.location.line} | ${e.location.lineText}`;
|
|
93
|
+
// Add caret pointing to column
|
|
94
|
+
if (e.location.column) {
|
|
95
|
+
const padding = " ".repeat(
|
|
96
|
+
String(e.location.line).length + 3 + e.location.column - 1
|
|
97
|
+
);
|
|
98
|
+
output += `\n${padding}^`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
output += `ERROR: ${e.text}`;
|
|
168
103
|
}
|
|
169
|
-
|
|
104
|
+
|
|
105
|
+
return output;
|
|
170
106
|
})
|
|
171
|
-
.join("\n");
|
|
107
|
+
.join("\n\n");
|
|
172
108
|
}
|