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/commands/types.ts
CHANGED
|
@@ -1,172 +1,144 @@
|
|
|
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
|
+
BuildFailureDetails,
|
|
14
|
+
TypecheckResult,
|
|
15
|
+
SandboxBuildOptions,
|
|
16
|
+
SandboxTypecheckOptions,
|
|
17
|
+
RunOptions,
|
|
18
|
+
RunResult,
|
|
19
|
+
BundleError,
|
|
20
|
+
Diagnostic,
|
|
21
|
+
} from "../types";
|
|
8
22
|
|
|
9
23
|
/**
|
|
10
|
-
*
|
|
24
|
+
* Reference to sandbox methods that commands can call.
|
|
25
|
+
*
|
|
26
|
+
* Commands receive this interface rather than raw dependencies,
|
|
27
|
+
* ensuring they use the same logic as direct API calls.
|
|
11
28
|
*/
|
|
12
|
-
export interface
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
bundle: BundleResult;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The loaded module exports.
|
|
20
|
-
* If validation was provided, this is the validated module.
|
|
21
|
-
*/
|
|
22
|
-
module: Record<string, unknown>;
|
|
23
|
-
}
|
|
29
|
+
export interface SandboxRef {
|
|
30
|
+
/** The virtual filesystem */
|
|
31
|
+
readonly fs: Filesystem;
|
|
24
32
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
* Takes the raw module exports and returns validated exports (or throws).
|
|
28
|
-
*/
|
|
29
|
-
export type ValidateFn = (module: Record<string, unknown>) => Record<string, unknown>;
|
|
33
|
+
/** Install a package */
|
|
34
|
+
install(packageSpec: string): Promise<InstallResult>;
|
|
30
35
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
|
|
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[];
|
|
36
|
+
/** Uninstall a package */
|
|
37
|
+
uninstall(packageName: string): Promise<UninstallResult>;
|
|
38
|
+
|
|
39
|
+
/** Build the project */
|
|
40
|
+
build(options?: SandboxBuildOptions): Promise<BuildResult>;
|
|
41
|
+
|
|
42
|
+
/** Type check the project */
|
|
43
|
+
typecheck(options?: SandboxTypecheckOptions): Promise<TypecheckResult>;
|
|
44
|
+
|
|
45
|
+
/** Run code (build + execute) */
|
|
46
|
+
run(options?: RunOptions): Promise<RunResult>;
|
|
80
47
|
}
|
|
81
48
|
|
|
82
49
|
/**
|
|
83
|
-
*
|
|
84
|
-
* This provides sandboxed code with access to sandbox capabilities.
|
|
50
|
+
* Format a file size in bytes to a human-readable string
|
|
85
51
|
*/
|
|
86
|
-
export
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
fs: IFileSystem;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Environment variables (configurable per-sandbox)
|
|
94
|
-
*/
|
|
95
|
-
env: Record<string, string>;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Command-line arguments passed to `run`
|
|
99
|
-
*/
|
|
100
|
-
args: string[];
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Explicit logging function (alternative to console.log)
|
|
104
|
-
*/
|
|
105
|
-
log: (...args: unknown[]) => void;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Explicit error logging function (alternative to console.error)
|
|
109
|
-
*/
|
|
110
|
-
error: (...args: unknown[]) => void;
|
|
52
|
+
export function formatSize(bytes: number): string {
|
|
53
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
54
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
55
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
111
56
|
}
|
|
112
57
|
|
|
113
58
|
/**
|
|
114
|
-
*
|
|
59
|
+
* Format diagnostics for shell output
|
|
115
60
|
*/
|
|
116
|
-
export
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
* Whether to skip type checking before running (default: false)
|
|
130
|
-
*/
|
|
131
|
-
skipTypecheck?: boolean;
|
|
61
|
+
export function formatDiagnostics(diagnostics: Diagnostic[]): string {
|
|
62
|
+
if (diagnostics.length === 0) return "";
|
|
63
|
+
|
|
64
|
+
return diagnostics
|
|
65
|
+
.map((d) => {
|
|
66
|
+
const severity = d.severity.toUpperCase();
|
|
67
|
+
if (d.file) {
|
|
68
|
+
const loc = `${d.file}${d.line ? `:${d.line}` : ""}${d.column ? `:${d.column}` : ""}`;
|
|
69
|
+
return `${severity}: ${loc}: ${d.message}`;
|
|
70
|
+
}
|
|
71
|
+
return `${severity}: ${d.message}`;
|
|
72
|
+
})
|
|
73
|
+
.join("\n");
|
|
132
74
|
}
|
|
133
75
|
|
|
134
76
|
/**
|
|
135
|
-
*
|
|
77
|
+
* Format bundle errors for shell output
|
|
136
78
|
*/
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
79
|
+
export function formatBundleErrors(errors: BundleError[]): string {
|
|
80
|
+
if (errors.length === 0) return "";
|
|
81
|
+
|
|
82
|
+
return errors
|
|
83
|
+
.map((e) => {
|
|
84
|
+
let output = "";
|
|
85
|
+
|
|
86
|
+
// Location header
|
|
87
|
+
if (e.location) {
|
|
88
|
+
const loc = `${e.location.file}:${e.location.line}${e.location.column ? `:${e.location.column}` : ""}`;
|
|
89
|
+
output += `ERROR: ${loc}: ${e.text}`;
|
|
90
|
+
|
|
91
|
+
// Show source line if available
|
|
92
|
+
if (e.location.lineText) {
|
|
93
|
+
output += `\n ${e.location.line} | ${e.location.lineText}`;
|
|
94
|
+
// Add caret pointing to column
|
|
95
|
+
if (e.location.column) {
|
|
96
|
+
const padding = " ".repeat(
|
|
97
|
+
String(e.location.line).length + 3 + e.location.column - 1
|
|
98
|
+
);
|
|
99
|
+
output += `\n${padding}^`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
output += `ERROR: ${e.text}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return output;
|
|
107
|
+
})
|
|
108
|
+
.join("\n\n");
|
|
152
109
|
}
|
|
153
110
|
|
|
154
111
|
/**
|
|
155
|
-
* Format
|
|
112
|
+
* Format a build failure for shell output.
|
|
113
|
+
* Used by both build and run commands for consistent error formatting.
|
|
114
|
+
*
|
|
115
|
+
* @param failure - The build failure details
|
|
116
|
+
* @param prefix - Optional prefix for the error message (default: "Build failed")
|
|
156
117
|
*/
|
|
157
|
-
export function
|
|
158
|
-
|
|
118
|
+
export function formatBuildFailure(
|
|
119
|
+
failure: BuildFailureDetails,
|
|
120
|
+
prefix = "Build failed"
|
|
159
121
|
): string {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
122
|
+
switch (failure.phase) {
|
|
123
|
+
case "entry":
|
|
124
|
+
return `${prefix}: ${failure.message}\n`;
|
|
125
|
+
|
|
126
|
+
case "typecheck":
|
|
127
|
+
if (failure.diagnostics && failure.diagnostics.length > 0) {
|
|
128
|
+
const errors = failure.diagnostics.filter((d) => d.severity === "error");
|
|
129
|
+
if (errors.length > 0) {
|
|
130
|
+
return `${prefix}: Type check errors\n\n${formatDiagnostics(errors)}\n`;
|
|
131
|
+
}
|
|
168
132
|
}
|
|
169
|
-
return
|
|
170
|
-
|
|
171
|
-
|
|
133
|
+
return `${prefix}: Type check errors\n`;
|
|
134
|
+
|
|
135
|
+
case "bundle":
|
|
136
|
+
if (failure.bundleErrors && failure.bundleErrors.length > 0) {
|
|
137
|
+
return `${prefix}: Bundle errors\n\n${formatBundleErrors(failure.bundleErrors)}\n`;
|
|
138
|
+
}
|
|
139
|
+
return `${prefix}: Bundle error\n`;
|
|
140
|
+
|
|
141
|
+
default:
|
|
142
|
+
return `${prefix}: Unknown error\n`;
|
|
143
|
+
}
|
|
172
144
|
}
|