@innovatorved/code-lab 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 +1 -1
- package/dist/code-lab.css +78 -31
- package/dist/code-lab.d.ts +3 -1
- package/dist/code-lab.esm.js +507 -114
- package/dist/code-lab.js +507 -114
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.esm.js +48 -3
- package/dist/runtime.js +48 -3
- package/dist/shell.esm.js +295 -40
- package/dist/shell.js +295 -40
- package/package.json +1 -1
- package/src/code-lab.css +78 -31
- package/src/runtime.js +48 -3
- package/src/runtime.ts +53 -4
- package/src/shell.js +295 -40
- package/src/shell.ts +295 -40
- package/src/workbench.js +164 -71
- package/src/workbench.ts +164 -71
package/src/workbench.ts
CHANGED
|
@@ -1172,6 +1172,9 @@ declare module 'bun:sqlite' {
|
|
|
1172
1172
|
this.folders = new Set(this.savedState?.folders || []);
|
|
1173
1173
|
this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
|
|
1174
1174
|
this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
|
|
1175
|
+
this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
|
|
1176
|
+
? this.savedState.explorerWidth
|
|
1177
|
+
: 196;
|
|
1175
1178
|
this.folderSwitcherOpen = false;
|
|
1176
1179
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
1177
1180
|
this.renamingItem = null;
|
|
@@ -1509,7 +1512,8 @@ declare module 'bun:sqlite' {
|
|
|
1509
1512
|
activeFile: this.activeFile,
|
|
1510
1513
|
folders: Array.from(this.folders || []),
|
|
1511
1514
|
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
1512
|
-
explorerFolder: this.explorerFolder || ''
|
|
1515
|
+
explorerFolder: this.explorerFolder || '',
|
|
1516
|
+
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
|
|
1513
1517
|
};
|
|
1514
1518
|
this.savedState = state;
|
|
1515
1519
|
if (this.options && this.options.persistState === false) {
|
|
@@ -1690,6 +1694,13 @@ declare module 'bun:sqlite' {
|
|
|
1690
1694
|
if (stopBtn) {
|
|
1691
1695
|
stopBtn.style.display = this.isRunning ? 'inline-flex' : 'none';
|
|
1692
1696
|
}
|
|
1697
|
+
const ctrlCBtn = this.container.querySelector('#cl-ctrl-c-btn');
|
|
1698
|
+
if (ctrlCBtn) {
|
|
1699
|
+
ctrlCBtn.classList.toggle('is-running', Boolean(this.isRunning));
|
|
1700
|
+
ctrlCBtn.title = this.isRunning
|
|
1701
|
+
? 'Send Ctrl+C — interrupt the running command'
|
|
1702
|
+
: 'Send Ctrl+C (clears the current input line)';
|
|
1703
|
+
}
|
|
1693
1704
|
this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
|
|
1694
1705
|
btn.disabled = this.isRunning;
|
|
1695
1706
|
});
|
|
@@ -1704,8 +1715,9 @@ declare module 'bun:sqlite' {
|
|
|
1704
1715
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
1705
1716
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
1706
1717
|
const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
|
|
1718
|
+
const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
|
|
1707
1719
|
this.container.innerHTML = `
|
|
1708
|
-
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr}>
|
|
1720
|
+
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
1709
1721
|
<!-- Top Bar -->
|
|
1710
1722
|
<div class="codelab-topbar codelab-toolbar">
|
|
1711
1723
|
<div class="codelab-topbar__left">
|
|
@@ -1821,6 +1833,9 @@ declare module 'bun:sqlite' {
|
|
|
1821
1833
|
<div class="codelab-explorer__list" id="cl-explorer-list"></div>
|
|
1822
1834
|
</div>
|
|
1823
1835
|
|
|
1836
|
+
<!-- Explorer Resize Splitter -->
|
|
1837
|
+
<div class="codelab-splitter-files" id="cl-splitter-files" role="separator" aria-orientation="vertical" title="Drag to resize file explorer (double-click to reset)"></div>
|
|
1838
|
+
|
|
1824
1839
|
<!-- Editor Column -->
|
|
1825
1840
|
<div class="codelab-editor-col">
|
|
1826
1841
|
<div class="codelab-tabs codelab-file-tabs" id="cl-file-tabs" role="tablist" aria-label="Open Files"></div>
|
|
@@ -1874,6 +1889,7 @@ declare module 'bun:sqlite' {
|
|
|
1874
1889
|
</button>
|
|
1875
1890
|
</div>
|
|
1876
1891
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
1892
|
+
<button type="button" class="codelab-btn codelab-btn--icon codelab-btn--ctrl-c" id="cl-ctrl-c-btn" data-cl-action="interrupt" title="Send Ctrl+C — interrupt a running command" aria-label="Send Ctrl+C interrupt" style="padding:2px 8px;font-size:11px;font-family:var(--cl-font-mono);">Ctrl+C</button>
|
|
1877
1893
|
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="clear-terminal" title="Clear Output" style="padding:2px 6px;font-size:11px;">Clear</button>
|
|
1878
1894
|
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="toggle-drawer" title="Minimize/Expand Drawer" aria-label="Minimize or Expand Drawer" style="padding:2px 6px;font-size:11px;">${CL_ICONS.chevronsUpDown}</button>
|
|
1879
1895
|
</div>
|
|
@@ -3015,10 +3031,10 @@ declare module 'bun:sqlite' {
|
|
|
3015
3031
|
this._ptyInputAfterCursor = '';
|
|
3016
3032
|
this._updatePtyActiveLine();
|
|
3017
3033
|
}
|
|
3018
|
-
} else if (
|
|
3034
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
|
|
3019
3035
|
e.preventDefault();
|
|
3020
3036
|
this._handleInterrupt();
|
|
3021
|
-
} else if (
|
|
3037
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
|
|
3022
3038
|
e.preventDefault();
|
|
3023
3039
|
if (this.inRepl) {
|
|
3024
3040
|
this.inRepl = false;
|
|
@@ -3027,7 +3043,7 @@ declare module 'bun:sqlite' {
|
|
|
3027
3043
|
const nextInput = this.container.querySelector('#cl-repl-input');
|
|
3028
3044
|
if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
|
|
3029
3045
|
}
|
|
3030
|
-
} else if (
|
|
3046
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
|
|
3031
3047
|
e.preventDefault();
|
|
3032
3048
|
this.terminalLogs = [];
|
|
3033
3049
|
this._renderDrawerBody();
|
|
@@ -4772,41 +4788,18 @@ declare module 'bun:sqlite' {
|
|
|
4772
4788
|
|
|
4773
4789
|
_renderEmptyEditorContent(emptyEl) {
|
|
4774
4790
|
if (!emptyEl) return;
|
|
4775
|
-
const fileBtns = this._orderedFileNames().map(f => {
|
|
4776
|
-
const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
4777
|
-
return `
|
|
4778
|
-
<button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
|
|
4779
|
-
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
|
|
4780
|
-
<span>${escapeHtml(f)}</span>
|
|
4781
|
-
</button>
|
|
4782
|
-
`;
|
|
4783
|
-
}).join('');
|
|
4784
|
-
|
|
4785
4791
|
emptyEl.innerHTML = `
|
|
4786
4792
|
<div class="codelab-empty-editor__inner">
|
|
4787
|
-
<div class="codelab-empty-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
<
|
|
4791
|
-
</svg>
|
|
4792
|
-
</div>
|
|
4793
|
-
<h2 class="codelab-empty-editor__title">No Open Editors</h2>
|
|
4794
|
-
<p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
|
|
4795
|
-
<div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
|
|
4796
|
-
${fileBtns}
|
|
4797
|
-
</div>
|
|
4798
|
-
<div class="codelab-empty-editor__actions">
|
|
4799
|
-
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
|
|
4800
|
-
${CL_ICONS.play}
|
|
4801
|
-
<span>Run Demo</span>
|
|
4802
|
-
<span class="codelab-btn__kbd">⇧⌘↵</span>
|
|
4793
|
+
<div class="codelab-empty-editor__watermark" aria-hidden="true">code-lab</div>
|
|
4794
|
+
<div class="codelab-empty-editor__shortcuts" role="group" aria-label="Quick actions">
|
|
4795
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette-files">
|
|
4796
|
+
<span>Go to File</span><kbd>⌘P</kbd>
|
|
4803
4797
|
</button>
|
|
4804
|
-
<button type="button" class="codelab-
|
|
4805
|
-
|
|
4806
|
-
<span>Run Tests</span>
|
|
4807
|
-
<span class="codelab-btn__kbd">⌘↵</span>
|
|
4798
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette">
|
|
4799
|
+
<span>Show All Commands</span><kbd>⌘⇧P</kbd>
|
|
4808
4800
|
</button>
|
|
4809
4801
|
</div>
|
|
4802
|
+
<p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
|
|
4810
4803
|
</div>
|
|
4811
4804
|
`;
|
|
4812
4805
|
}
|
|
@@ -4876,7 +4869,7 @@ declare module 'bun:sqlite' {
|
|
|
4876
4869
|
this.openCommandPalette('files');
|
|
4877
4870
|
return;
|
|
4878
4871
|
}
|
|
4879
|
-
if (
|
|
4872
|
+
if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
|
|
4880
4873
|
const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
|
|
4881
4874
|
if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
|
|
4882
4875
|
e.preventDefault();
|
|
@@ -5178,6 +5171,7 @@ declare module 'bun:sqlite' {
|
|
|
5178
5171
|
if (action === 'run-demo') this.runDemo();
|
|
5179
5172
|
else if (action === 'run-tests') this.runTests();
|
|
5180
5173
|
else if (action === 'stop-run') this.stopExecution();
|
|
5174
|
+
else if (action === 'interrupt') this._handleInterrupt();
|
|
5181
5175
|
else if (action === 'verify-step') this.verifyCurrentStep();
|
|
5182
5176
|
else if (action === 'show-diff') this.showSolutionModal();
|
|
5183
5177
|
else if (action === 'compare-diff') {
|
|
@@ -5771,6 +5765,48 @@ declare module 'bun:sqlite' {
|
|
|
5771
5765
|
hSplitter.addEventListener('pointerup', onUp);
|
|
5772
5766
|
});
|
|
5773
5767
|
}
|
|
5768
|
+
|
|
5769
|
+
const fSplitter = this.container.querySelector('#cl-splitter-files');
|
|
5770
|
+
if (fSplitter) {
|
|
5771
|
+
const applyWidth = (w) => {
|
|
5772
|
+
this.explorerWidth = Math.round(w);
|
|
5773
|
+
shell.style.setProperty('--cl-explorer-width', `${this.explorerWidth}px`);
|
|
5774
|
+
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
5775
|
+
};
|
|
5776
|
+
|
|
5777
|
+
fSplitter.addEventListener('dblclick', () => {
|
|
5778
|
+
applyWidth(196);
|
|
5779
|
+
this._saveState();
|
|
5780
|
+
});
|
|
5781
|
+
|
|
5782
|
+
fSplitter.addEventListener('pointerdown', e => {
|
|
5783
|
+
e.preventDefault();
|
|
5784
|
+
fSplitter.classList.add('is-dragging');
|
|
5785
|
+
shell.classList.add('is-resizing');
|
|
5786
|
+
try { fSplitter.setPointerCapture(e.pointerId); } catch (_) {}
|
|
5787
|
+
|
|
5788
|
+
const onMove = ev => {
|
|
5789
|
+
const ws = this.container.querySelector('.codelab-workspace');
|
|
5790
|
+
const rect = (ws || shell).getBoundingClientRect();
|
|
5791
|
+
const minW = 140;
|
|
5792
|
+
const maxW = Math.max(minW, Math.floor(rect.width * 0.5));
|
|
5793
|
+
const nextW = Math.min(maxW, Math.max(minW, Math.round(ev.clientX - rect.left)));
|
|
5794
|
+
applyWidth(nextW);
|
|
5795
|
+
};
|
|
5796
|
+
|
|
5797
|
+
const onUp = ev => {
|
|
5798
|
+
fSplitter.classList.remove('is-dragging');
|
|
5799
|
+
shell.classList.remove('is-resizing');
|
|
5800
|
+
try { fSplitter.releasePointerCapture(ev.pointerId); } catch (_) {}
|
|
5801
|
+
fSplitter.removeEventListener('pointermove', onMove);
|
|
5802
|
+
fSplitter.removeEventListener('pointerup', onUp);
|
|
5803
|
+
this._saveState();
|
|
5804
|
+
};
|
|
5805
|
+
|
|
5806
|
+
fSplitter.addEventListener('pointermove', onMove);
|
|
5807
|
+
fSplitter.addEventListener('pointerup', onUp);
|
|
5808
|
+
});
|
|
5809
|
+
}
|
|
5774
5810
|
}
|
|
5775
5811
|
|
|
5776
5812
|
selectStep(idx, shouldJump = true) {
|
|
@@ -6050,14 +6086,14 @@ declare module 'bun:sqlite' {
|
|
|
6050
6086
|
</div>
|
|
6051
6087
|
${pkgs.length === 0 ? `
|
|
6052
6088
|
<div style="padding:12px;border:1px solid var(--cl-border);border-radius:var(--cl-radius-sm);background:var(--cl-bg);color:var(--cl-fg-muted);font-size:12.5px;">
|
|
6053
|
-
No external npm packages imported yet. Any <code>import ... from 'pkg'</code> or <code>require('pkg')</code> in your code is automatically resolved via <strong>
|
|
6089
|
+
No external npm packages imported yet. Any <code>import ... from 'pkg'</code> or <code>require('pkg')</code> in your code is automatically resolved via <strong>jsDelivr</strong> when you run or test.
|
|
6054
6090
|
</div>
|
|
6055
6091
|
` : `
|
|
6056
6092
|
<div style="display:flex;flex-direction:column;gap:6px;">
|
|
6057
6093
|
${pkgs.map(p => `
|
|
6058
6094
|
<div style="display:flex;align-items:center;justify-content:space-between;padding:8px 12px;border:1px solid var(--cl-border);border-radius:var(--cl-radius-sm);background:var(--cl-bg);font-family:var(--cl-font-mono);font-size:12px;">
|
|
6059
6095
|
<span style="color:var(--cl-fg);font-weight:600;">${escapeHtml(p.name)}</span>
|
|
6060
|
-
<span style="color:var(--cl-accent);">${escapeHtml(p.version)} ·
|
|
6096
|
+
<span style="color:var(--cl-accent);">${escapeHtml(p.version)} · jsDelivr</span>
|
|
6061
6097
|
</div>
|
|
6062
6098
|
`).join('')}
|
|
6063
6099
|
</div>
|
|
@@ -6167,6 +6203,12 @@ declare module 'bun:sqlite' {
|
|
|
6167
6203
|
}
|
|
6168
6204
|
|
|
6169
6205
|
// ── Execution Engine (Web Worker + Virtual Node Runtime) ───────────────
|
|
6206
|
+
_isAbortResult(res, signal) {
|
|
6207
|
+
if (signal && signal.aborted) return true;
|
|
6208
|
+
if (!res || typeof res !== 'object') return false;
|
|
6209
|
+
return Boolean(res.cancelled || res.aborted || res.exitCode === 130);
|
|
6210
|
+
}
|
|
6211
|
+
|
|
6170
6212
|
async _executeRuntime(execOptions) {
|
|
6171
6213
|
const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
6172
6214
|
const payload = {
|
|
@@ -6185,9 +6227,14 @@ declare module 'bun:sqlite' {
|
|
|
6185
6227
|
if (detectedList.length > 0) {
|
|
6186
6228
|
this._setRuntimeStatus('fetching', `Fetching ${detectedList.map(d => typeof d === 'string' ? d : d.name).join(', ')}...`);
|
|
6187
6229
|
}
|
|
6188
|
-
await root.CodeLabRuntime.preloadNpmPackages(payload.files, pkgName => {
|
|
6189
|
-
this._setRuntimeStatus('fetching', `Fetching ${pkgName} from
|
|
6230
|
+
const preloaded = await root.CodeLabRuntime.preloadNpmPackages(payload.files, pkgName => {
|
|
6231
|
+
this._setRuntimeStatus('fetching', `Fetching ${pkgName} from jsDelivr CDN...`);
|
|
6190
6232
|
});
|
|
6233
|
+
// Hand the fetched module sources to the runtime so the Web Worker
|
|
6234
|
+
// (which has an isolated module cache) can resolve them from node_modules.
|
|
6235
|
+
if (preloaded && typeof preloaded === 'object' && Object.keys(preloaded).length > 0) {
|
|
6236
|
+
payload.packages = Object.assign({}, preloaded, payload.packages || {});
|
|
6237
|
+
}
|
|
6191
6238
|
}
|
|
6192
6239
|
this._setRuntimeStatus('running', `Running ${payload.entry || payload.mode || 'script'}...`);
|
|
6193
6240
|
let res;
|
|
@@ -6203,7 +6250,11 @@ declare module 'bun:sqlite' {
|
|
|
6203
6250
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
6204
6251
|
return res;
|
|
6205
6252
|
} catch (err) {
|
|
6206
|
-
|
|
6253
|
+
if (payload.signal && payload.signal.aborted) {
|
|
6254
|
+
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
6255
|
+
} else {
|
|
6256
|
+
this._setRuntimeStatus('error', 'Execution error');
|
|
6257
|
+
}
|
|
6207
6258
|
throw err;
|
|
6208
6259
|
}
|
|
6209
6260
|
}
|
|
@@ -6245,18 +6296,21 @@ declare module 'bun:sqlite' {
|
|
|
6245
6296
|
}
|
|
6246
6297
|
});
|
|
6247
6298
|
this._flushTerminalStream();
|
|
6299
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
6248
6300
|
|
|
6249
|
-
if (!streamedStdout && res.stdout) {
|
|
6301
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
6250
6302
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
6251
6303
|
}
|
|
6252
|
-
if (!streamedStderr && res.stderr) {
|
|
6304
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
6253
6305
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6254
6306
|
}
|
|
6255
|
-
if (res.error) {
|
|
6307
|
+
if (!aborted && res.error) {
|
|
6256
6308
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6257
6309
|
}
|
|
6258
|
-
|
|
6259
|
-
|
|
6310
|
+
if (!aborted) {
|
|
6311
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
6312
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
6313
|
+
}
|
|
6260
6314
|
|
|
6261
6315
|
if (this.onRun) {
|
|
6262
6316
|
try { this.onRun(res); } catch (_) {}
|
|
@@ -6264,7 +6318,9 @@ declare module 'bun:sqlite' {
|
|
|
6264
6318
|
this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
|
|
6265
6319
|
} catch (err) {
|
|
6266
6320
|
this._flushTerminalStream();
|
|
6267
|
-
|
|
6321
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6322
|
+
this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
|
|
6323
|
+
}
|
|
6268
6324
|
} finally {
|
|
6269
6325
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
6270
6326
|
this._activeCommandAbortController = null;
|
|
@@ -6313,18 +6369,21 @@ declare module 'bun:sqlite' {
|
|
|
6313
6369
|
}
|
|
6314
6370
|
});
|
|
6315
6371
|
this._flushTerminalStream();
|
|
6372
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
6316
6373
|
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6374
|
+
if (!aborted) {
|
|
6375
|
+
this.lastTestResults = res.testResults || [];
|
|
6376
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
6377
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
6378
|
+
}
|
|
6320
6379
|
|
|
6321
|
-
if (!streamedStdout && res.stdout) {
|
|
6380
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
6322
6381
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
6323
6382
|
}
|
|
6324
|
-
if (!streamedStderr && res.stderr) {
|
|
6383
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
6325
6384
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6326
6385
|
}
|
|
6327
|
-
if (res.error) {
|
|
6386
|
+
if (!aborted && res.error) {
|
|
6328
6387
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6329
6388
|
}
|
|
6330
6389
|
|
|
@@ -6375,7 +6434,9 @@ declare module 'bun:sqlite' {
|
|
|
6375
6434
|
}
|
|
6376
6435
|
} catch (err) {
|
|
6377
6436
|
this._flushTerminalStream();
|
|
6378
|
-
|
|
6437
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6438
|
+
this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
|
|
6439
|
+
}
|
|
6379
6440
|
} finally {
|
|
6380
6441
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
6381
6442
|
this._activeCommandAbortController = null;
|
|
@@ -6466,16 +6527,19 @@ declare module 'bun:sqlite' {
|
|
|
6466
6527
|
onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
|
|
6467
6528
|
});
|
|
6468
6529
|
this._flushTerminalStream();
|
|
6530
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
6469
6531
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
6470
|
-
if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
6471
|
-
if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6472
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6532
|
+
if (!aborted && !streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
6533
|
+
if (!aborted && !streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6534
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6473
6535
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
6474
6536
|
}
|
|
6475
|
-
if (res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6537
|
+
if (!aborted && res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
6476
6538
|
} catch (err) {
|
|
6477
6539
|
this._flushTerminalStream();
|
|
6478
|
-
|
|
6540
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6541
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
6542
|
+
}
|
|
6479
6543
|
} finally {
|
|
6480
6544
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
6481
6545
|
this._activeCommandAbortController = null;
|
|
@@ -6507,8 +6571,17 @@ declare module 'bun:sqlite' {
|
|
|
6507
6571
|
return;
|
|
6508
6572
|
}
|
|
6509
6573
|
|
|
6510
|
-
const
|
|
6511
|
-
|
|
6574
|
+
const firstWord = (trimmed.split(/\s+/)[0] || '').replace(/^.*\//, '');
|
|
6575
|
+
const shellKnowsCommand = Boolean(
|
|
6576
|
+
firstWord &&
|
|
6577
|
+
this.shell &&
|
|
6578
|
+
typeof this.shell.hasCommand === 'function' &&
|
|
6579
|
+
this.shell.hasCommand(firstWord)
|
|
6580
|
+
);
|
|
6581
|
+
const looksLikeJsExpr = !shellKnowsCommand && (
|
|
6582
|
+
/^(const|let|var|function|class|await|return|typeof|instanceof|new\s+|Math\.|JSON\.|Object\.|Array\.|Promise\.|console\.|process\.|Buffer\.|require\s*\(|import\s*\(|[0-9]+\s*[\+\-\*\/\%]|['"`\[{])/.test(trimmed)
|
|
6583
|
+
|| /^[a-zA-Z_$][\w$]*\s*(\.|===|!==|==|!=|<=|>=|\+=|-=|\*=|\(|\+\+|--)/.test(trimmed)
|
|
6584
|
+
);
|
|
6512
6585
|
|
|
6513
6586
|
if (this.shell && typeof this.shell.execute === 'function' && !looksLikeJsExpr) {
|
|
6514
6587
|
const abortCtrl = new AbortController();
|
|
@@ -6534,6 +6607,7 @@ declare module 'bun:sqlite' {
|
|
|
6534
6607
|
signal: abortCtrl.signal
|
|
6535
6608
|
});
|
|
6536
6609
|
this._flushTerminalStream();
|
|
6610
|
+
const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
|
|
6537
6611
|
this.cwd = this.shell.cwd || this.cwd;
|
|
6538
6612
|
this._syncVfsSnapshot(null, true);
|
|
6539
6613
|
|
|
@@ -6553,10 +6627,10 @@ declare module 'bun:sqlite' {
|
|
|
6553
6627
|
|
|
6554
6628
|
const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
|
|
6555
6629
|
if (!isCmdNotFound) {
|
|
6556
|
-
if (shellRes && shellRes.stdout && !streamedStdout) {
|
|
6630
|
+
if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
|
|
6557
6631
|
this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
|
|
6558
6632
|
}
|
|
6559
|
-
if (shellRes && shellRes.stderr && !streamedStderr) {
|
|
6633
|
+
if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
|
|
6560
6634
|
this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
|
|
6561
6635
|
}
|
|
6562
6636
|
this._renderDrawerBody();
|
|
@@ -6569,7 +6643,9 @@ declare module 'bun:sqlite' {
|
|
|
6569
6643
|
}
|
|
6570
6644
|
} catch (err) {
|
|
6571
6645
|
this._flushTerminalStream();
|
|
6572
|
-
|
|
6646
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6647
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
6648
|
+
}
|
|
6573
6649
|
this._renderDrawerBody();
|
|
6574
6650
|
return;
|
|
6575
6651
|
} finally {
|
|
@@ -6605,17 +6681,18 @@ declare module 'bun:sqlite' {
|
|
|
6605
6681
|
}
|
|
6606
6682
|
});
|
|
6607
6683
|
this._flushTerminalStream();
|
|
6684
|
+
const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
|
|
6608
6685
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
6609
|
-
if (!streamedFallbackStdout && cleanStdout) {
|
|
6686
|
+
if (!aborted && !streamedFallbackStdout && cleanStdout) {
|
|
6610
6687
|
this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
6611
6688
|
}
|
|
6612
|
-
if (!streamedFallbackStderr && res.stderr) {
|
|
6689
|
+
if (!aborted && !streamedFallbackStderr && res.stderr) {
|
|
6613
6690
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
6614
6691
|
}
|
|
6615
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6692
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
6616
6693
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
6617
6694
|
}
|
|
6618
|
-
if (res.error) {
|
|
6695
|
+
if (!aborted && res.error) {
|
|
6619
6696
|
const errStr = formatErrorText(res.error);
|
|
6620
6697
|
if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
|
|
6621
6698
|
this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
|
|
@@ -6625,7 +6702,9 @@ declare module 'bun:sqlite' {
|
|
|
6625
6702
|
}
|
|
6626
6703
|
} catch (err) {
|
|
6627
6704
|
this._flushTerminalStream();
|
|
6628
|
-
|
|
6705
|
+
if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
6706
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
6707
|
+
}
|
|
6629
6708
|
} finally {
|
|
6630
6709
|
if (this._activeCommandAbortController === fallbackAbortCtrl) {
|
|
6631
6710
|
this._activeCommandAbortController = null;
|
|
@@ -6877,8 +6956,13 @@ declare module 'bun:sqlite' {
|
|
|
6877
6956
|
const intoRoot = options.intoRoot !== false;
|
|
6878
6957
|
const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
|
|
6879
6958
|
const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
|
|
6959
|
+
this.drawerTab = 'terminal';
|
|
6880
6960
|
this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
|
|
6961
|
+
this.isRunning = true;
|
|
6962
|
+
const abortCtrl = new AbortController();
|
|
6963
|
+
this._activeCommandAbortController = abortCtrl;
|
|
6881
6964
|
this._renderDrawerBody();
|
|
6965
|
+
this._updateRunStateUI();
|
|
6882
6966
|
|
|
6883
6967
|
try {
|
|
6884
6968
|
if (intoRoot && this.shell && this.shell.vfs) {
|
|
@@ -6901,6 +6985,7 @@ declare module 'bun:sqlite' {
|
|
|
6901
6985
|
maxFiles: options.maxFiles || 250,
|
|
6902
6986
|
maxFileSize: options.maxFileSize || 512 * 1024,
|
|
6903
6987
|
fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
|
|
6988
|
+
signal: abortCtrl.signal,
|
|
6904
6989
|
onProgress: options.onProgress
|
|
6905
6990
|
});
|
|
6906
6991
|
|
|
@@ -6972,10 +7057,18 @@ declare module 'bun:sqlite' {
|
|
|
6972
7057
|
this._emitEvent('repo:cloned', eventDetail);
|
|
6973
7058
|
return result;
|
|
6974
7059
|
} catch (err) {
|
|
6975
|
-
|
|
6976
|
-
|
|
7060
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
7061
|
+
const msg = err && err.message ? err.message : String(err);
|
|
7062
|
+
this.terminalLogs.push({ type: 'stderr', text: msg });
|
|
7063
|
+
}
|
|
6977
7064
|
this._renderDrawerBody();
|
|
6978
7065
|
throw err;
|
|
7066
|
+
} finally {
|
|
7067
|
+
if (this._activeCommandAbortController === abortCtrl) {
|
|
7068
|
+
this._activeCommandAbortController = null;
|
|
7069
|
+
}
|
|
7070
|
+
this.isRunning = false;
|
|
7071
|
+
this._updateRunStateUI();
|
|
6979
7072
|
}
|
|
6980
7073
|
}
|
|
6981
7074
|
|