@innovatorved/code-lab 0.1.13 → 0.3.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/ARCHITECTURE.md +12 -7
- package/CHANGELOG.md +134 -0
- package/README.md +59 -9
- package/dist/code-lab.css +198 -0
- package/dist/code-lab.d.ts +37 -7
- package/dist/code-lab.esm.js +20444 -1278
- package/dist/code-lab.js +20439 -1276
- package/dist/extensions/cpp.d.ts +145 -0
- package/dist/extensions/cpp.esm.js +5932 -0
- package/dist/extensions/cpp.js +5951 -0
- package/dist/extensions/guided-lab.esm.js +86 -6
- package/dist/extensions/guided-lab.js +87 -6
- package/dist/extensions/javascript.d.ts +24 -0
- package/dist/extensions/javascript.esm.js +36 -0
- package/dist/extensions/javascript.js +59 -0
- package/dist/extensions/python.d.ts +92 -0
- package/dist/extensions/python.esm.js +5476 -0
- package/dist/extensions/python.js +5495 -0
- package/dist/extensions/typescript.d.ts +36 -0
- package/dist/extensions/typescript.esm.js +55 -0
- package/dist/extensions/typescript.js +78 -0
- package/dist/index.d.ts +9 -3
- package/dist/preview-sw.js +1 -1
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/module-loader.d.ts +11 -0
- package/dist/runtime/test-harness.d.ts +24 -0
- package/dist/runtime/vfs.d.ts +31 -0
- package/dist/runtime/wasi-host.d.ts +33 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.esm.js +920 -15
- package/dist/runtime.js +914 -15
- package/dist/schemas.d.ts +237 -25
- package/dist/schemas.esm.js +85 -6
- package/dist/schemas.js +85 -6
- package/dist/shell/coreutils/compilers-cli.d.ts +24 -0
- package/dist/shell/index.d.ts +4 -0
- package/dist/shell/lexer-parser.d.ts +26 -0
- package/dist/shell.esm.js +289 -4
- package/dist/shell.js +289 -4
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/dist/workbench/command-palette.d.ts +10 -0
- package/dist/workbench/diff-editor.d.ts +26 -0
- package/dist/workbench/drawer.d.ts +18 -0
- package/dist/workbench/editor.d.ts +11 -0
- package/dist/workbench/file-tree.d.ts +11 -0
- package/dist/workbench/guided-pane.d.ts +11 -0
- package/dist/workbench/icons.d.ts +5 -0
- package/dist/workbench/index.d.ts +39 -0
- package/dist/workbench/share.d.ts +21 -0
- package/dist/workbench/styles.d.ts +4 -0
- package/dist/workbench/toolbar.d.ts +17 -0
- package/dist/workbench.d.ts +6 -1
- package/package.json +33 -3
- package/src/code-lab.css +198 -0
- package/src/extensions/cpp.ts +1786 -0
- package/src/extensions/guided-lab.ts +10 -0
- package/src/extensions/javascript.ts +54 -0
- package/src/extensions/python.ts +1293 -0
- package/src/extensions/typescript.ts +85 -0
- package/src/index.ts +66 -3
- package/src/runtime/index.ts +5 -0
- package/src/runtime/test-harness.ts +57 -0
- package/src/runtime.ts +915 -14
- package/src/schemas.ts +94 -7
- package/src/shell/coreutils/compilers-cli.ts +103 -0
- package/src/shell/index.ts +5 -0
- package/src/shell.ts +288 -3
- package/src/workbench/command-palette.ts +140 -0
- package/src/workbench/diff-editor.ts +216 -0
- package/src/workbench/drawer.ts +148 -0
- package/src/workbench/editor.ts +49 -0
- package/src/workbench/file-tree.ts +51 -0
- package/src/workbench/guided-pane.ts +33 -0
- package/src/workbench/icons.ts +48 -0
- package/src/workbench/index.ts +38 -0
- package/src/workbench/share.ts +99 -0
- package/src/workbench/styles.ts +200 -0
- package/src/workbench/toolbar.ts +171 -0
- package/src/workbench.ts +1016 -78
package/dist/schemas.js
CHANGED
|
@@ -21,6 +21,8 @@ var schemas_exports = {};
|
|
|
21
21
|
__export(schemas_exports, {
|
|
22
22
|
CloneProgressEventSchema: () => CloneProgressEventSchema,
|
|
23
23
|
CloneProgressPhaseSchema: () => CloneProgressPhaseSchema,
|
|
24
|
+
CppExtensionOptionsSchema: () => CppExtensionOptionsSchema,
|
|
25
|
+
CppToolchainProgressSchema: () => CppToolchainProgressSchema,
|
|
24
26
|
DiagnosticItemSchema: () => DiagnosticItemSchema,
|
|
25
27
|
DiagnosticSeveritySchema: () => DiagnosticSeveritySchema,
|
|
26
28
|
GitFileChangeTypeSchema: () => GitFileChangeTypeSchema,
|
|
@@ -30,6 +32,10 @@ __export(schemas_exports, {
|
|
|
30
32
|
GuidedLabExtensionOptionsSchema: () => GuidedLabExtensionOptionsSchema,
|
|
31
33
|
GuidedStepSchema: () => GuidedStepSchema,
|
|
32
34
|
LanguageBundleSchema: () => LanguageBundleSchema,
|
|
35
|
+
LanguageEnum: () => LanguageEnum,
|
|
36
|
+
LanguageIdSchema: () => LanguageIdSchema,
|
|
37
|
+
PythonExtensionOptionsSchema: () => PythonExtensionOptionsSchema,
|
|
38
|
+
PythonToolchainProgressSchema: () => PythonToolchainProgressSchema,
|
|
33
39
|
RuntimeExecuteOptionsSchema: () => RuntimeExecuteOptionsSchema,
|
|
34
40
|
SearchOptionsSchema: () => SearchOptionsSchema,
|
|
35
41
|
StoredProjectSchema: () => StoredProjectSchema,
|
|
@@ -4092,8 +4098,10 @@ var GuidedStepSchema = external_exports.object({
|
|
|
4092
4098
|
hint: external_exports.string().optional(),
|
|
4093
4099
|
testNames: external_exports.array(external_exports.string()).optional()
|
|
4094
4100
|
});
|
|
4101
|
+
var LanguageIdSchema = external_exports.enum(["js", "ts", "cpp", "py"]);
|
|
4102
|
+
var LanguageEnum = LanguageIdSchema;
|
|
4095
4103
|
var LanguageBundleSchema = external_exports.object({
|
|
4096
|
-
language:
|
|
4104
|
+
language: LanguageIdSchema.default("js"),
|
|
4097
4105
|
files: external_exports.record(external_exports.string()).default({}),
|
|
4098
4106
|
starterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4099
4107
|
solutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
@@ -4104,17 +4112,77 @@ var GuidedLabExtensionOptionsSchema = external_exports.object({
|
|
|
4104
4112
|
steps: external_exports.array(GuidedStepSchema).default([]),
|
|
4105
4113
|
stepIndex: external_exports.number().int().nonnegative().default(0),
|
|
4106
4114
|
mode: external_exports.enum(["guided", "sandbox"]).default("guided"),
|
|
4107
|
-
language:
|
|
4108
|
-
lang:
|
|
4115
|
+
language: LanguageIdSchema.optional(),
|
|
4116
|
+
lang: LanguageIdSchema.optional(),
|
|
4109
4117
|
starterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4110
4118
|
solutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4111
4119
|
tsStarterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4112
4120
|
tsSolutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4113
4121
|
tsFiles: external_exports.record(external_exports.string()).optional(),
|
|
4122
|
+
cppStarterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4123
|
+
cppSolutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4124
|
+
cppFiles: external_exports.record(external_exports.string()).optional(),
|
|
4125
|
+
pyStarterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4126
|
+
pySolutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4127
|
+
pyFiles: external_exports.record(external_exports.string()).optional(),
|
|
4128
|
+
pyEntry: external_exports.string().optional(),
|
|
4129
|
+
pyTestEntry: external_exports.string().optional(),
|
|
4130
|
+
pyTestCode: external_exports.string().optional(),
|
|
4114
4131
|
summary: external_exports.string().optional(),
|
|
4115
4132
|
onStepComplete: external_exports.function().args(GuidedStepSchema, external_exports.number()).returns(external_exports.void()).optional(),
|
|
4116
4133
|
onLabComplete: external_exports.function().args(external_exports.string()).returns(external_exports.void()).optional()
|
|
4117
4134
|
});
|
|
4135
|
+
var CppToolchainProgressSchema = external_exports.object({
|
|
4136
|
+
stage: external_exports.enum(["downloading", "caching", "extracting", "compiling", "linking", "ready"]),
|
|
4137
|
+
loadedBytes: external_exports.number().optional(),
|
|
4138
|
+
totalBytes: external_exports.number().optional(),
|
|
4139
|
+
percent: external_exports.number().optional(),
|
|
4140
|
+
message: external_exports.string().optional()
|
|
4141
|
+
});
|
|
4142
|
+
var CppExtensionOptionsSchema = external_exports.object({
|
|
4143
|
+
toolchainUrl: external_exports.string().optional(),
|
|
4144
|
+
clangWasmUrl: external_exports.string().optional(),
|
|
4145
|
+
clangUrl: external_exports.string().optional(),
|
|
4146
|
+
lldWasmUrl: external_exports.string().optional(),
|
|
4147
|
+
lldUrl: external_exports.string().optional(),
|
|
4148
|
+
sysrootTarUrl: external_exports.string().optional(),
|
|
4149
|
+
sysrootUrl: external_exports.string().optional(),
|
|
4150
|
+
cacheInIndexedDB: external_exports.boolean().default(true),
|
|
4151
|
+
preload: external_exports.boolean().default(false),
|
|
4152
|
+
std: external_exports.enum(["c++17", "c++20", "c++23"]).default("c++20"),
|
|
4153
|
+
optLevel: external_exports.enum(["-O0", "-O1", "-O2", "-O3"]).default("-O2"),
|
|
4154
|
+
flags: external_exports.array(external_exports.string()).default(["-O2", "-Wall", "-Wextra"]),
|
|
4155
|
+
headers: external_exports.record(external_exports.string()).optional(),
|
|
4156
|
+
extraHeaders: external_exports.record(external_exports.string()).optional(),
|
|
4157
|
+
files: external_exports.record(external_exports.string()).optional(),
|
|
4158
|
+
starterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4159
|
+
solutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4160
|
+
onProgress: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional()
|
|
4161
|
+
});
|
|
4162
|
+
var PythonToolchainProgressSchema = external_exports.object({
|
|
4163
|
+
stage: external_exports.enum(["downloading", "caching", "extracting", "initializing", "ready"]),
|
|
4164
|
+
loadedBytes: external_exports.number().optional(),
|
|
4165
|
+
totalBytes: external_exports.number().optional(),
|
|
4166
|
+
percent: external_exports.number().optional(),
|
|
4167
|
+
message: external_exports.string().optional()
|
|
4168
|
+
});
|
|
4169
|
+
var PythonExtensionOptionsSchema = external_exports.object({
|
|
4170
|
+
cdnBaseUrl: external_exports.string().optional(),
|
|
4171
|
+
indexUrl: external_exports.string().optional(),
|
|
4172
|
+
pyodideIndexUrl: external_exports.string().optional(),
|
|
4173
|
+
cacheInIndexedDB: external_exports.boolean().default(true),
|
|
4174
|
+
preload: external_exports.boolean().default(false),
|
|
4175
|
+
activate: external_exports.boolean().optional(),
|
|
4176
|
+
entry: external_exports.string().default("main.py"),
|
|
4177
|
+
testEntry: external_exports.string().default("test.py"),
|
|
4178
|
+
packages: external_exports.array(external_exports.string()).optional(),
|
|
4179
|
+
preloadPackages: external_exports.array(external_exports.string()).optional(),
|
|
4180
|
+
compilerMemoryLimitMb: external_exports.number().optional(),
|
|
4181
|
+
files: external_exports.record(external_exports.string()).optional(),
|
|
4182
|
+
starterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4183
|
+
solutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4184
|
+
onProgress: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional()
|
|
4185
|
+
});
|
|
4118
4186
|
var CloneProgressPhaseSchema = external_exports.enum([
|
|
4119
4187
|
"connecting",
|
|
4120
4188
|
"metadata",
|
|
@@ -4171,7 +4239,7 @@ var WorkspaceSnapshotSchema = external_exports.object({
|
|
|
4171
4239
|
openTabs: external_exports.array(external_exports.string()).default([]),
|
|
4172
4240
|
activeFile: external_exports.string().nullable().optional(),
|
|
4173
4241
|
mode: external_exports.enum(["guided", "sandbox"]).optional(),
|
|
4174
|
-
lang:
|
|
4242
|
+
lang: LanguageIdSchema.optional(),
|
|
4175
4243
|
labId: external_exports.string().optional()
|
|
4176
4244
|
});
|
|
4177
4245
|
var WorkbenchOptionsSchema = external_exports.object({
|
|
@@ -4207,10 +4275,21 @@ var WorkbenchOptionsSchema = external_exports.object({
|
|
|
4207
4275
|
tsFiles: external_exports.record(external_exports.string()).optional(),
|
|
4208
4276
|
tsStarterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4209
4277
|
tsSolutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4278
|
+
cppFiles: external_exports.record(external_exports.string()).optional(),
|
|
4279
|
+
cppStarterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4280
|
+
cppSolutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4281
|
+
pyFiles: external_exports.record(external_exports.string()).optional(),
|
|
4282
|
+
pyStarterFiles: external_exports.record(external_exports.string()).optional(),
|
|
4283
|
+
pySolutionFiles: external_exports.record(external_exports.string()).optional(),
|
|
4284
|
+
pyEntry: external_exports.string().optional().default("main.py"),
|
|
4285
|
+
pyTestEntry: external_exports.string().optional().default("test.py"),
|
|
4286
|
+
pyTestCode: external_exports.string().optional(),
|
|
4287
|
+
showWebPreview: external_exports.boolean().optional(),
|
|
4288
|
+
stdin: external_exports.string().optional(),
|
|
4210
4289
|
guided: external_exports.any().optional(),
|
|
4211
4290
|
mode: external_exports.enum(["guided", "sandbox"]).optional(),
|
|
4212
|
-
language:
|
|
4213
|
-
lang:
|
|
4291
|
+
language: LanguageIdSchema.optional(),
|
|
4292
|
+
lang: LanguageIdSchema.optional(),
|
|
4214
4293
|
stepIndex: external_exports.number().int().optional(),
|
|
4215
4294
|
onStepComplete: external_exports.function().args(external_exports.any(), external_exports.number()).returns(external_exports.void()).optional(),
|
|
4216
4295
|
onLabComplete: external_exports.function().args(external_exports.string()).returns(external_exports.void()).optional()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @innovatorved/code-lab — Shell Compiler Coreutils
|
|
3
|
+
* Provides `node`, `tsx`, `tsc`, `g++`, `clang++`, `python`, `python3`, `pytest`, `pip`.
|
|
4
|
+
*/
|
|
5
|
+
export interface ShellExecutionContext {
|
|
6
|
+
vfs: any;
|
|
7
|
+
cwd: string;
|
|
8
|
+
env: Record<string, string>;
|
|
9
|
+
resolvePath: (p: string) => string;
|
|
10
|
+
onStdout?: (text: string) => void;
|
|
11
|
+
onStderr?: (text: string) => void;
|
|
12
|
+
shell?: any;
|
|
13
|
+
}
|
|
14
|
+
export interface ShellExecResult {
|
|
15
|
+
code: number;
|
|
16
|
+
stdout: string;
|
|
17
|
+
stderr: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const COMPILER_COREUTILS: {
|
|
20
|
+
python3(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
21
|
+
python(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
22
|
+
pytest(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
23
|
+
pip(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @innovatorved/code-lab — POSIX Shell Lexer & AST Parser
|
|
3
|
+
*/
|
|
4
|
+
export interface ShellToken {
|
|
5
|
+
type: 'word' | 'pipe' | 'redirect_out' | 'redirect_append' | 'redirect_in' | 'and' | 'or' | 'semi' | 'bg';
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ShellCommandNode {
|
|
9
|
+
type: 'command';
|
|
10
|
+
args: string[];
|
|
11
|
+
redirects?: Array<{
|
|
12
|
+
type: string;
|
|
13
|
+
target: string;
|
|
14
|
+
fd?: number;
|
|
15
|
+
}>;
|
|
16
|
+
async?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface ShellPipelineNode {
|
|
19
|
+
type: 'pipeline';
|
|
20
|
+
commands: ShellCommandNode[];
|
|
21
|
+
operator?: '&&' | '||' | ';';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Tokenizes a raw POSIX shell command string safely without eval.
|
|
25
|
+
*/
|
|
26
|
+
export declare function tokenizeShell(cmdString: string): string[];
|
package/dist/shell.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.
|
|
3
|
+
* @innovatorved/code-lab v0.3.0 — Standalone Browser Code IDE & Virtual Runtime
|
|
4
4
|
* ============================================================
|
|
5
5
|
* Features:
|
|
6
6
|
* - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
|
|
@@ -1801,7 +1801,7 @@ var CodeLabLogger = (() => {
|
|
|
1801
1801
|
}
|
|
1802
1802
|
return Array.from(children).sort();
|
|
1803
1803
|
},
|
|
1804
|
-
readFileSync(p) {
|
|
1804
|
+
readFileSync(p, encoding) {
|
|
1805
1805
|
const np = norm(p);
|
|
1806
1806
|
const f = files.get(np);
|
|
1807
1807
|
if (!f) {
|
|
@@ -1809,6 +1809,9 @@ var CodeLabLogger = (() => {
|
|
|
1809
1809
|
err.code = 'ENOENT';
|
|
1810
1810
|
throw err;
|
|
1811
1811
|
}
|
|
1812
|
+
if (!encoding && f.rawBytes instanceof Uint8Array) {
|
|
1813
|
+
return f.rawBytes;
|
|
1814
|
+
}
|
|
1812
1815
|
return f.data;
|
|
1813
1816
|
},
|
|
1814
1817
|
writeFileSync(p, data) {
|
|
@@ -1819,9 +1822,13 @@ var CodeLabLogger = (() => {
|
|
|
1819
1822
|
let cur = '';
|
|
1820
1823
|
for (const pt of parts) { cur += '/' + pt; dirs.add(cur); }
|
|
1821
1824
|
}
|
|
1822
|
-
const
|
|
1825
|
+
const isBinary = data instanceof Uint8Array;
|
|
1826
|
+
const rawBytes = isBinary ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : null;
|
|
1827
|
+
const str = isBinary
|
|
1828
|
+
? new TextDecoder('utf-8').decode(rawBytes)
|
|
1829
|
+
: (typeof data === 'string' ? data : (data && data.toString ? data.toString('utf8') : String(data)));
|
|
1823
1830
|
const prevMode = files.has(np) ? files.get(np).mode : 0o100644;
|
|
1824
|
-
files.set(np, { data: str, mtimeMs: Date.now(), mode: prevMode });
|
|
1831
|
+
files.set(np, { data: str, rawBytes, mtimeMs: Date.now(), mode: prevMode });
|
|
1825
1832
|
},
|
|
1826
1833
|
appendFileSync(p, data) {
|
|
1827
1834
|
const np = norm(p);
|
|
@@ -6048,6 +6055,8 @@ var CodeLabLogger = (() => {
|
|
|
6048
6055
|
stdout += ' history, ps, jobs, kill Process and job management\n';
|
|
6049
6056
|
stdout += ' git [status diff log] Built-in version control\n';
|
|
6050
6057
|
stdout += ' node, bun, npm, pnpm, npx, bunx CLI runtime and package shims\n';
|
|
6058
|
+
stdout += ' g++, clang++, c++ C++20 WebAssembly compiler (via cppExtension)\n';
|
|
6059
|
+
stdout += ' python, python3, pytest Python 3.12 WebAssembly runtime (via pythonExtension)\n';
|
|
6051
6060
|
stdout += ' serve [dir] [--port] Built-in preview server (transpiles TS/JSX for the browser)\n';
|
|
6052
6061
|
stdout += ' ports, curl Port table inspection & HTTP requests\n';
|
|
6053
6062
|
stdout += ' hey, ab, wrk Concurrent HTTP load generator & latency percentiles\n';
|
|
@@ -6166,6 +6175,236 @@ var CodeLabLogger = (() => {
|
|
|
6166
6175
|
return { code: res.ok ? 0 : (res.exitCode || 1), stdout: res.stdout, stderr: res.stderr };
|
|
6167
6176
|
},
|
|
6168
6177
|
|
|
6178
|
+
async 'g++'(args, ctx) {
|
|
6179
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
6180
|
+
return {
|
|
6181
|
+
code: 0,
|
|
6182
|
+
stdout: 'clang version 18.1.8 (Target: wasm32-unknown-wasi)\nTarget: wasm32-unknown-wasi\nThread model: posix\nInstalledDir: /usr/bin\n',
|
|
6183
|
+
stderr: ''
|
|
6184
|
+
};
|
|
6185
|
+
}
|
|
6186
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
6187
|
+
return {
|
|
6188
|
+
code: 0,
|
|
6189
|
+
stdout:
|
|
6190
|
+
'Usage: g++ [options] file...\n' +
|
|
6191
|
+
'Options:\n' +
|
|
6192
|
+
' -std=<standard> Assume that the input sources are for <standard> (c++17, c++20, c++23)\n' +
|
|
6193
|
+
' -O0, -O1, -O2, -O3 Optimization level\n' +
|
|
6194
|
+
' -o <file> Write output to <file> (default: a.out)\n' +
|
|
6195
|
+
' -I <dir> Add directory to include search path\n',
|
|
6196
|
+
stderr: ''
|
|
6197
|
+
};
|
|
6198
|
+
}
|
|
6199
|
+
|
|
6200
|
+
const sourceFiles = [];
|
|
6201
|
+
const extraFlags = [];
|
|
6202
|
+
let outputPath = PosixPath.join(ctx.cwd, 'a.out');
|
|
6203
|
+
let std = 'c++20';
|
|
6204
|
+
let optLevel = '-O2';
|
|
6205
|
+
|
|
6206
|
+
for (let i = 0; i < args.length; i++) {
|
|
6207
|
+
const arg = args[i];
|
|
6208
|
+
if (arg === '-o' && i + 1 < args.length) {
|
|
6209
|
+
outputPath = ctx.resolvePath(args[++i]);
|
|
6210
|
+
} else if (arg.startsWith('-o') && arg.length > 2) {
|
|
6211
|
+
outputPath = ctx.resolvePath(arg.slice(2));
|
|
6212
|
+
} else if (arg.startsWith('-std=')) {
|
|
6213
|
+
const val = arg.slice(5);
|
|
6214
|
+
if (val === 'c++17' || val === 'gnu++17') std = 'c++17';
|
|
6215
|
+
else if (val === 'c++23' || val === 'c++2b' || val === 'gnu++23') std = 'c++23';
|
|
6216
|
+
else std = 'c++20';
|
|
6217
|
+
} else if (arg === '-O0' || arg === '-O1' || arg === '-O2' || arg === '-O3') {
|
|
6218
|
+
optLevel = arg;
|
|
6219
|
+
} else if (arg.startsWith('-I') || arg.startsWith('-D') || arg.startsWith('-W')) {
|
|
6220
|
+
extraFlags.push(arg);
|
|
6221
|
+
} else if (!arg.startsWith('-')) {
|
|
6222
|
+
sourceFiles.push(ctx.resolvePath(arg));
|
|
6223
|
+
}
|
|
6224
|
+
}
|
|
6225
|
+
|
|
6226
|
+
if (sourceFiles.length === 0) {
|
|
6227
|
+
return { code: 1, stdout: '', stderr: 'g++: fatal error: no input files\ncompilation terminated.\n' };
|
|
6228
|
+
}
|
|
6229
|
+
|
|
6230
|
+
for (const src of sourceFiles) {
|
|
6231
|
+
if (!ctx.vfs.existsSync(src)) {
|
|
6232
|
+
return { code: 1, stdout: '', stderr: `g++: error: ${src}: No such file or directory\n` };
|
|
6233
|
+
}
|
|
6234
|
+
}
|
|
6235
|
+
|
|
6236
|
+
const cppCompiler =
|
|
6237
|
+
(ctx.shell && ctx.shell.options && ctx.shell.options.cppCompiler) ||
|
|
6238
|
+
(typeof globalThis !== 'undefined' && globalThis.__codelabCppCompiler) ||
|
|
6239
|
+
(typeof window !== 'undefined' && window.__codelabCppCompiler);
|
|
6240
|
+
|
|
6241
|
+
if (typeof cppCompiler !== 'function') {
|
|
6242
|
+
return {
|
|
6243
|
+
code: 1,
|
|
6244
|
+
stdout: '',
|
|
6245
|
+
stderr:
|
|
6246
|
+
'g++: C++ toolchain is not enabled. Enable cppExtension from "@innovatorved/code-lab/extensions/cpp" to compile C++ files.\n'
|
|
6247
|
+
};
|
|
6248
|
+
}
|
|
6249
|
+
|
|
6250
|
+
let outText = '';
|
|
6251
|
+
let errText = '';
|
|
6252
|
+
const compileRes = await cppCompiler({
|
|
6253
|
+
entry: sourceFiles[0],
|
|
6254
|
+
sourceFiles,
|
|
6255
|
+
outputPath,
|
|
6256
|
+
std,
|
|
6257
|
+
optLevel,
|
|
6258
|
+
extraFlags,
|
|
6259
|
+
vfs: ctx.vfs,
|
|
6260
|
+
onStdout: (t) => {
|
|
6261
|
+
outText += t;
|
|
6262
|
+
if (ctx.onStdout) ctx.onStdout(t);
|
|
6263
|
+
},
|
|
6264
|
+
onStderr: (t) => {
|
|
6265
|
+
errText += t;
|
|
6266
|
+
if (ctx.onStderr) ctx.onStderr(t);
|
|
6267
|
+
}
|
|
6268
|
+
});
|
|
6269
|
+
|
|
6270
|
+
if (!compileRes || compileRes.exitCode !== 0) {
|
|
6271
|
+
return {
|
|
6272
|
+
code: (compileRes && compileRes.exitCode) || 1,
|
|
6273
|
+
stdout: outText,
|
|
6274
|
+
stderr: errText || 'g++: error: linker command failed with exit code 1\n'
|
|
6275
|
+
};
|
|
6276
|
+
}
|
|
6277
|
+
|
|
6278
|
+
if (compileRes.wasmBinary) {
|
|
6279
|
+
ctx.vfs.writeFileSync(outputPath, compileRes.wasmBinary);
|
|
6280
|
+
if (typeof ctx.vfs.chmodSync === 'function') {
|
|
6281
|
+
try { ctx.vfs.chmodSync(outputPath, 0o755); } catch (err) { _shellLogger.debug('chmodSync failed on compiled binary', err); }
|
|
6282
|
+
}
|
|
6283
|
+
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', outputPath);
|
|
6284
|
+
}
|
|
6285
|
+
|
|
6286
|
+
return { code: 0, stdout: outText, stderr: errText };
|
|
6287
|
+
},
|
|
6288
|
+
|
|
6289
|
+
async 'clang++'(args, ctx) {
|
|
6290
|
+
return COREUTILS['g++'](args, ctx);
|
|
6291
|
+
},
|
|
6292
|
+
|
|
6293
|
+
async 'c++'(args, ctx) {
|
|
6294
|
+
return COREUTILS['g++'](args, ctx);
|
|
6295
|
+
},
|
|
6296
|
+
|
|
6297
|
+
async python3(args, ctx) {
|
|
6298
|
+
if (args.length === 0) {
|
|
6299
|
+
return { code: 0, stdout: 'Python 3.12.8 (CPython WebAssembly via Pyodide)\n', stderr: '' };
|
|
6300
|
+
}
|
|
6301
|
+
|
|
6302
|
+
if (args[0] === '--version' || args[0] === '-V') {
|
|
6303
|
+
return { code: 0, stdout: 'Python 3.12.8 (CPython WebAssembly via Pyodide)\n', stderr: '' };
|
|
6304
|
+
}
|
|
6305
|
+
|
|
6306
|
+
let codeToRun = undefined;
|
|
6307
|
+
let entryFile = undefined;
|
|
6308
|
+
|
|
6309
|
+
if (args[0] === '-c' && args.length > 1) {
|
|
6310
|
+
codeToRun = args[1];
|
|
6311
|
+
} else if (!args[0].startsWith('-')) {
|
|
6312
|
+
entryFile = ctx.resolvePath(args[0]);
|
|
6313
|
+
}
|
|
6314
|
+
|
|
6315
|
+
const pyCompiler =
|
|
6316
|
+
(ctx.shell && ctx.shell.options && ctx.shell.options.pythonCompiler) ||
|
|
6317
|
+
(typeof globalThis !== 'undefined' && globalThis.__codelabPythonCompiler) ||
|
|
6318
|
+
(typeof window !== 'undefined' && window.__codelabPythonCompiler);
|
|
6319
|
+
|
|
6320
|
+
if (typeof pyCompiler !== 'function') {
|
|
6321
|
+
return {
|
|
6322
|
+
code: 1,
|
|
6323
|
+
stdout: '',
|
|
6324
|
+
stderr:
|
|
6325
|
+
'python3: Python WebAssembly toolchain is not enabled. Enable pythonExtension from "@innovatorved/code-lab/extensions/python".\n'
|
|
6326
|
+
};
|
|
6327
|
+
}
|
|
6328
|
+
|
|
6329
|
+
let outText = '';
|
|
6330
|
+
let errText = '';
|
|
6331
|
+
const res = await pyCompiler({
|
|
6332
|
+
entry: entryFile,
|
|
6333
|
+
source: codeToRun,
|
|
6334
|
+
vfs: ctx.vfs,
|
|
6335
|
+
onStdout: (t) => {
|
|
6336
|
+
outText += t;
|
|
6337
|
+
if (ctx.onStdout) ctx.onStdout(t);
|
|
6338
|
+
},
|
|
6339
|
+
onStderr: (t) => {
|
|
6340
|
+
errText += t;
|
|
6341
|
+
if (ctx.onStderr) ctx.onStderr(t);
|
|
6342
|
+
}
|
|
6343
|
+
});
|
|
6344
|
+
|
|
6345
|
+
return {
|
|
6346
|
+
code: res && res.ok ? 0 : ((res && res.exitCode) || 1),
|
|
6347
|
+
stdout: outText,
|
|
6348
|
+
stderr: errText
|
|
6349
|
+
};
|
|
6350
|
+
},
|
|
6351
|
+
|
|
6352
|
+
async python(args, ctx) {
|
|
6353
|
+
return COREUTILS['python3'](args, ctx);
|
|
6354
|
+
},
|
|
6355
|
+
|
|
6356
|
+
async pytest(args, ctx) {
|
|
6357
|
+
if (args.length > 0 && (args[0] === '--version' || args[0] === '-V')) {
|
|
6358
|
+
return { code: 0, stdout: 'pytest 8.3.4 (Python 3.12 WebAssembly)\n', stderr: '' };
|
|
6359
|
+
}
|
|
6360
|
+
const testFiles = args.filter((a) => !a.startsWith('-'));
|
|
6361
|
+
let target = testFiles[0];
|
|
6362
|
+
if (!target && ctx.vfs) {
|
|
6363
|
+
try {
|
|
6364
|
+
const allFiles = Object.keys(typeof ctx.vfs.toSnapshot === 'function' ? ctx.vfs.toSnapshot('/workspace') : (ctx.vfs.files || {}));
|
|
6365
|
+
target = allFiles.find((f) => /(?:^|\/)(?:test_.*|.*_test|test)\.py$/i.test(f));
|
|
6366
|
+
} catch (err) {
|
|
6367
|
+
void err;
|
|
6368
|
+
}
|
|
6369
|
+
}
|
|
6370
|
+
target = target || 'test.py';
|
|
6371
|
+
return COREUTILS['python3']([target], ctx);
|
|
6372
|
+
},
|
|
6373
|
+
|
|
6374
|
+
async pip(args, ctx) {
|
|
6375
|
+
if (args.length === 0 || args[0] === '--version' || args[0] === '-V') {
|
|
6376
|
+
return { code: 0, stdout: 'pip 24.0 from /usr/lib/python/pip (python 3.12)\n', stderr: '' };
|
|
6377
|
+
}
|
|
6378
|
+
if (args[0] === 'install') {
|
|
6379
|
+
const pkgs = args.slice(1).filter((p) => !p.startsWith('-'));
|
|
6380
|
+
const toolchain =
|
|
6381
|
+
(ctx.shell && ctx.shell.options && ctx.shell.options.pythonToolchain) ||
|
|
6382
|
+
(typeof globalThis !== 'undefined' && globalThis.__codelabPythonToolchain) ||
|
|
6383
|
+
(typeof window !== 'undefined' && window.__codelabPythonToolchain);
|
|
6384
|
+
if (toolchain && typeof toolchain.installPackages === 'function') {
|
|
6385
|
+
const res = await toolchain.installPackages(pkgs);
|
|
6386
|
+
if (res.ok) {
|
|
6387
|
+
return {
|
|
6388
|
+
code: 0,
|
|
6389
|
+
stdout: `Successfully installed ${res.installed.join(', ') || 'packages'}\n`,
|
|
6390
|
+
stderr: ''
|
|
6391
|
+
};
|
|
6392
|
+
}
|
|
6393
|
+
return {
|
|
6394
|
+
code: 1,
|
|
6395
|
+
stdout: '',
|
|
6396
|
+
stderr: `ERROR: Could not find a version that satisfies the requirement ${res.error || pkgs.join(', ')}\n`
|
|
6397
|
+
};
|
|
6398
|
+
}
|
|
6399
|
+
return {
|
|
6400
|
+
code: 0,
|
|
6401
|
+
stdout: `Successfully installed ${pkgs.join(', ') || 'packages'}\n`,
|
|
6402
|
+
stderr: ''
|
|
6403
|
+
};
|
|
6404
|
+
}
|
|
6405
|
+
return { code: 0, stdout: 'pip 24.0 (Pyodide micropip)\n', stderr: '' };
|
|
6406
|
+
},
|
|
6407
|
+
|
|
6169
6408
|
async bun(args, ctx) {
|
|
6170
6409
|
if (args.length === 0) {
|
|
6171
6410
|
return { code: 0, stdout: 'Bun v1.1.20\n', stderr: '' };
|
|
@@ -7768,6 +8007,10 @@ var CodeLabLogger = (() => {
|
|
|
7768
8007
|
return { code: lastCode, exitCode: lastCode, stdout: combinedStdout, stderr: combinedStderr, ok: lastCode === 0 };
|
|
7769
8008
|
}
|
|
7770
8009
|
|
|
8010
|
+
async executeCommand(commandLine, execOptions = {}) {
|
|
8011
|
+
return this.execute(commandLine, execOptions);
|
|
8012
|
+
}
|
|
8013
|
+
|
|
7771
8014
|
async _executeWithRedirects(redirects, context, execFn) {
|
|
7772
8015
|
if (!redirects || redirects.length === 0) {
|
|
7773
8016
|
return execFn(context);
|
|
@@ -8448,6 +8691,48 @@ var CodeLabLogger = (() => {
|
|
|
8448
8691
|
Object.assign(context.env, this.env);
|
|
8449
8692
|
context.cwd = this.cwd;
|
|
8450
8693
|
}
|
|
8694
|
+
} else if (
|
|
8695
|
+
(cmdName.startsWith('./') || cmdName.startsWith('../') || cmdName.startsWith('/')) &&
|
|
8696
|
+
this.vfs.existsSync(this.resolvePath(cmdName))
|
|
8697
|
+
) {
|
|
8698
|
+
const absBin = this.resolvePath(cmdName);
|
|
8699
|
+
const st = this.vfs.statSync(absBin);
|
|
8700
|
+
if (st && st.isDirectory()) {
|
|
8701
|
+
res = { code: 126, stdout: '', stderr: `shell: ${cmdName}: Is a directory\n` };
|
|
8702
|
+
} else if (hasVirtualRuntime()) {
|
|
8703
|
+
let rawData = null;
|
|
8704
|
+
try { rawData = this.vfs.readFileSync(absBin); } catch (err) { _shellLogger.debug('Failed to read binary', err); }
|
|
8705
|
+
const isWasmMagic =
|
|
8706
|
+
(rawData instanceof Uint8Array &&
|
|
8707
|
+
rawData.length >= 4 &&
|
|
8708
|
+
rawData[0] === 0x00 &&
|
|
8709
|
+
rawData[1] === 0x61 &&
|
|
8710
|
+
rawData[2] === 0x73 &&
|
|
8711
|
+
rawData[3] === 0x6d) ||
|
|
8712
|
+
(typeof rawData === 'string' && rawData.startsWith('\0asm'));
|
|
8713
|
+
const runRes = await executeInVirtualRuntime({
|
|
8714
|
+
mode: 'run',
|
|
8715
|
+
entry: absBin,
|
|
8716
|
+
wasmBinary: isWasmMagic && rawData instanceof Uint8Array ? rawData : undefined,
|
|
8717
|
+
argv: [cmdName, ...args],
|
|
8718
|
+
stdin: effectiveStdin,
|
|
8719
|
+
env: cmdEnv,
|
|
8720
|
+
vfs: this.vfs,
|
|
8721
|
+
activePortTable: this.portTable,
|
|
8722
|
+
pid: cmdCtx.pid,
|
|
8723
|
+
isBackground: cmdCtx.isBackground,
|
|
8724
|
+
onStdout: cmdCtx.onStdout,
|
|
8725
|
+
onStderr: cmdCtx.onStderr,
|
|
8726
|
+
signal: context.signal
|
|
8727
|
+
});
|
|
8728
|
+
res = {
|
|
8729
|
+
code: runRes.ok ? 0 : (runRes.exitCode || 1),
|
|
8730
|
+
stdout: runRes.stdout || '',
|
|
8731
|
+
stderr: runRes.stderr || ''
|
|
8732
|
+
};
|
|
8733
|
+
} else {
|
|
8734
|
+
res = { code: 126, stdout: '', stderr: `shell: ${cmdName}: cannot execute binary file\n` };
|
|
8735
|
+
}
|
|
8451
8736
|
} else if (DIRECT_DEV_TOOL_RE.test(cmdName)) {
|
|
8452
8737
|
// A native dev server (vite/ng/astro/…) typed directly. It cannot run in
|
|
8453
8738
|
// this runtime — whether or not it was installed — so route it to the
|