@innovatorved/code-lab 0.1.13 → 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/ARCHITECTURE.md +7 -7
- package/CHANGELOG.md +107 -0
- package/README.md +48 -8
- package/dist/code-lab.d.ts +19 -7
- package/dist/code-lab.esm.js +11085 -84
- package/dist/code-lab.js +11078 -80
- package/dist/extensions/cpp.d.ts +119 -0
- package/dist/extensions/cpp.esm.js +5193 -0
- package/dist/extensions/cpp.js +5212 -0
- package/dist/extensions/guided-lab.esm.js +48 -6
- package/dist/extensions/guided-lab.js +49 -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/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 +5 -2
- package/dist/preview-sw.js +1 -1
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.esm.js +888 -15
- package/dist/runtime.js +882 -15
- package/dist/schemas.d.ts +122 -23
- package/dist/schemas.esm.js +43 -6
- package/dist/schemas.js +43 -6
- package/dist/shell.esm.js +177 -4
- package/dist/shell.js +177 -4
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +27 -3
- package/src/extensions/cpp.ts +1081 -0
- package/src/extensions/guided-lab.ts +10 -0
- package/src/extensions/javascript.ts +54 -0
- package/src/extensions/typescript.ts +85 -0
- package/src/index.ts +33 -2
- package/src/runtime.ts +883 -14
- package/src/schemas.ts +49 -7
- package/src/shell.ts +176 -3
- package/src/workbench.ts +298 -45
package/dist/shell.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.
|
|
3
|
+
* @innovatorved/code-lab v0.2.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,7 @@ 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';
|
|
6051
6059
|
stdout += ' serve [dir] [--port] Built-in preview server (transpiles TS/JSX for the browser)\n';
|
|
6052
6060
|
stdout += ' ports, curl Port table inspection & HTTP requests\n';
|
|
6053
6061
|
stdout += ' hey, ab, wrk Concurrent HTTP load generator & latency percentiles\n';
|
|
@@ -6166,6 +6174,125 @@ var CodeLabLogger = (() => {
|
|
|
6166
6174
|
return { code: res.ok ? 0 : (res.exitCode || 1), stdout: res.stdout, stderr: res.stderr };
|
|
6167
6175
|
},
|
|
6168
6176
|
|
|
6177
|
+
async 'g++'(args, ctx) {
|
|
6178
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
6179
|
+
return {
|
|
6180
|
+
code: 0,
|
|
6181
|
+
stdout: 'clang version 18.1.8 (Target: wasm32-unknown-wasi)\nTarget: wasm32-unknown-wasi\nThread model: posix\nInstalledDir: /usr/bin\n',
|
|
6182
|
+
stderr: ''
|
|
6183
|
+
};
|
|
6184
|
+
}
|
|
6185
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
6186
|
+
return {
|
|
6187
|
+
code: 0,
|
|
6188
|
+
stdout:
|
|
6189
|
+
'Usage: g++ [options] file...\n' +
|
|
6190
|
+
'Options:\n' +
|
|
6191
|
+
' -std=<standard> Assume that the input sources are for <standard> (c++17, c++20, c++23)\n' +
|
|
6192
|
+
' -O0, -O1, -O2, -O3 Optimization level\n' +
|
|
6193
|
+
' -o <file> Write output to <file> (default: a.out)\n' +
|
|
6194
|
+
' -I <dir> Add directory to include search path\n',
|
|
6195
|
+
stderr: ''
|
|
6196
|
+
};
|
|
6197
|
+
}
|
|
6198
|
+
|
|
6199
|
+
const sourceFiles = [];
|
|
6200
|
+
const extraFlags = [];
|
|
6201
|
+
let outputPath = PosixPath.join(ctx.cwd, 'a.out');
|
|
6202
|
+
let std = 'c++20';
|
|
6203
|
+
let optLevel = '-O2';
|
|
6204
|
+
|
|
6205
|
+
for (let i = 0; i < args.length; i++) {
|
|
6206
|
+
const arg = args[i];
|
|
6207
|
+
if (arg === '-o' && i + 1 < args.length) {
|
|
6208
|
+
outputPath = ctx.resolvePath(args[++i]);
|
|
6209
|
+
} else if (arg.startsWith('-o') && arg.length > 2) {
|
|
6210
|
+
outputPath = ctx.resolvePath(arg.slice(2));
|
|
6211
|
+
} else if (arg.startsWith('-std=')) {
|
|
6212
|
+
const val = arg.slice(5);
|
|
6213
|
+
if (val === 'c++17' || val === 'gnu++17') std = 'c++17';
|
|
6214
|
+
else if (val === 'c++23' || val === 'c++2b' || val === 'gnu++23') std = 'c++23';
|
|
6215
|
+
else std = 'c++20';
|
|
6216
|
+
} else if (arg === '-O0' || arg === '-O1' || arg === '-O2' || arg === '-O3') {
|
|
6217
|
+
optLevel = arg;
|
|
6218
|
+
} else if (arg.startsWith('-I') || arg.startsWith('-D') || arg.startsWith('-W')) {
|
|
6219
|
+
extraFlags.push(arg);
|
|
6220
|
+
} else if (!arg.startsWith('-')) {
|
|
6221
|
+
sourceFiles.push(ctx.resolvePath(arg));
|
|
6222
|
+
}
|
|
6223
|
+
}
|
|
6224
|
+
|
|
6225
|
+
if (sourceFiles.length === 0) {
|
|
6226
|
+
return { code: 1, stdout: '', stderr: 'g++: fatal error: no input files\ncompilation terminated.\n' };
|
|
6227
|
+
}
|
|
6228
|
+
|
|
6229
|
+
for (const src of sourceFiles) {
|
|
6230
|
+
if (!ctx.vfs.existsSync(src)) {
|
|
6231
|
+
return { code: 1, stdout: '', stderr: `g++: error: ${src}: No such file or directory\n` };
|
|
6232
|
+
}
|
|
6233
|
+
}
|
|
6234
|
+
|
|
6235
|
+
const cppCompiler =
|
|
6236
|
+
(ctx.shell && ctx.shell.options && ctx.shell.options.cppCompiler) ||
|
|
6237
|
+
(typeof globalThis !== 'undefined' && globalThis.__codelabCppCompiler) ||
|
|
6238
|
+
(typeof window !== 'undefined' && window.__codelabCppCompiler);
|
|
6239
|
+
|
|
6240
|
+
if (typeof cppCompiler !== 'function') {
|
|
6241
|
+
return {
|
|
6242
|
+
code: 1,
|
|
6243
|
+
stdout: '',
|
|
6244
|
+
stderr:
|
|
6245
|
+
'g++: C++ toolchain is not enabled. Enable cppExtension from "@innovatorved/code-lab/extensions/cpp" to compile C++ files.\n'
|
|
6246
|
+
};
|
|
6247
|
+
}
|
|
6248
|
+
|
|
6249
|
+
let outText = '';
|
|
6250
|
+
let errText = '';
|
|
6251
|
+
const compileRes = await cppCompiler({
|
|
6252
|
+
entry: sourceFiles[0],
|
|
6253
|
+
sourceFiles,
|
|
6254
|
+
outputPath,
|
|
6255
|
+
std,
|
|
6256
|
+
optLevel,
|
|
6257
|
+
extraFlags,
|
|
6258
|
+
vfs: ctx.vfs,
|
|
6259
|
+
onStdout: (t) => {
|
|
6260
|
+
outText += t;
|
|
6261
|
+
if (ctx.onStdout) ctx.onStdout(t);
|
|
6262
|
+
},
|
|
6263
|
+
onStderr: (t) => {
|
|
6264
|
+
errText += t;
|
|
6265
|
+
if (ctx.onStderr) ctx.onStderr(t);
|
|
6266
|
+
}
|
|
6267
|
+
});
|
|
6268
|
+
|
|
6269
|
+
if (!compileRes || compileRes.exitCode !== 0) {
|
|
6270
|
+
return {
|
|
6271
|
+
code: (compileRes && compileRes.exitCode) || 1,
|
|
6272
|
+
stdout: outText,
|
|
6273
|
+
stderr: errText || 'g++: error: linker command failed with exit code 1\n'
|
|
6274
|
+
};
|
|
6275
|
+
}
|
|
6276
|
+
|
|
6277
|
+
if (compileRes.wasmBinary) {
|
|
6278
|
+
ctx.vfs.writeFileSync(outputPath, compileRes.wasmBinary);
|
|
6279
|
+
if (typeof ctx.vfs.chmodSync === 'function') {
|
|
6280
|
+
try { ctx.vfs.chmodSync(outputPath, 0o755); } catch (err) { _shellLogger.debug('chmodSync failed on compiled binary', err); }
|
|
6281
|
+
}
|
|
6282
|
+
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', outputPath);
|
|
6283
|
+
}
|
|
6284
|
+
|
|
6285
|
+
return { code: 0, stdout: outText, stderr: errText };
|
|
6286
|
+
},
|
|
6287
|
+
|
|
6288
|
+
async 'clang++'(args, ctx) {
|
|
6289
|
+
return COREUTILS['g++'](args, ctx);
|
|
6290
|
+
},
|
|
6291
|
+
|
|
6292
|
+
async 'c++'(args, ctx) {
|
|
6293
|
+
return COREUTILS['g++'](args, ctx);
|
|
6294
|
+
},
|
|
6295
|
+
|
|
6169
6296
|
async bun(args, ctx) {
|
|
6170
6297
|
if (args.length === 0) {
|
|
6171
6298
|
return { code: 0, stdout: 'Bun v1.1.20\n', stderr: '' };
|
|
@@ -7768,6 +7895,10 @@ var CodeLabLogger = (() => {
|
|
|
7768
7895
|
return { code: lastCode, exitCode: lastCode, stdout: combinedStdout, stderr: combinedStderr, ok: lastCode === 0 };
|
|
7769
7896
|
}
|
|
7770
7897
|
|
|
7898
|
+
async executeCommand(commandLine, execOptions = {}) {
|
|
7899
|
+
return this.execute(commandLine, execOptions);
|
|
7900
|
+
}
|
|
7901
|
+
|
|
7771
7902
|
async _executeWithRedirects(redirects, context, execFn) {
|
|
7772
7903
|
if (!redirects || redirects.length === 0) {
|
|
7773
7904
|
return execFn(context);
|
|
@@ -8448,6 +8579,48 @@ var CodeLabLogger = (() => {
|
|
|
8448
8579
|
Object.assign(context.env, this.env);
|
|
8449
8580
|
context.cwd = this.cwd;
|
|
8450
8581
|
}
|
|
8582
|
+
} else if (
|
|
8583
|
+
(cmdName.startsWith('./') || cmdName.startsWith('../') || cmdName.startsWith('/')) &&
|
|
8584
|
+
this.vfs.existsSync(this.resolvePath(cmdName))
|
|
8585
|
+
) {
|
|
8586
|
+
const absBin = this.resolvePath(cmdName);
|
|
8587
|
+
const st = this.vfs.statSync(absBin);
|
|
8588
|
+
if (st && st.isDirectory()) {
|
|
8589
|
+
res = { code: 126, stdout: '', stderr: `shell: ${cmdName}: Is a directory\n` };
|
|
8590
|
+
} else if (hasVirtualRuntime()) {
|
|
8591
|
+
let rawData = null;
|
|
8592
|
+
try { rawData = this.vfs.readFileSync(absBin); } catch (err) { _shellLogger.debug('Failed to read binary', err); }
|
|
8593
|
+
const isWasmMagic =
|
|
8594
|
+
(rawData instanceof Uint8Array &&
|
|
8595
|
+
rawData.length >= 4 &&
|
|
8596
|
+
rawData[0] === 0x00 &&
|
|
8597
|
+
rawData[1] === 0x61 &&
|
|
8598
|
+
rawData[2] === 0x73 &&
|
|
8599
|
+
rawData[3] === 0x6d) ||
|
|
8600
|
+
(typeof rawData === 'string' && rawData.startsWith('\0asm'));
|
|
8601
|
+
const runRes = await executeInVirtualRuntime({
|
|
8602
|
+
mode: 'run',
|
|
8603
|
+
entry: absBin,
|
|
8604
|
+
wasmBinary: isWasmMagic && rawData instanceof Uint8Array ? rawData : undefined,
|
|
8605
|
+
argv: [cmdName, ...args],
|
|
8606
|
+
stdin: effectiveStdin,
|
|
8607
|
+
env: cmdEnv,
|
|
8608
|
+
vfs: this.vfs,
|
|
8609
|
+
activePortTable: this.portTable,
|
|
8610
|
+
pid: cmdCtx.pid,
|
|
8611
|
+
isBackground: cmdCtx.isBackground,
|
|
8612
|
+
onStdout: cmdCtx.onStdout,
|
|
8613
|
+
onStderr: cmdCtx.onStderr,
|
|
8614
|
+
signal: context.signal
|
|
8615
|
+
});
|
|
8616
|
+
res = {
|
|
8617
|
+
code: runRes.ok ? 0 : (runRes.exitCode || 1),
|
|
8618
|
+
stdout: runRes.stdout || '',
|
|
8619
|
+
stderr: runRes.stderr || ''
|
|
8620
|
+
};
|
|
8621
|
+
} else {
|
|
8622
|
+
res = { code: 126, stdout: '', stderr: `shell: ${cmdName}: cannot execute binary file\n` };
|
|
8623
|
+
}
|
|
8451
8624
|
} else if (DIRECT_DEV_TOOL_RE.test(cmdName)) {
|
|
8452
8625
|
// A native dev server (vite/ng/astro/…) typed directly. It cannot run in
|
|
8453
8626
|
// this runtime — whether or not it was installed — so route it to the
|
package/dist/shell.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.
|
|
3
|
+
* @innovatorved/code-lab v0.2.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
|
|
@@ -1802,7 +1802,7 @@ var CodeLabLogger = (() => {
|
|
|
1802
1802
|
}
|
|
1803
1803
|
return Array.from(children).sort();
|
|
1804
1804
|
},
|
|
1805
|
-
readFileSync(p) {
|
|
1805
|
+
readFileSync(p, encoding) {
|
|
1806
1806
|
const np = norm(p);
|
|
1807
1807
|
const f = files.get(np);
|
|
1808
1808
|
if (!f) {
|
|
@@ -1810,6 +1810,9 @@ var CodeLabLogger = (() => {
|
|
|
1810
1810
|
err.code = 'ENOENT';
|
|
1811
1811
|
throw err;
|
|
1812
1812
|
}
|
|
1813
|
+
if (!encoding && f.rawBytes instanceof Uint8Array) {
|
|
1814
|
+
return f.rawBytes;
|
|
1815
|
+
}
|
|
1813
1816
|
return f.data;
|
|
1814
1817
|
},
|
|
1815
1818
|
writeFileSync(p, data) {
|
|
@@ -1820,9 +1823,13 @@ var CodeLabLogger = (() => {
|
|
|
1820
1823
|
let cur = '';
|
|
1821
1824
|
for (const pt of parts) { cur += '/' + pt; dirs.add(cur); }
|
|
1822
1825
|
}
|
|
1823
|
-
const
|
|
1826
|
+
const isBinary = data instanceof Uint8Array;
|
|
1827
|
+
const rawBytes = isBinary ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : null;
|
|
1828
|
+
const str = isBinary
|
|
1829
|
+
? new TextDecoder('utf-8').decode(rawBytes)
|
|
1830
|
+
: (typeof data === 'string' ? data : (data && data.toString ? data.toString('utf8') : String(data)));
|
|
1824
1831
|
const prevMode = files.has(np) ? files.get(np).mode : 0o100644;
|
|
1825
|
-
files.set(np, { data: str, mtimeMs: Date.now(), mode: prevMode });
|
|
1832
|
+
files.set(np, { data: str, rawBytes, mtimeMs: Date.now(), mode: prevMode });
|
|
1826
1833
|
},
|
|
1827
1834
|
appendFileSync(p, data) {
|
|
1828
1835
|
const np = norm(p);
|
|
@@ -6049,6 +6056,7 @@ var CodeLabLogger = (() => {
|
|
|
6049
6056
|
stdout += ' history, ps, jobs, kill Process and job management\n';
|
|
6050
6057
|
stdout += ' git [status diff log] Built-in version control\n';
|
|
6051
6058
|
stdout += ' node, bun, npm, pnpm, npx, bunx CLI runtime and package shims\n';
|
|
6059
|
+
stdout += ' g++, clang++, c++ C++20 WebAssembly compiler (via cppExtension)\n';
|
|
6052
6060
|
stdout += ' serve [dir] [--port] Built-in preview server (transpiles TS/JSX for the browser)\n';
|
|
6053
6061
|
stdout += ' ports, curl Port table inspection & HTTP requests\n';
|
|
6054
6062
|
stdout += ' hey, ab, wrk Concurrent HTTP load generator & latency percentiles\n';
|
|
@@ -6167,6 +6175,125 @@ var CodeLabLogger = (() => {
|
|
|
6167
6175
|
return { code: res.ok ? 0 : (res.exitCode || 1), stdout: res.stdout, stderr: res.stderr };
|
|
6168
6176
|
},
|
|
6169
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
|
+
|
|
6170
6297
|
async bun(args, ctx) {
|
|
6171
6298
|
if (args.length === 0) {
|
|
6172
6299
|
return { code: 0, stdout: 'Bun v1.1.20\n', stderr: '' };
|
|
@@ -7769,6 +7896,10 @@ var CodeLabLogger = (() => {
|
|
|
7769
7896
|
return { code: lastCode, exitCode: lastCode, stdout: combinedStdout, stderr: combinedStderr, ok: lastCode === 0 };
|
|
7770
7897
|
}
|
|
7771
7898
|
|
|
7899
|
+
async executeCommand(commandLine, execOptions = {}) {
|
|
7900
|
+
return this.execute(commandLine, execOptions);
|
|
7901
|
+
}
|
|
7902
|
+
|
|
7772
7903
|
async _executeWithRedirects(redirects, context, execFn) {
|
|
7773
7904
|
if (!redirects || redirects.length === 0) {
|
|
7774
7905
|
return execFn(context);
|
|
@@ -8449,6 +8580,48 @@ var CodeLabLogger = (() => {
|
|
|
8449
8580
|
Object.assign(context.env, this.env);
|
|
8450
8581
|
context.cwd = this.cwd;
|
|
8451
8582
|
}
|
|
8583
|
+
} else if (
|
|
8584
|
+
(cmdName.startsWith('./') || cmdName.startsWith('../') || cmdName.startsWith('/')) &&
|
|
8585
|
+
this.vfs.existsSync(this.resolvePath(cmdName))
|
|
8586
|
+
) {
|
|
8587
|
+
const absBin = this.resolvePath(cmdName);
|
|
8588
|
+
const st = this.vfs.statSync(absBin);
|
|
8589
|
+
if (st && st.isDirectory()) {
|
|
8590
|
+
res = { code: 126, stdout: '', stderr: `shell: ${cmdName}: Is a directory\n` };
|
|
8591
|
+
} else if (hasVirtualRuntime()) {
|
|
8592
|
+
let rawData = null;
|
|
8593
|
+
try { rawData = this.vfs.readFileSync(absBin); } catch (err) { _shellLogger.debug('Failed to read binary', err); }
|
|
8594
|
+
const isWasmMagic =
|
|
8595
|
+
(rawData instanceof Uint8Array &&
|
|
8596
|
+
rawData.length >= 4 &&
|
|
8597
|
+
rawData[0] === 0x00 &&
|
|
8598
|
+
rawData[1] === 0x61 &&
|
|
8599
|
+
rawData[2] === 0x73 &&
|
|
8600
|
+
rawData[3] === 0x6d) ||
|
|
8601
|
+
(typeof rawData === 'string' && rawData.startsWith('\0asm'));
|
|
8602
|
+
const runRes = await executeInVirtualRuntime({
|
|
8603
|
+
mode: 'run',
|
|
8604
|
+
entry: absBin,
|
|
8605
|
+
wasmBinary: isWasmMagic && rawData instanceof Uint8Array ? rawData : undefined,
|
|
8606
|
+
argv: [cmdName, ...args],
|
|
8607
|
+
stdin: effectiveStdin,
|
|
8608
|
+
env: cmdEnv,
|
|
8609
|
+
vfs: this.vfs,
|
|
8610
|
+
activePortTable: this.portTable,
|
|
8611
|
+
pid: cmdCtx.pid,
|
|
8612
|
+
isBackground: cmdCtx.isBackground,
|
|
8613
|
+
onStdout: cmdCtx.onStdout,
|
|
8614
|
+
onStderr: cmdCtx.onStderr,
|
|
8615
|
+
signal: context.signal
|
|
8616
|
+
});
|
|
8617
|
+
res = {
|
|
8618
|
+
code: runRes.ok ? 0 : (runRes.exitCode || 1),
|
|
8619
|
+
stdout: runRes.stdout || '',
|
|
8620
|
+
stderr: runRes.stderr || ''
|
|
8621
|
+
};
|
|
8622
|
+
} else {
|
|
8623
|
+
res = { code: 126, stdout: '', stderr: `shell: ${cmdName}: cannot execute binary file\n` };
|
|
8624
|
+
}
|
|
8452
8625
|
} else if (DIRECT_DEV_TOOL_RE.test(cmdName)) {
|
|
8453
8626
|
// A native dev server (vite/ng/astro/…) typed directly. It cannot run in
|
|
8454
8627
|
// this runtime — whether or not it was installed — so route it to the
|
package/dist/terminal.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.
|
|
3
|
+
* @innovatorved/code-lab v0.2.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
|
package/dist/terminal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.
|
|
3
|
+
* @innovatorved/code-lab v0.2.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
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innovatorved/code-lab",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Standalone browser-native IDE Workbench, POSIX Shell & Coreutils, PTY Terminal,
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Standalone browser-native IDE Workbench, POSIX Shell & Coreutils, PTY Terminal, Web Worker Node.js/Bun Virtual Runtime, and Real WebAssembly C++20 (Clang/WASI) Extension.",
|
|
5
5
|
"main": "./dist/code-lab.js",
|
|
6
6
|
"module": "./dist/code-lab.esm.js",
|
|
7
7
|
"types": "./dist/code-lab.d.ts",
|
|
@@ -37,6 +37,24 @@
|
|
|
37
37
|
"require": "./dist/extensions/guided-lab.js",
|
|
38
38
|
"default": "./dist/extensions/guided-lab.js"
|
|
39
39
|
},
|
|
40
|
+
"./extensions/javascript": {
|
|
41
|
+
"types": "./dist/extensions/javascript.d.ts",
|
|
42
|
+
"import": "./dist/extensions/javascript.esm.js",
|
|
43
|
+
"require": "./dist/extensions/javascript.js",
|
|
44
|
+
"default": "./dist/extensions/javascript.js"
|
|
45
|
+
},
|
|
46
|
+
"./extensions/typescript": {
|
|
47
|
+
"types": "./dist/extensions/typescript.d.ts",
|
|
48
|
+
"import": "./dist/extensions/typescript.esm.js",
|
|
49
|
+
"require": "./dist/extensions/typescript.js",
|
|
50
|
+
"default": "./dist/extensions/typescript.js"
|
|
51
|
+
},
|
|
52
|
+
"./extensions/cpp": {
|
|
53
|
+
"types": "./dist/extensions/cpp.d.ts",
|
|
54
|
+
"import": "./dist/extensions/cpp.esm.js",
|
|
55
|
+
"require": "./dist/extensions/cpp.js",
|
|
56
|
+
"default": "./dist/extensions/cpp.js"
|
|
57
|
+
},
|
|
40
58
|
"./schemas": {
|
|
41
59
|
"types": "./dist/schemas.d.ts",
|
|
42
60
|
"import": "./dist/schemas.esm.js",
|
|
@@ -58,6 +76,7 @@
|
|
|
58
76
|
"src",
|
|
59
77
|
"README.md",
|
|
60
78
|
"ARCHITECTURE.md",
|
|
79
|
+
"CHANGELOG.md",
|
|
61
80
|
"LICENSE"
|
|
62
81
|
],
|
|
63
82
|
"repository": {
|
|
@@ -104,7 +123,12 @@
|
|
|
104
123
|
"web-component",
|
|
105
124
|
"system-design",
|
|
106
125
|
"browser-sandbox",
|
|
107
|
-
"guided-labs"
|
|
126
|
+
"guided-labs",
|
|
127
|
+
"cpp",
|
|
128
|
+
"webassembly",
|
|
129
|
+
"wasi",
|
|
130
|
+
"clang",
|
|
131
|
+
"dsa"
|
|
108
132
|
],
|
|
109
133
|
"author": "Ved Gupta",
|
|
110
134
|
"license": "MIT"
|