@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/dist/code-lab.esm.js
CHANGED
|
@@ -4681,8 +4681,22 @@ function __initVirtualRuntime(rootScope) {
|
|
|
4681
4681
|
}
|
|
4682
4682
|
|
|
4683
4683
|
const _npmPackageCache = new Map();
|
|
4684
|
+
const _npmMetadataCache = new Map();
|
|
4685
|
+
|
|
4686
|
+
async function preloadNpmPackages(files = {}, secondArg = null, thirdArg = null) {
|
|
4687
|
+
// The 2nd/3rd arguments are overloaded for backwards compatibility:
|
|
4688
|
+
// preloadNpmPackages(files)
|
|
4689
|
+
// preloadNpmPackages(files, onProgress) // progress callback (used by the Workbench)
|
|
4690
|
+
// preloadNpmPackages(files, existingCache) // package-text cache (Map)
|
|
4691
|
+
// preloadNpmPackages(files, existingCache, onProgress)
|
|
4692
|
+
const isCacheLike = (v) => !!v && typeof v !== 'function' && typeof v.has === 'function' && typeof v.get === 'function';
|
|
4693
|
+
let onProgress = null;
|
|
4694
|
+
let existingCache = _npmPackageCache;
|
|
4695
|
+
if (typeof secondArg === 'function') onProgress = secondArg;
|
|
4696
|
+
else if (isCacheLike(secondArg)) existingCache = secondArg;
|
|
4697
|
+
if (typeof thirdArg === 'function') onProgress = onProgress || thirdArg;
|
|
4698
|
+
else if (isCacheLike(thirdArg)) existingCache = thirdArg;
|
|
4684
4699
|
|
|
4685
|
-
async function preloadNpmPackages(files = {}, existingCache = _npmPackageCache) {
|
|
4686
4700
|
const specs = new Set();
|
|
4687
4701
|
const builtinSet = new Set([
|
|
4688
4702
|
'fs', 'fs/promises', 'path', 'os', 'crypto', 'zlib', 'http', 'https', 'net',
|
|
@@ -4718,20 +4732,51 @@ function __initVirtualRuntime(rootScope) {
|
|
|
4718
4732
|
while ((m = impRe.exec(content)) !== null) addSpec(m[1]);
|
|
4719
4733
|
}
|
|
4720
4734
|
|
|
4735
|
+
// Follow declared dependencies transitively (best effort, bounded). Metadata
|
|
4736
|
+
// is memoised across calls so repeated preloads stay cheap.
|
|
4737
|
+
if (typeof fetch === 'function') {
|
|
4738
|
+
let pass = 0;
|
|
4739
|
+
while (pass < 6) {
|
|
4740
|
+
const pending = [];
|
|
4741
|
+
for (const pkg of specs) {
|
|
4742
|
+
if (!_npmMetadataCache.has(pkg)) pending.push(pkg);
|
|
4743
|
+
}
|
|
4744
|
+
if (pending.length === 0) break;
|
|
4745
|
+
pass++;
|
|
4746
|
+
await Promise.all(pending.map(async (pkg) => {
|
|
4747
|
+
let deps = [];
|
|
4748
|
+
try {
|
|
4749
|
+
const res = await fetch(`https://cdn.jsdelivr.net/npm/${pkg}/package.json`);
|
|
4750
|
+
if (res && res.ok) {
|
|
4751
|
+
const meta = await res.json();
|
|
4752
|
+
deps = Object.keys((meta && meta.dependencies) || {});
|
|
4753
|
+
}
|
|
4754
|
+
} catch (_) {}
|
|
4755
|
+
_npmMetadataCache.set(pkg, deps);
|
|
4756
|
+
}));
|
|
4757
|
+
for (const pkg of pending) {
|
|
4758
|
+
for (const dep of (_npmMetadataCache.get(pkg) || [])) addSpec(dep);
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
|
|
4721
4763
|
const loaded = {};
|
|
4722
4764
|
for (const pkg of specs) {
|
|
4723
4765
|
const nmKey = `node_modules/${pkg}/index.js`;
|
|
4724
4766
|
if (files[nmKey] || files[`/workspace/${nmKey}`]) continue;
|
|
4725
|
-
if (existingCache
|
|
4767
|
+
if (existingCache.has(pkg)) {
|
|
4726
4768
|
loaded[pkg] = existingCache.get(pkg);
|
|
4727
4769
|
continue;
|
|
4728
4770
|
}
|
|
4771
|
+
if (typeof onProgress === 'function') {
|
|
4772
|
+
try { onProgress(pkg); } catch (_) {}
|
|
4773
|
+
}
|
|
4729
4774
|
if (typeof fetch === 'function') {
|
|
4730
4775
|
try {
|
|
4731
4776
|
const res = await fetch(`https://cdn.jsdelivr.net/npm/${pkg}`);
|
|
4732
4777
|
if (res && res.ok) {
|
|
4733
4778
|
const text = await res.text();
|
|
4734
|
-
if (existingCache) existingCache.set(pkg, text);
|
|
4779
|
+
if (typeof existingCache.set === 'function') existingCache.set(pkg, text);
|
|
4735
4780
|
loaded[pkg] = text;
|
|
4736
4781
|
}
|
|
4737
4782
|
} catch (_) {}
|
|
@@ -9499,6 +9544,16 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9499
9544
|
const requestedBranch = options.branch || parsed.branch || null;
|
|
9500
9545
|
const { owner, repo } = parsed;
|
|
9501
9546
|
|
|
9547
|
+
const signal = options.signal || null;
|
|
9548
|
+
const throwIfAborted = () => {
|
|
9549
|
+
if (signal && signal.aborted) {
|
|
9550
|
+
const abortErr = new Error('fatal: clone cancelled (SIGINT)');
|
|
9551
|
+
abortErr.name = 'AbortError';
|
|
9552
|
+
throw abortErr;
|
|
9553
|
+
}
|
|
9554
|
+
};
|
|
9555
|
+
throwIfAborted();
|
|
9556
|
+
|
|
9502
9557
|
let resolvedBranch = requestedBranch;
|
|
9503
9558
|
let rawTreeEntries = null;
|
|
9504
9559
|
let repoNotFound = false;
|
|
@@ -9511,7 +9566,8 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9511
9566
|
try {
|
|
9512
9567
|
if (!resolvedBranch) {
|
|
9513
9568
|
const metaRes = await fetchFn(`https://api.github.com/repos/${owner}/${repo}`, {
|
|
9514
|
-
headers: { Accept: 'application/vnd.github.v3+json' }
|
|
9569
|
+
headers: { Accept: 'application/vnd.github.v3+json' },
|
|
9570
|
+
signal
|
|
9515
9571
|
});
|
|
9516
9572
|
if (metaRes.status === 404) {
|
|
9517
9573
|
repoNotFound = true;
|
|
@@ -9529,9 +9585,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9529
9585
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
9530
9586
|
|
|
9531
9587
|
for (const cand of branchCandidates) {
|
|
9588
|
+
throwIfAborted();
|
|
9532
9589
|
const treeRes = await fetchFn(
|
|
9533
9590
|
`https://api.github.com/repos/${owner}/${repo}/git/trees/${encodeURIComponent(cand)}?recursive=1`,
|
|
9534
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
9591
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
9535
9592
|
);
|
|
9536
9593
|
if (treeRes.ok) {
|
|
9537
9594
|
const treeJson = await treeRes.json();
|
|
@@ -9557,8 +9614,10 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9557
9614
|
: Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
|
|
9558
9615
|
|
|
9559
9616
|
for (const cand of branchCandidates) {
|
|
9617
|
+
throwIfAborted();
|
|
9560
9618
|
const flatRes = await fetchFn(
|
|
9561
|
-
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat
|
|
9619
|
+
`https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`,
|
|
9620
|
+
{ signal }
|
|
9562
9621
|
);
|
|
9563
9622
|
if (flatRes && flatRes.ok) {
|
|
9564
9623
|
const flatJson = await flatRes.json();
|
|
@@ -9627,28 +9686,34 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9627
9686
|
const BATCH_SIZE = 12;
|
|
9628
9687
|
|
|
9629
9688
|
for (let i = 0; i < selectedFiles.length; i += BATCH_SIZE) {
|
|
9689
|
+
throwIfAborted();
|
|
9630
9690
|
const batch = selectedFiles.slice(i, i + BATCH_SIZE);
|
|
9631
9691
|
await Promise.all(
|
|
9632
9692
|
batch.map(async (entry) => {
|
|
9693
|
+
throwIfAborted();
|
|
9633
9694
|
const encodedPath = entry.repoPath.split('/').map(encodeURIComponent).join('/');
|
|
9634
9695
|
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
9635
9696
|
const cdnUrl = `https://cdn.jsdelivr.net/gh/${owner}/${repo}@${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
|
|
9636
9697
|
|
|
9637
9698
|
let text = null;
|
|
9638
9699
|
try {
|
|
9639
|
-
const r1 = await fetchFn(rawUrl);
|
|
9700
|
+
const r1 = await fetchFn(rawUrl, { signal });
|
|
9640
9701
|
if (r1 && r1.ok) {
|
|
9641
9702
|
text = await r1.text();
|
|
9642
9703
|
}
|
|
9643
|
-
} catch (_) {
|
|
9704
|
+
} catch (_) {
|
|
9705
|
+
if (signal && signal.aborted) throw _;
|
|
9706
|
+
}
|
|
9644
9707
|
|
|
9645
9708
|
if (text === null) {
|
|
9646
9709
|
try {
|
|
9647
|
-
const r2 = await fetchFn(cdnUrl);
|
|
9710
|
+
const r2 = await fetchFn(cdnUrl, { signal });
|
|
9648
9711
|
if (r2 && r2.ok) {
|
|
9649
9712
|
text = await r2.text();
|
|
9650
9713
|
}
|
|
9651
|
-
} catch (_) {
|
|
9714
|
+
} catch (_) {
|
|
9715
|
+
if (signal && signal.aborted) throw _;
|
|
9716
|
+
}
|
|
9652
9717
|
}
|
|
9653
9718
|
|
|
9654
9719
|
if (text !== null && text.length <= maxFileSize) {
|
|
@@ -9672,6 +9737,8 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9672
9737
|
);
|
|
9673
9738
|
}
|
|
9674
9739
|
|
|
9740
|
+
throwIfAborted();
|
|
9741
|
+
|
|
9675
9742
|
if (onProgress) {
|
|
9676
9743
|
onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
|
|
9677
9744
|
}
|
|
@@ -9692,7 +9759,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9692
9759
|
try {
|
|
9693
9760
|
const commitsRes = await fetchFn(
|
|
9694
9761
|
`https://api.github.com/repos/${owner}/${repo}/commits?sha=${encodeURIComponent(resolvedBranch)}&per_page=10`,
|
|
9695
|
-
{ headers: { Accept: 'application/vnd.github.v3+json' } }
|
|
9762
|
+
{ headers: { Accept: 'application/vnd.github.v3+json' }, signal }
|
|
9696
9763
|
);
|
|
9697
9764
|
if (commitsRes && commitsRes.ok) {
|
|
9698
9765
|
const commitsJson = await commitsRes.json();
|
|
@@ -9804,38 +9871,221 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
9804
9871
|
} catch (_) {}
|
|
9805
9872
|
}
|
|
9806
9873
|
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9874
|
+
// ---------------------------------------------------------------------------
|
|
9875
|
+
// Real npm package installation via the jsDelivr CDN
|
|
9876
|
+
// ---------------------------------------------------------------------------
|
|
9877
|
+
const CDN_NPM_BASE = 'https://cdn.jsdelivr.net/npm';
|
|
9878
|
+
|
|
9879
|
+
// Minimal offline registry, used only when the CDN is unreachable so common
|
|
9880
|
+
// demos still resolve without network access.
|
|
9881
|
+
const OFFLINE_PACKAGE_FALLBACKS = {
|
|
9882
|
+
'is-even': 'module.exports = function isEven(n) { return (Number(n) % 2) === 0; };\n',
|
|
9883
|
+
'tiny-invariant': 'module.exports = function invariant(condition, message) { if (!condition) throw new Error(message || "Invariant failed"); };\n',
|
|
9884
|
+
'lodash': 'module.exports = { isArray: Array.isArray, isObject: function (v) { return v !== null && typeof v === "object"; } };\n',
|
|
9885
|
+
'left-pad': 'module.exports = function leftPad(str, len, ch) { str = String(str); ch = (ch === undefined ? " " : String(ch)); while (str.length < len) str = ch + str; return str.slice(-len); };\n'
|
|
9886
|
+
};
|
|
9887
|
+
|
|
9888
|
+
function packageCtxFetch(ctx) {
|
|
9889
|
+
if (ctx && ctx.shell && ctx.shell.options && typeof ctx.shell.options.fetchImpl === 'function') {
|
|
9890
|
+
return ctx.shell.options.fetchImpl;
|
|
9891
|
+
}
|
|
9892
|
+
if (typeof fetch === 'function') return fetch.bind(globalThis);
|
|
9893
|
+
return null;
|
|
9894
|
+
}
|
|
9895
|
+
|
|
9896
|
+
function parsePackageSpec(spec) {
|
|
9897
|
+
const raw = String(spec || '').trim();
|
|
9898
|
+
if (!raw) return { name: '', range: null };
|
|
9899
|
+
if (raw.startsWith('@')) {
|
|
9900
|
+
const at = raw.indexOf('@', 1);
|
|
9901
|
+
if (at === -1) return { name: raw, range: null };
|
|
9902
|
+
return { name: raw.slice(0, at), range: raw.slice(at + 1) || null };
|
|
9903
|
+
}
|
|
9904
|
+
const at = raw.indexOf('@');
|
|
9905
|
+
if (at <= 0) return { name: raw, range: null };
|
|
9906
|
+
return { name: raw.slice(0, at), range: raw.slice(at + 1) || null };
|
|
9907
|
+
}
|
|
9908
|
+
|
|
9909
|
+
function resolveEntryRelPath(pkgJson) {
|
|
9910
|
+
let entry = pkgJson.main || pkgJson.module ||
|
|
9911
|
+
(typeof pkgJson.browser === 'string' ? pkgJson.browser : '') || 'index.js';
|
|
9912
|
+
entry = String(entry).replace(/^[./]+/, '');
|
|
9913
|
+
return entry || 'index.js';
|
|
9914
|
+
}
|
|
9915
|
+
|
|
9916
|
+
function stripRelPath(rel) {
|
|
9917
|
+
return String(rel || '').replace(/^[./]+/, '');
|
|
9918
|
+
}
|
|
9919
|
+
|
|
9920
|
+
function extractRelativeSpecifiers(code) {
|
|
9921
|
+
const out = new Set();
|
|
9922
|
+
const re = /(?:\brequire\s*\(\s*|\bimport\s+[\s\S]{0,120}?\bfrom\s*|\bimport\s*\(\s*)['"](\.{1,2}\/[^'"]+)['"]/g;
|
|
9923
|
+
let m;
|
|
9924
|
+
while ((m = re.exec(code)) !== null) out.add(m[1]);
|
|
9925
|
+
return Array.from(out);
|
|
9926
|
+
}
|
|
9927
|
+
|
|
9928
|
+
function normalizeRelPath(baseDir, rel) {
|
|
9929
|
+
const parts = String(baseDir || '').split('/').filter(Boolean);
|
|
9930
|
+
for (const seg of String(rel).split('/')) {
|
|
9931
|
+
if (!seg || seg === '.') continue;
|
|
9932
|
+
if (seg === '..') parts.pop();
|
|
9933
|
+
else parts.push(seg);
|
|
9934
|
+
}
|
|
9935
|
+
return parts.join('/');
|
|
9936
|
+
}
|
|
9937
|
+
|
|
9938
|
+
async function fetchTextFromCdn(fetchImpl, url) {
|
|
9939
|
+
try {
|
|
9940
|
+
const res = await fetchImpl(url);
|
|
9941
|
+
if (!res) return null;
|
|
9942
|
+
const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
|
|
9943
|
+
if (!ok) return null;
|
|
9944
|
+
if (typeof res.text === 'function') return await res.text();
|
|
9945
|
+
return String(res.body != null ? res.body : '');
|
|
9946
|
+
} catch (_) {
|
|
9947
|
+
return null;
|
|
9948
|
+
}
|
|
9949
|
+
}
|
|
9950
|
+
|
|
9951
|
+
async function resolvePackageMetadata(fetchImpl, name, range) {
|
|
9952
|
+
const urls = range
|
|
9953
|
+
? [`${CDN_NPM_BASE}/${name}@${range}/package.json`, `${CDN_NPM_BASE}/${name}/package.json`]
|
|
9954
|
+
: [`${CDN_NPM_BASE}/${name}/package.json`];
|
|
9955
|
+
for (const url of urls) {
|
|
9956
|
+
const text = await fetchTextFromCdn(fetchImpl, url);
|
|
9957
|
+
if (!text) continue;
|
|
9958
|
+
try {
|
|
9959
|
+
const parsed = JSON.parse(text);
|
|
9960
|
+
if (parsed && parsed.version) return parsed;
|
|
9961
|
+
} catch (_) {}
|
|
9962
|
+
}
|
|
9963
|
+
return null;
|
|
9964
|
+
}
|
|
9965
|
+
|
|
9966
|
+
// Download a package's entry module, its relative submodules and record its
|
|
9967
|
+
// declared dependencies so the caller can resolve them transitively.
|
|
9968
|
+
async function downloadPackageFiles(fetchImpl, name, range, seen) {
|
|
9969
|
+
const meta = await resolvePackageMetadata(fetchImpl, name, range);
|
|
9970
|
+
if (!meta) {
|
|
9971
|
+
const fallback = OFFLINE_PACKAGE_FALLBACKS[name];
|
|
9972
|
+
if (fallback) {
|
|
9973
|
+
const v = range ? range.replace(/^[\^~>=<\s]+/, '') || '1.0.0' : '1.0.0';
|
|
9974
|
+
return { ok: true, offline: true, version: v, entry: 'index.js', files: [{ rel: 'index.js', content: fallback }], deps: [] };
|
|
9975
|
+
}
|
|
9976
|
+
return { ok: false, reason: `${name}: package metadata not found on the registry (offline?)` };
|
|
9977
|
+
}
|
|
9978
|
+
|
|
9979
|
+
const version = meta.version;
|
|
9980
|
+
const key = `${name}@${version}`;
|
|
9981
|
+
if (seen.has(key)) {
|
|
9982
|
+
return { ok: true, deduped: true, version, entry: resolveEntryRelPath(meta), files: [], deps: [] };
|
|
9983
|
+
}
|
|
9984
|
+
seen.add(key);
|
|
9985
|
+
|
|
9986
|
+
const entry = resolveEntryRelPath(meta);
|
|
9987
|
+
const files = [];
|
|
9988
|
+
const visited = new Set();
|
|
9989
|
+
const queue = [entry];
|
|
9990
|
+
while (queue.length > 0) {
|
|
9991
|
+
const rel = stripRelPath(queue.shift());
|
|
9992
|
+
if (!rel || visited.has(rel)) continue;
|
|
9993
|
+
visited.add(rel);
|
|
9994
|
+
const text = await fetchTextFromCdn(fetchImpl, `${CDN_NPM_BASE}/${name}@${version}/${rel}`);
|
|
9995
|
+
if (text === null) continue;
|
|
9996
|
+
files.push({ rel, content: text });
|
|
9997
|
+
const baseDir = rel.includes('/') ? rel.slice(0, rel.lastIndexOf('/')) : '';
|
|
9998
|
+
for (const spec of extractRelativeSpecifiers(text)) {
|
|
9999
|
+
const target = normalizeRelPath(baseDir, spec);
|
|
10000
|
+
for (const cand of [target, `${target}.js`, `${target}.json`, `${target}/index.js`]) {
|
|
10001
|
+
const c = stripRelPath(cand);
|
|
10002
|
+
if (c && !visited.has(c)) { queue.push(cand); break; }
|
|
10003
|
+
}
|
|
10004
|
+
}
|
|
10005
|
+
}
|
|
10006
|
+
// The declared entry may be missing on the CDN; fall back to index.js.
|
|
10007
|
+
if (!files.some(f => f.rel === entry)) {
|
|
10008
|
+
const idxText = await fetchTextFromCdn(fetchImpl, `${CDN_NPM_BASE}/${name}@${version}/index.js`);
|
|
10009
|
+
if (idxText !== null) files.push({ rel: 'index.js', content: idxText });
|
|
10010
|
+
}
|
|
10011
|
+
|
|
10012
|
+
return { ok: true, version, entry, files, deps: Object.keys(meta.dependencies || {}) };
|
|
10013
|
+
}
|
|
10014
|
+
|
|
10015
|
+
function installTargetDirs(ctx, name) {
|
|
10016
|
+
const dirs = ['/workspace/node_modules/' + name];
|
|
10017
|
+
const cwdTarget = PosixPath.join(ctx.cwd || '/workspace', 'node_modules', name);
|
|
10018
|
+
if (!dirs.includes(cwdTarget)) dirs.push(cwdTarget);
|
|
10019
|
+
return dirs;
|
|
10020
|
+
}
|
|
10021
|
+
|
|
10022
|
+
function writeInstalledPackageFiles(ctx, dirs, name, info) {
|
|
10023
|
+
for (const dir of dirs) {
|
|
10024
|
+
ensureDirSync(ctx.vfs, dir, ctx.emitMutation);
|
|
10025
|
+
for (const f of info.files) {
|
|
10026
|
+
const full = PosixPath.join(dir, f.rel);
|
|
10027
|
+
ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
|
|
10028
|
+
ctx.vfs.writeFileSync(full, f.content);
|
|
10029
|
+
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
|
|
10030
|
+
}
|
|
10031
|
+
const modPkgPath = PosixPath.join(dir, 'package.json');
|
|
10032
|
+
const modPkg = { name, version: info.version || '1.0.0', main: './' + (info.entry || 'index.js') };
|
|
10033
|
+
ctx.vfs.writeFileSync(modPkgPath, JSON.stringify(modPkg, null, 2) + '\n');
|
|
10034
|
+
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', modPkgPath);
|
|
10035
|
+
}
|
|
10036
|
+
}
|
|
10037
|
+
|
|
10038
|
+
async function installPackage(pkgSpec, ctx) {
|
|
10039
|
+
const { name: pkgName, range } = parsePackageSpec(pkgSpec);
|
|
10040
|
+
if (!pkgName) return { name: null, ok: false, installed: [], warning: null };
|
|
9811
10041
|
|
|
9812
10042
|
const { path: pkgPath, data: pkgData } = readPackageJson(ctx.vfs, ctx.cwd);
|
|
9813
10043
|
if (!pkgData.dependencies) pkgData.dependencies = {};
|
|
9814
|
-
pkgData.dependencies[pkgName] = pkgVersion;
|
|
9815
|
-
writePackageJson(ctx.vfs, pkgPath, pkgData, ctx.emitMutation);
|
|
9816
10044
|
|
|
9817
|
-
const
|
|
9818
|
-
const
|
|
9819
|
-
|
|
10045
|
+
const fetchImpl = packageCtxFetch(ctx);
|
|
10046
|
+
const seen = (ctx.shell && ctx.shell._cdnSeen)
|
|
10047
|
+
? ctx.shell._cdnSeen
|
|
10048
|
+
: (ctx.shell ? (ctx.shell._cdnSeen = new Set()) : new Set());
|
|
10049
|
+
|
|
10050
|
+
const queue = [{ name: pkgName, range, direct: true }];
|
|
10051
|
+
const requested = new Set([pkgName]);
|
|
10052
|
+
const installed = [];
|
|
10053
|
+
let warning = null;
|
|
10054
|
+
let directVersion = null;
|
|
10055
|
+
|
|
10056
|
+
while (queue.length > 0) {
|
|
10057
|
+
const item = queue.shift();
|
|
10058
|
+
const info = fetchImpl
|
|
10059
|
+
? await downloadPackageFiles(fetchImpl, item.name, item.range, seen)
|
|
10060
|
+
: { ok: false, reason: `${item.name}: no fetch implementation available` };
|
|
10061
|
+
|
|
10062
|
+
if (!info.ok) {
|
|
10063
|
+
// Final fallback: an empty stub so offline demos still resolve the module.
|
|
10064
|
+
writeInstalledPackageFiles(ctx, installTargetDirs(ctx, item.name), item.name, {
|
|
10065
|
+
version: '0.0.0', entry: 'index.js', files: [{ rel: 'index.js', content: 'module.exports = {};\n' }]
|
|
10066
|
+
});
|
|
10067
|
+
if (!warning) warning = info.reason;
|
|
10068
|
+
installed.push({ name: item.name, version: '0.0.0' });
|
|
10069
|
+
continue;
|
|
10070
|
+
}
|
|
9820
10071
|
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
const modIndexPath = PosixPath.join(modDir, 'index.js');
|
|
9825
|
-
ctx.vfs.writeFileSync(modPkgPath, JSON.stringify({ name: pkgName, version: pkgVersion.replace(/^[\^~]/, ''), main: './index.js' }, null, 2) + '\n');
|
|
9826
|
-
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', modPkgPath);
|
|
10072
|
+
writeInstalledPackageFiles(ctx, installTargetDirs(ctx, item.name), item.name, info);
|
|
10073
|
+
installed.push({ name: item.name, version: info.version || '1.0.0' });
|
|
10074
|
+
if (item.direct) directVersion = info.version || null;
|
|
9827
10075
|
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
code = 'module.exports = { isArray: Array.isArray, isObject: function(v) { return v !== null && typeof v === "object"; } };\n';
|
|
10076
|
+
for (const dep of (info.deps || [])) {
|
|
10077
|
+
const parsed = parsePackageSpec(dep);
|
|
10078
|
+
if (parsed.name && !requested.has(parsed.name)) {
|
|
10079
|
+
requested.add(parsed.name);
|
|
10080
|
+
queue.push({ name: parsed.name, range: null, direct: false });
|
|
10081
|
+
}
|
|
9835
10082
|
}
|
|
9836
|
-
ctx.vfs.writeFileSync(modIndexPath, code);
|
|
9837
|
-
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', modIndexPath);
|
|
9838
10083
|
}
|
|
10084
|
+
|
|
10085
|
+
pkgData.dependencies[pkgName] = range || (directVersion ? `^${directVersion}` : (pkgData.dependencies[pkgName] || 'latest'));
|
|
10086
|
+
writePackageJson(ctx.vfs, pkgPath, pkgData, ctx.emitMutation);
|
|
10087
|
+
|
|
10088
|
+
return { name: pkgName, ok: true, version: directVersion, installed, warning };
|
|
9839
10089
|
}
|
|
9840
10090
|
|
|
9841
10091
|
function uninstallPackage(pkgName, ctx) {
|
|
@@ -11939,6 +12189,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11939
12189
|
targetDir,
|
|
11940
12190
|
branch: branchOpt,
|
|
11941
12191
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
12192
|
+
signal: ctx.signal,
|
|
11942
12193
|
onFile: (absPath) => ctx.emitMutation('create', absPath),
|
|
11943
12194
|
onProgress: (ev) => {
|
|
11944
12195
|
if (!ev) return;
|
|
@@ -11979,6 +12230,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
11979
12230
|
`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`;
|
|
11980
12231
|
return { code: 0, stdout, stderr: '' };
|
|
11981
12232
|
} catch (err) {
|
|
12233
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
12234
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
12235
|
+
}
|
|
11982
12236
|
const msg = err && err.message ? err.message : String(err);
|
|
11983
12237
|
if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
|
|
11984
12238
|
return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
@@ -12306,6 +12560,7 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12306
12560
|
targetDir: repoRoot,
|
|
12307
12561
|
branch: gitState.branch,
|
|
12308
12562
|
fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
|
|
12563
|
+
signal: ctx.signal,
|
|
12309
12564
|
onFile: (absPath) => ctx.emitMutation('change', absPath)
|
|
12310
12565
|
});
|
|
12311
12566
|
gitState.headSnapshot = Object.assign({}, result.headSnapshot);
|
|
@@ -12315,6 +12570,9 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12315
12570
|
stderr: ''
|
|
12316
12571
|
};
|
|
12317
12572
|
} catch (err) {
|
|
12573
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
12574
|
+
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
12575
|
+
}
|
|
12318
12576
|
const msg = err && err.message ? err.message : String(err);
|
|
12319
12577
|
return { code: 1, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
|
|
12320
12578
|
}
|
|
@@ -12504,6 +12762,18 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12504
12762
|
|
|
12505
12763
|
const sub = args[0];
|
|
12506
12764
|
|
|
12765
|
+
if (sub === '--version' || sub === '-v' || sub === '--revision') {
|
|
12766
|
+
return { code: 0, stdout: '1.1.20\n', stderr: '' };
|
|
12767
|
+
}
|
|
12768
|
+
|
|
12769
|
+
if (sub === '--help' || sub === '-h') {
|
|
12770
|
+
return {
|
|
12771
|
+
code: 0,
|
|
12772
|
+
stdout: 'Bun v1.1.20\nUsage: bun <command> [flags]\n\nCommands:\n run <file|script> Run a file or package script\n install, i, add Install dependencies\n remove, rm Remove dependencies\n test Run tests\n init Scaffold a new project\n -e <code> Evaluate JavaScript\n',
|
|
12773
|
+
stderr: ''
|
|
12774
|
+
};
|
|
12775
|
+
}
|
|
12776
|
+
|
|
12507
12777
|
if (sub === 'init') {
|
|
12508
12778
|
const pkgPath = PosixPath.join(ctx.cwd, 'package.json');
|
|
12509
12779
|
const dirName = PosixPath.basename(ctx.cwd) || 'app';
|
|
@@ -12553,12 +12823,28 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12553
12823
|
return { code: 0, stdout: 'Done! A package.json file was created in ' + ctx.cwd + '\n', stderr: '' };
|
|
12554
12824
|
}
|
|
12555
12825
|
|
|
12556
|
-
if (sub === '
|
|
12826
|
+
if (sub === 'install' || sub === 'i' || sub === 'ci') {
|
|
12557
12827
|
const pkgs = args.slice(1).filter(a => !a.startsWith('-'));
|
|
12558
|
-
|
|
12559
|
-
|
|
12828
|
+
if (pkgs.length === 0) {
|
|
12829
|
+
const { data: pkgData } = readPackageJson(ctx.vfs, ctx.cwd);
|
|
12830
|
+
const deps = Object.keys(pkgData.dependencies || {});
|
|
12831
|
+
const results = [];
|
|
12832
|
+
for (const p of deps) results.push(await installPackage(p, ctx));
|
|
12833
|
+
const warning = results.map(r => r && r.warning).filter(Boolean)[0];
|
|
12834
|
+
return { code: 0, stdout: deps.length === 0 ? 'up to date\n' : `installed ${deps.length} package(s)\n`, stderr: warning ? `bun warn ${warning}\n` : '' };
|
|
12560
12835
|
}
|
|
12561
|
-
|
|
12836
|
+
const results = [];
|
|
12837
|
+
for (const p of pkgs) results.push(await installPackage(p, ctx));
|
|
12838
|
+
const warning = results.map(r => r && r.warning).filter(Boolean)[0];
|
|
12839
|
+
return { code: 0, stdout: `saved ${results.filter(r => r && r.name).length} package(s)\n`, stderr: warning ? `bun warn ${warning}\n` : '' };
|
|
12840
|
+
}
|
|
12841
|
+
|
|
12842
|
+
if (sub === 'add') {
|
|
12843
|
+
const pkgs = args.slice(1).filter(a => !a.startsWith('-'));
|
|
12844
|
+
const results = [];
|
|
12845
|
+
for (const p of pkgs) results.push(await installPackage(p, ctx));
|
|
12846
|
+
const warning = results.map(r => r && r.warning).filter(Boolean)[0];
|
|
12847
|
+
return { code: 0, stdout: `saved ${results.filter(r => r && r.name).length} package(s)\n`, stderr: warning ? `bun warn ${warning}\n` : '' };
|
|
12562
12848
|
}
|
|
12563
12849
|
|
|
12564
12850
|
if (sub === 'remove' || sub === 'rm') {
|
|
@@ -12721,15 +13007,19 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12721
13007
|
const pkgs = args.slice(1).filter(a => !a.startsWith('-'));
|
|
12722
13008
|
if (pkgs.length === 0) {
|
|
12723
13009
|
const { data: pkgData } = readPackageJson(ctx.vfs, ctx.cwd);
|
|
13010
|
+
const results = [];
|
|
12724
13011
|
for (const p of Object.keys(pkgData.dependencies || {})) {
|
|
12725
|
-
installPackage(p, ctx);
|
|
13012
|
+
results.push(await installPackage(p, ctx));
|
|
12726
13013
|
}
|
|
12727
|
-
|
|
13014
|
+
const warning = results.map(r => r && r.warning).filter(Boolean)[0];
|
|
13015
|
+
return { code: 0, stdout: 'up to date\n', stderr: warning ? `npm warn ${warning}\n` : '' };
|
|
12728
13016
|
}
|
|
13017
|
+
const results = [];
|
|
12729
13018
|
for (const p of pkgs) {
|
|
12730
|
-
installPackage(p, ctx);
|
|
13019
|
+
results.push(await installPackage(p, ctx));
|
|
12731
13020
|
}
|
|
12732
|
-
|
|
13021
|
+
const warning = results.map(r => r && r.warning).filter(Boolean)[0];
|
|
13022
|
+
return { code: 0, stdout: `added ${results.filter(r => r && r.name).length} package(s) in 0.1s\n`, stderr: warning ? `npm warn ${warning}\n` : '' };
|
|
12733
13023
|
}
|
|
12734
13024
|
|
|
12735
13025
|
if (sub === 'uninstall' || sub === 'remove' || sub === 'rm') {
|
|
@@ -12954,6 +13244,16 @@ if (typeof module !== 'undefined' && module.exports) {
|
|
|
12954
13244
|
return PosixPath.resolve(this.cwd, p);
|
|
12955
13245
|
}
|
|
12956
13246
|
|
|
13247
|
+
// True when `name` resolves to a shell function or coreutil (used by the
|
|
13248
|
+
// workbench to route recognised commands straight to the shell instead of
|
|
13249
|
+
// treating flag-looking input such as `node --version` as a JS expression).
|
|
13250
|
+
hasCommand(name) {
|
|
13251
|
+
if (!name) return false;
|
|
13252
|
+
const n = String(name);
|
|
13253
|
+
if (this.functions && Object.prototype.hasOwnProperty.call(this.functions, n)) return true;
|
|
13254
|
+
return !!this.commands && Object.prototype.hasOwnProperty.call(this.commands, n);
|
|
13255
|
+
}
|
|
13256
|
+
|
|
12957
13257
|
_emitVfsMutation(type, absPath) {
|
|
12958
13258
|
if (!this.vfs) return;
|
|
12959
13259
|
const evt = { type, path: absPath, timestamp: Date.now() };
|
|
@@ -16126,6 +16426,9 @@ declare module 'bun:sqlite' {
|
|
|
16126
16426
|
this.folders = new Set(this.savedState?.folders || []);
|
|
16127
16427
|
this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
|
|
16128
16428
|
this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
|
|
16429
|
+
this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
|
|
16430
|
+
? this.savedState.explorerWidth
|
|
16431
|
+
: 196;
|
|
16129
16432
|
this.folderSwitcherOpen = false;
|
|
16130
16433
|
this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
|
|
16131
16434
|
this.renamingItem = null;
|
|
@@ -16463,7 +16766,8 @@ declare module 'bun:sqlite' {
|
|
|
16463
16766
|
activeFile: this.activeFile,
|
|
16464
16767
|
folders: Array.from(this.folders || []),
|
|
16465
16768
|
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
16466
|
-
explorerFolder: this.explorerFolder || ''
|
|
16769
|
+
explorerFolder: this.explorerFolder || '',
|
|
16770
|
+
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
|
|
16467
16771
|
};
|
|
16468
16772
|
this.savedState = state;
|
|
16469
16773
|
if (this.options && this.options.persistState === false) {
|
|
@@ -16644,6 +16948,13 @@ declare module 'bun:sqlite' {
|
|
|
16644
16948
|
if (stopBtn) {
|
|
16645
16949
|
stopBtn.style.display = this.isRunning ? 'inline-flex' : 'none';
|
|
16646
16950
|
}
|
|
16951
|
+
const ctrlCBtn = this.container.querySelector('#cl-ctrl-c-btn');
|
|
16952
|
+
if (ctrlCBtn) {
|
|
16953
|
+
ctrlCBtn.classList.toggle('is-running', Boolean(this.isRunning));
|
|
16954
|
+
ctrlCBtn.title = this.isRunning
|
|
16955
|
+
? 'Send Ctrl+C — interrupt the running command'
|
|
16956
|
+
: 'Send Ctrl+C (clears the current input line)';
|
|
16957
|
+
}
|
|
16647
16958
|
this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
|
|
16648
16959
|
btn.disabled = this.isRunning;
|
|
16649
16960
|
});
|
|
@@ -16658,8 +16969,9 @@ declare module 'bun:sqlite' {
|
|
|
16658
16969
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
16659
16970
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
16660
16971
|
const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
|
|
16972
|
+
const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
|
|
16661
16973
|
this.container.innerHTML = `
|
|
16662
|
-
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr}>
|
|
16974
|
+
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
16663
16975
|
<!-- Top Bar -->
|
|
16664
16976
|
<div class="codelab-topbar codelab-toolbar">
|
|
16665
16977
|
<div class="codelab-topbar__left">
|
|
@@ -16775,6 +17087,9 @@ declare module 'bun:sqlite' {
|
|
|
16775
17087
|
<div class="codelab-explorer__list" id="cl-explorer-list"></div>
|
|
16776
17088
|
</div>
|
|
16777
17089
|
|
|
17090
|
+
<!-- Explorer Resize Splitter -->
|
|
17091
|
+
<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>
|
|
17092
|
+
|
|
16778
17093
|
<!-- Editor Column -->
|
|
16779
17094
|
<div class="codelab-editor-col">
|
|
16780
17095
|
<div class="codelab-tabs codelab-file-tabs" id="cl-file-tabs" role="tablist" aria-label="Open Files"></div>
|
|
@@ -16828,6 +17143,7 @@ declare module 'bun:sqlite' {
|
|
|
16828
17143
|
</button>
|
|
16829
17144
|
</div>
|
|
16830
17145
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
17146
|
+
<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>
|
|
16831
17147
|
<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>
|
|
16832
17148
|
<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>
|
|
16833
17149
|
</div>
|
|
@@ -17969,10 +18285,10 @@ declare module 'bun:sqlite' {
|
|
|
17969
18285
|
this._ptyInputAfterCursor = '';
|
|
17970
18286
|
this._updatePtyActiveLine();
|
|
17971
18287
|
}
|
|
17972
|
-
} else if (
|
|
18288
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
|
|
17973
18289
|
e.preventDefault();
|
|
17974
18290
|
this._handleInterrupt();
|
|
17975
|
-
} else if (
|
|
18291
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
|
|
17976
18292
|
e.preventDefault();
|
|
17977
18293
|
if (this.inRepl) {
|
|
17978
18294
|
this.inRepl = false;
|
|
@@ -17981,7 +18297,7 @@ declare module 'bun:sqlite' {
|
|
|
17981
18297
|
const nextInput = this.container.querySelector('#cl-repl-input');
|
|
17982
18298
|
if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
|
|
17983
18299
|
}
|
|
17984
|
-
} else if (
|
|
18300
|
+
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
|
|
17985
18301
|
e.preventDefault();
|
|
17986
18302
|
this.terminalLogs = [];
|
|
17987
18303
|
this._renderDrawerBody();
|
|
@@ -19726,41 +20042,18 @@ declare module 'bun:sqlite' {
|
|
|
19726
20042
|
|
|
19727
20043
|
_renderEmptyEditorContent(emptyEl) {
|
|
19728
20044
|
if (!emptyEl) return;
|
|
19729
|
-
const fileBtns = this._orderedFileNames().map(f => {
|
|
19730
|
-
const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
19731
|
-
return `
|
|
19732
|
-
<button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
|
|
19733
|
-
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
|
|
19734
|
-
<span>${escapeHtml(f)}</span>
|
|
19735
|
-
</button>
|
|
19736
|
-
`;
|
|
19737
|
-
}).join('');
|
|
19738
|
-
|
|
19739
20045
|
emptyEl.innerHTML = `
|
|
19740
20046
|
<div class="codelab-empty-editor__inner">
|
|
19741
|
-
<div class="codelab-empty-
|
|
19742
|
-
|
|
19743
|
-
|
|
19744
|
-
<
|
|
19745
|
-
</svg>
|
|
19746
|
-
</div>
|
|
19747
|
-
<h2 class="codelab-empty-editor__title">No Open Editors</h2>
|
|
19748
|
-
<p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
|
|
19749
|
-
<div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
|
|
19750
|
-
${fileBtns}
|
|
19751
|
-
</div>
|
|
19752
|
-
<div class="codelab-empty-editor__actions">
|
|
19753
|
-
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
|
|
19754
|
-
${CL_ICONS.play}
|
|
19755
|
-
<span>Run Demo</span>
|
|
19756
|
-
<span class="codelab-btn__kbd">⇧⌘↵</span>
|
|
20047
|
+
<div class="codelab-empty-editor__watermark" aria-hidden="true">code-lab</div>
|
|
20048
|
+
<div class="codelab-empty-editor__shortcuts" role="group" aria-label="Quick actions">
|
|
20049
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette-files">
|
|
20050
|
+
<span>Go to File</span><kbd>⌘P</kbd>
|
|
19757
20051
|
</button>
|
|
19758
|
-
<button type="button" class="codelab-
|
|
19759
|
-
|
|
19760
|
-
<span>Run Tests</span>
|
|
19761
|
-
<span class="codelab-btn__kbd">⌘↵</span>
|
|
20052
|
+
<button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette">
|
|
20053
|
+
<span>Show All Commands</span><kbd>⌘⇧P</kbd>
|
|
19762
20054
|
</button>
|
|
19763
20055
|
</div>
|
|
20056
|
+
<p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
|
|
19764
20057
|
</div>
|
|
19765
20058
|
`;
|
|
19766
20059
|
}
|
|
@@ -19830,7 +20123,7 @@ declare module 'bun:sqlite' {
|
|
|
19830
20123
|
this.openCommandPalette('files');
|
|
19831
20124
|
return;
|
|
19832
20125
|
}
|
|
19833
|
-
if (
|
|
20126
|
+
if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
|
|
19834
20127
|
const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
|
|
19835
20128
|
if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
|
|
19836
20129
|
e.preventDefault();
|
|
@@ -20132,6 +20425,7 @@ declare module 'bun:sqlite' {
|
|
|
20132
20425
|
if (action === 'run-demo') this.runDemo();
|
|
20133
20426
|
else if (action === 'run-tests') this.runTests();
|
|
20134
20427
|
else if (action === 'stop-run') this.stopExecution();
|
|
20428
|
+
else if (action === 'interrupt') this._handleInterrupt();
|
|
20135
20429
|
else if (action === 'verify-step') this.verifyCurrentStep();
|
|
20136
20430
|
else if (action === 'show-diff') this.showSolutionModal();
|
|
20137
20431
|
else if (action === 'compare-diff') {
|
|
@@ -20725,6 +21019,48 @@ declare module 'bun:sqlite' {
|
|
|
20725
21019
|
hSplitter.addEventListener('pointerup', onUp);
|
|
20726
21020
|
});
|
|
20727
21021
|
}
|
|
21022
|
+
|
|
21023
|
+
const fSplitter = this.container.querySelector('#cl-splitter-files');
|
|
21024
|
+
if (fSplitter) {
|
|
21025
|
+
const applyWidth = (w) => {
|
|
21026
|
+
this.explorerWidth = Math.round(w);
|
|
21027
|
+
shell.style.setProperty('--cl-explorer-width', `${this.explorerWidth}px`);
|
|
21028
|
+
if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
|
|
21029
|
+
};
|
|
21030
|
+
|
|
21031
|
+
fSplitter.addEventListener('dblclick', () => {
|
|
21032
|
+
applyWidth(196);
|
|
21033
|
+
this._saveState();
|
|
21034
|
+
});
|
|
21035
|
+
|
|
21036
|
+
fSplitter.addEventListener('pointerdown', e => {
|
|
21037
|
+
e.preventDefault();
|
|
21038
|
+
fSplitter.classList.add('is-dragging');
|
|
21039
|
+
shell.classList.add('is-resizing');
|
|
21040
|
+
try { fSplitter.setPointerCapture(e.pointerId); } catch (_) {}
|
|
21041
|
+
|
|
21042
|
+
const onMove = ev => {
|
|
21043
|
+
const ws = this.container.querySelector('.codelab-workspace');
|
|
21044
|
+
const rect = (ws || shell).getBoundingClientRect();
|
|
21045
|
+
const minW = 140;
|
|
21046
|
+
const maxW = Math.max(minW, Math.floor(rect.width * 0.5));
|
|
21047
|
+
const nextW = Math.min(maxW, Math.max(minW, Math.round(ev.clientX - rect.left)));
|
|
21048
|
+
applyWidth(nextW);
|
|
21049
|
+
};
|
|
21050
|
+
|
|
21051
|
+
const onUp = ev => {
|
|
21052
|
+
fSplitter.classList.remove('is-dragging');
|
|
21053
|
+
shell.classList.remove('is-resizing');
|
|
21054
|
+
try { fSplitter.releasePointerCapture(ev.pointerId); } catch (_) {}
|
|
21055
|
+
fSplitter.removeEventListener('pointermove', onMove);
|
|
21056
|
+
fSplitter.removeEventListener('pointerup', onUp);
|
|
21057
|
+
this._saveState();
|
|
21058
|
+
};
|
|
21059
|
+
|
|
21060
|
+
fSplitter.addEventListener('pointermove', onMove);
|
|
21061
|
+
fSplitter.addEventListener('pointerup', onUp);
|
|
21062
|
+
});
|
|
21063
|
+
}
|
|
20728
21064
|
}
|
|
20729
21065
|
|
|
20730
21066
|
selectStep(idx, shouldJump = true) {
|
|
@@ -21004,14 +21340,14 @@ declare module 'bun:sqlite' {
|
|
|
21004
21340
|
</div>
|
|
21005
21341
|
${pkgs.length === 0 ? `
|
|
21006
21342
|
<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;">
|
|
21007
|
-
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>
|
|
21343
|
+
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.
|
|
21008
21344
|
</div>
|
|
21009
21345
|
` : `
|
|
21010
21346
|
<div style="display:flex;flex-direction:column;gap:6px;">
|
|
21011
21347
|
${pkgs.map(p => `
|
|
21012
21348
|
<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;">
|
|
21013
21349
|
<span style="color:var(--cl-fg);font-weight:600;">${escapeHtml(p.name)}</span>
|
|
21014
|
-
<span style="color:var(--cl-accent);">${escapeHtml(p.version)} ·
|
|
21350
|
+
<span style="color:var(--cl-accent);">${escapeHtml(p.version)} · jsDelivr</span>
|
|
21015
21351
|
</div>
|
|
21016
21352
|
`).join('')}
|
|
21017
21353
|
</div>
|
|
@@ -21121,6 +21457,12 @@ declare module 'bun:sqlite' {
|
|
|
21121
21457
|
}
|
|
21122
21458
|
|
|
21123
21459
|
// ── Execution Engine (Web Worker + Virtual Node Runtime) ───────────────
|
|
21460
|
+
_isAbortResult(res, signal) {
|
|
21461
|
+
if (signal && signal.aborted) return true;
|
|
21462
|
+
if (!res || typeof res !== 'object') return false;
|
|
21463
|
+
return Boolean(res.cancelled || res.aborted || res.exitCode === 130);
|
|
21464
|
+
}
|
|
21465
|
+
|
|
21124
21466
|
async _executeRuntime(execOptions) {
|
|
21125
21467
|
const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
21126
21468
|
const payload = {
|
|
@@ -21139,9 +21481,14 @@ declare module 'bun:sqlite' {
|
|
|
21139
21481
|
if (detectedList.length > 0) {
|
|
21140
21482
|
this._setRuntimeStatus('fetching', `Fetching ${detectedList.map(d => typeof d === 'string' ? d : d.name).join(', ')}...`);
|
|
21141
21483
|
}
|
|
21142
|
-
await root.CodeLabRuntime.preloadNpmPackages(payload.files, pkgName => {
|
|
21143
|
-
this._setRuntimeStatus('fetching', `Fetching ${pkgName} from
|
|
21484
|
+
const preloaded = await root.CodeLabRuntime.preloadNpmPackages(payload.files, pkgName => {
|
|
21485
|
+
this._setRuntimeStatus('fetching', `Fetching ${pkgName} from jsDelivr CDN...`);
|
|
21144
21486
|
});
|
|
21487
|
+
// Hand the fetched module sources to the runtime so the Web Worker
|
|
21488
|
+
// (which has an isolated module cache) can resolve them from node_modules.
|
|
21489
|
+
if (preloaded && typeof preloaded === 'object' && Object.keys(preloaded).length > 0) {
|
|
21490
|
+
payload.packages = Object.assign({}, preloaded, payload.packages || {});
|
|
21491
|
+
}
|
|
21145
21492
|
}
|
|
21146
21493
|
this._setRuntimeStatus('running', `Running ${payload.entry || payload.mode || 'script'}...`);
|
|
21147
21494
|
let res;
|
|
@@ -21157,7 +21504,11 @@ declare module 'bun:sqlite' {
|
|
|
21157
21504
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
21158
21505
|
return res;
|
|
21159
21506
|
} catch (err) {
|
|
21160
|
-
|
|
21507
|
+
if (payload.signal && payload.signal.aborted) {
|
|
21508
|
+
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
21509
|
+
} else {
|
|
21510
|
+
this._setRuntimeStatus('error', 'Execution error');
|
|
21511
|
+
}
|
|
21161
21512
|
throw err;
|
|
21162
21513
|
}
|
|
21163
21514
|
}
|
|
@@ -21199,18 +21550,21 @@ declare module 'bun:sqlite' {
|
|
|
21199
21550
|
}
|
|
21200
21551
|
});
|
|
21201
21552
|
this._flushTerminalStream();
|
|
21553
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21202
21554
|
|
|
21203
|
-
if (!streamedStdout && res.stdout) {
|
|
21555
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
21204
21556
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
21205
21557
|
}
|
|
21206
|
-
if (!streamedStderr && res.stderr) {
|
|
21558
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
21207
21559
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21208
21560
|
}
|
|
21209
|
-
if (res.error) {
|
|
21561
|
+
if (!aborted && res.error) {
|
|
21210
21562
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21211
21563
|
}
|
|
21212
|
-
|
|
21213
|
-
|
|
21564
|
+
if (!aborted) {
|
|
21565
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
21566
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
21567
|
+
}
|
|
21214
21568
|
|
|
21215
21569
|
if (this.onRun) {
|
|
21216
21570
|
try { this.onRun(res); } catch (_) {}
|
|
@@ -21218,7 +21572,9 @@ declare module 'bun:sqlite' {
|
|
|
21218
21572
|
this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
|
|
21219
21573
|
} catch (err) {
|
|
21220
21574
|
this._flushTerminalStream();
|
|
21221
|
-
|
|
21575
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21576
|
+
this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
|
|
21577
|
+
}
|
|
21222
21578
|
} finally {
|
|
21223
21579
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21224
21580
|
this._activeCommandAbortController = null;
|
|
@@ -21267,18 +21623,21 @@ declare module 'bun:sqlite' {
|
|
|
21267
21623
|
}
|
|
21268
21624
|
});
|
|
21269
21625
|
this._flushTerminalStream();
|
|
21626
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21270
21627
|
|
|
21271
|
-
|
|
21272
|
-
|
|
21273
|
-
|
|
21628
|
+
if (!aborted) {
|
|
21629
|
+
this.lastTestResults = res.testResults || [];
|
|
21630
|
+
this.lastFsSnapshot = res.fsSnapshot || [];
|
|
21631
|
+
this.lastHttpTrace = res.httpTrace || [];
|
|
21632
|
+
}
|
|
21274
21633
|
|
|
21275
|
-
if (!streamedStdout && res.stdout) {
|
|
21634
|
+
if (!aborted && !streamedStdout && res.stdout) {
|
|
21276
21635
|
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
21277
21636
|
}
|
|
21278
|
-
if (!streamedStderr && res.stderr) {
|
|
21637
|
+
if (!aborted && !streamedStderr && res.stderr) {
|
|
21279
21638
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21280
21639
|
}
|
|
21281
|
-
if (res.error) {
|
|
21640
|
+
if (!aborted && res.error) {
|
|
21282
21641
|
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21283
21642
|
}
|
|
21284
21643
|
|
|
@@ -21329,7 +21688,9 @@ declare module 'bun:sqlite' {
|
|
|
21329
21688
|
}
|
|
21330
21689
|
} catch (err) {
|
|
21331
21690
|
this._flushTerminalStream();
|
|
21332
|
-
|
|
21691
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21692
|
+
this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
|
|
21693
|
+
}
|
|
21333
21694
|
} finally {
|
|
21334
21695
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21335
21696
|
this._activeCommandAbortController = null;
|
|
@@ -21420,16 +21781,19 @@ declare module 'bun:sqlite' {
|
|
|
21420
21781
|
onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
|
|
21421
21782
|
});
|
|
21422
21783
|
this._flushTerminalStream();
|
|
21784
|
+
const aborted = this._isAbortResult(res, abortCtrl.signal);
|
|
21423
21785
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
21424
|
-
if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21425
|
-
if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21426
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21786
|
+
if (!aborted && !streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21787
|
+
if (!aborted && !streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21788
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21427
21789
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
21428
21790
|
}
|
|
21429
|
-
if (res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21791
|
+
if (!aborted && res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
|
|
21430
21792
|
} catch (err) {
|
|
21431
21793
|
this._flushTerminalStream();
|
|
21432
|
-
|
|
21794
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21795
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21796
|
+
}
|
|
21433
21797
|
} finally {
|
|
21434
21798
|
if (this._activeCommandAbortController === abortCtrl) {
|
|
21435
21799
|
this._activeCommandAbortController = null;
|
|
@@ -21461,8 +21825,17 @@ declare module 'bun:sqlite' {
|
|
|
21461
21825
|
return;
|
|
21462
21826
|
}
|
|
21463
21827
|
|
|
21464
|
-
const
|
|
21465
|
-
|
|
21828
|
+
const firstWord = (trimmed.split(/\s+/)[0] || '').replace(/^.*\//, '');
|
|
21829
|
+
const shellKnowsCommand = Boolean(
|
|
21830
|
+
firstWord &&
|
|
21831
|
+
this.shell &&
|
|
21832
|
+
typeof this.shell.hasCommand === 'function' &&
|
|
21833
|
+
this.shell.hasCommand(firstWord)
|
|
21834
|
+
);
|
|
21835
|
+
const looksLikeJsExpr = !shellKnowsCommand && (
|
|
21836
|
+
/^(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)
|
|
21837
|
+
|| /^[a-zA-Z_$][\w$]*\s*(\.|===|!==|==|!=|<=|>=|\+=|-=|\*=|\(|\+\+|--)/.test(trimmed)
|
|
21838
|
+
);
|
|
21466
21839
|
|
|
21467
21840
|
if (this.shell && typeof this.shell.execute === 'function' && !looksLikeJsExpr) {
|
|
21468
21841
|
const abortCtrl = new AbortController();
|
|
@@ -21488,6 +21861,7 @@ declare module 'bun:sqlite' {
|
|
|
21488
21861
|
signal: abortCtrl.signal
|
|
21489
21862
|
});
|
|
21490
21863
|
this._flushTerminalStream();
|
|
21864
|
+
const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
|
|
21491
21865
|
this.cwd = this.shell.cwd || this.cwd;
|
|
21492
21866
|
this._syncVfsSnapshot(null, true);
|
|
21493
21867
|
|
|
@@ -21507,10 +21881,10 @@ declare module 'bun:sqlite' {
|
|
|
21507
21881
|
|
|
21508
21882
|
const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
|
|
21509
21883
|
if (!isCmdNotFound) {
|
|
21510
|
-
if (shellRes && shellRes.stdout && !streamedStdout) {
|
|
21884
|
+
if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
|
|
21511
21885
|
this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
|
|
21512
21886
|
}
|
|
21513
|
-
if (shellRes && shellRes.stderr && !streamedStderr) {
|
|
21887
|
+
if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
|
|
21514
21888
|
this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
|
|
21515
21889
|
}
|
|
21516
21890
|
this._renderDrawerBody();
|
|
@@ -21523,7 +21897,9 @@ declare module 'bun:sqlite' {
|
|
|
21523
21897
|
}
|
|
21524
21898
|
} catch (err) {
|
|
21525
21899
|
this._flushTerminalStream();
|
|
21526
|
-
|
|
21900
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21901
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21902
|
+
}
|
|
21527
21903
|
this._renderDrawerBody();
|
|
21528
21904
|
return;
|
|
21529
21905
|
} finally {
|
|
@@ -21559,17 +21935,18 @@ declare module 'bun:sqlite' {
|
|
|
21559
21935
|
}
|
|
21560
21936
|
});
|
|
21561
21937
|
this._flushTerminalStream();
|
|
21938
|
+
const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
|
|
21562
21939
|
const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
|
|
21563
|
-
if (!streamedFallbackStdout && cleanStdout) {
|
|
21940
|
+
if (!aborted && !streamedFallbackStdout && cleanStdout) {
|
|
21564
21941
|
this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
|
|
21565
21942
|
}
|
|
21566
|
-
if (!streamedFallbackStderr && res.stderr) {
|
|
21943
|
+
if (!aborted && !streamedFallbackStderr && res.stderr) {
|
|
21567
21944
|
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
21568
21945
|
}
|
|
21569
|
-
if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21946
|
+
if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
|
|
21570
21947
|
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
21571
21948
|
}
|
|
21572
|
-
if (res.error) {
|
|
21949
|
+
if (!aborted && res.error) {
|
|
21573
21950
|
const errStr = formatErrorText(res.error);
|
|
21574
21951
|
if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
|
|
21575
21952
|
this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
|
|
@@ -21579,7 +21956,9 @@ declare module 'bun:sqlite' {
|
|
|
21579
21956
|
}
|
|
21580
21957
|
} catch (err) {
|
|
21581
21958
|
this._flushTerminalStream();
|
|
21582
|
-
|
|
21959
|
+
if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
21960
|
+
this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
|
|
21961
|
+
}
|
|
21583
21962
|
} finally {
|
|
21584
21963
|
if (this._activeCommandAbortController === fallbackAbortCtrl) {
|
|
21585
21964
|
this._activeCommandAbortController = null;
|
|
@@ -21831,8 +22210,13 @@ declare module 'bun:sqlite' {
|
|
|
21831
22210
|
const intoRoot = options.intoRoot !== false;
|
|
21832
22211
|
const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
|
|
21833
22212
|
const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
|
|
22213
|
+
this.drawerTab = 'terminal';
|
|
21834
22214
|
this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
|
|
22215
|
+
this.isRunning = true;
|
|
22216
|
+
const abortCtrl = new AbortController();
|
|
22217
|
+
this._activeCommandAbortController = abortCtrl;
|
|
21835
22218
|
this._renderDrawerBody();
|
|
22219
|
+
this._updateRunStateUI();
|
|
21836
22220
|
|
|
21837
22221
|
try {
|
|
21838
22222
|
if (intoRoot && this.shell && this.shell.vfs) {
|
|
@@ -21855,6 +22239,7 @@ declare module 'bun:sqlite' {
|
|
|
21855
22239
|
maxFiles: options.maxFiles || 250,
|
|
21856
22240
|
maxFileSize: options.maxFileSize || 512 * 1024,
|
|
21857
22241
|
fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
|
|
22242
|
+
signal: abortCtrl.signal,
|
|
21858
22243
|
onProgress: options.onProgress
|
|
21859
22244
|
});
|
|
21860
22245
|
|
|
@@ -21926,10 +22311,18 @@ declare module 'bun:sqlite' {
|
|
|
21926
22311
|
this._emitEvent('repo:cloned', eventDetail);
|
|
21927
22312
|
return result;
|
|
21928
22313
|
} catch (err) {
|
|
21929
|
-
|
|
21930
|
-
|
|
22314
|
+
if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
|
|
22315
|
+
const msg = err && err.message ? err.message : String(err);
|
|
22316
|
+
this.terminalLogs.push({ type: 'stderr', text: msg });
|
|
22317
|
+
}
|
|
21931
22318
|
this._renderDrawerBody();
|
|
21932
22319
|
throw err;
|
|
22320
|
+
} finally {
|
|
22321
|
+
if (this._activeCommandAbortController === abortCtrl) {
|
|
22322
|
+
this._activeCommandAbortController = null;
|
|
22323
|
+
}
|
|
22324
|
+
this.isRunning = false;
|
|
22325
|
+
this._updateRunStateUI();
|
|
21933
22326
|
}
|
|
21934
22327
|
}
|
|
21935
22328
|
|