@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/dist/shell.js CHANGED
@@ -2028,6 +2028,16 @@
2028
2028
  const requestedBranch = options.branch || parsed.branch || null;
2029
2029
  const { owner, repo } = parsed;
2030
2030
 
2031
+ const signal = options.signal || null;
2032
+ const throwIfAborted = () => {
2033
+ if (signal && signal.aborted) {
2034
+ const abortErr = new Error('fatal: clone cancelled (SIGINT)');
2035
+ abortErr.name = 'AbortError';
2036
+ throw abortErr;
2037
+ }
2038
+ };
2039
+ throwIfAborted();
2040
+
2031
2041
  let resolvedBranch = requestedBranch;
2032
2042
  let rawTreeEntries = null;
2033
2043
  let repoNotFound = false;
@@ -2040,7 +2050,8 @@
2040
2050
  try {
2041
2051
  if (!resolvedBranch) {
2042
2052
  const metaRes = await fetchFn(`https://api.github.com/repos/${owner}/${repo}`, {
2043
- headers: { Accept: 'application/vnd.github.v3+json' }
2053
+ headers: { Accept: 'application/vnd.github.v3+json' },
2054
+ signal
2044
2055
  });
2045
2056
  if (metaRes.status === 404) {
2046
2057
  repoNotFound = true;
@@ -2058,9 +2069,10 @@
2058
2069
  : Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
2059
2070
 
2060
2071
  for (const cand of branchCandidates) {
2072
+ throwIfAborted();
2061
2073
  const treeRes = await fetchFn(
2062
2074
  `https://api.github.com/repos/${owner}/${repo}/git/trees/${encodeURIComponent(cand)}?recursive=1`,
2063
- { headers: { Accept: 'application/vnd.github.v3+json' } }
2075
+ { headers: { Accept: 'application/vnd.github.v3+json' }, signal }
2064
2076
  );
2065
2077
  if (treeRes.ok) {
2066
2078
  const treeJson = await treeRes.json();
@@ -2086,8 +2098,10 @@
2086
2098
  : Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
2087
2099
 
2088
2100
  for (const cand of branchCandidates) {
2101
+ throwIfAborted();
2089
2102
  const flatRes = await fetchFn(
2090
- `https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`
2103
+ `https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`,
2104
+ { signal }
2091
2105
  );
2092
2106
  if (flatRes && flatRes.ok) {
2093
2107
  const flatJson = await flatRes.json();
@@ -2156,28 +2170,34 @@
2156
2170
  const BATCH_SIZE = 12;
2157
2171
 
2158
2172
  for (let i = 0; i < selectedFiles.length; i += BATCH_SIZE) {
2173
+ throwIfAborted();
2159
2174
  const batch = selectedFiles.slice(i, i + BATCH_SIZE);
2160
2175
  await Promise.all(
2161
2176
  batch.map(async (entry) => {
2177
+ throwIfAborted();
2162
2178
  const encodedPath = entry.repoPath.split('/').map(encodeURIComponent).join('/');
2163
2179
  const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
2164
2180
  const cdnUrl = `https://cdn.jsdelivr.net/gh/${owner}/${repo}@${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
2165
2181
 
2166
2182
  let text = null;
2167
2183
  try {
2168
- const r1 = await fetchFn(rawUrl);
2184
+ const r1 = await fetchFn(rawUrl, { signal });
2169
2185
  if (r1 && r1.ok) {
2170
2186
  text = await r1.text();
2171
2187
  }
2172
- } catch (_) {}
2188
+ } catch (_) {
2189
+ if (signal && signal.aborted) throw _;
2190
+ }
2173
2191
 
2174
2192
  if (text === null) {
2175
2193
  try {
2176
- const r2 = await fetchFn(cdnUrl);
2194
+ const r2 = await fetchFn(cdnUrl, { signal });
2177
2195
  if (r2 && r2.ok) {
2178
2196
  text = await r2.text();
2179
2197
  }
2180
- } catch (_) {}
2198
+ } catch (_) {
2199
+ if (signal && signal.aborted) throw _;
2200
+ }
2181
2201
  }
2182
2202
 
2183
2203
  if (text !== null && text.length <= maxFileSize) {
@@ -2201,6 +2221,8 @@
2201
2221
  );
2202
2222
  }
2203
2223
 
2224
+ throwIfAborted();
2225
+
2204
2226
  if (onProgress) {
2205
2227
  onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
2206
2228
  }
@@ -2221,7 +2243,7 @@
2221
2243
  try {
2222
2244
  const commitsRes = await fetchFn(
2223
2245
  `https://api.github.com/repos/${owner}/${repo}/commits?sha=${encodeURIComponent(resolvedBranch)}&per_page=10`,
2224
- { headers: { Accept: 'application/vnd.github.v3+json' } }
2246
+ { headers: { Accept: 'application/vnd.github.v3+json' }, signal }
2225
2247
  );
2226
2248
  if (commitsRes && commitsRes.ok) {
2227
2249
  const commitsJson = await commitsRes.json();
@@ -2333,38 +2355,221 @@
2333
2355
  } catch (_) {}
2334
2356
  }
2335
2357
 
2336
- function installPackage(pkgSpec, ctx) {
2337
- const parts = pkgSpec.split('@').filter(Boolean);
2338
- const pkgName = pkgSpec.startsWith('@') ? '@' + parts[0] : parts[0];
2339
- const pkgVersion = parts[1] || '^1.0.0';
2358
+ // ---------------------------------------------------------------------------
2359
+ // Real npm package installation via the jsDelivr CDN
2360
+ // ---------------------------------------------------------------------------
2361
+ const CDN_NPM_BASE = 'https://cdn.jsdelivr.net/npm';
2362
+
2363
+ // Minimal offline registry, used only when the CDN is unreachable so common
2364
+ // demos still resolve without network access.
2365
+ const OFFLINE_PACKAGE_FALLBACKS = {
2366
+ 'is-even': 'module.exports = function isEven(n) { return (Number(n) % 2) === 0; };\n',
2367
+ 'tiny-invariant': 'module.exports = function invariant(condition, message) { if (!condition) throw new Error(message || "Invariant failed"); };\n',
2368
+ 'lodash': 'module.exports = { isArray: Array.isArray, isObject: function (v) { return v !== null && typeof v === "object"; } };\n',
2369
+ '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'
2370
+ };
2371
+
2372
+ function packageCtxFetch(ctx) {
2373
+ if (ctx && ctx.shell && ctx.shell.options && typeof ctx.shell.options.fetchImpl === 'function') {
2374
+ return ctx.shell.options.fetchImpl;
2375
+ }
2376
+ if (typeof fetch === 'function') return fetch.bind(globalThis);
2377
+ return null;
2378
+ }
2379
+
2380
+ function parsePackageSpec(spec) {
2381
+ const raw = String(spec || '').trim();
2382
+ if (!raw) return { name: '', range: null };
2383
+ if (raw.startsWith('@')) {
2384
+ const at = raw.indexOf('@', 1);
2385
+ if (at === -1) return { name: raw, range: null };
2386
+ return { name: raw.slice(0, at), range: raw.slice(at + 1) || null };
2387
+ }
2388
+ const at = raw.indexOf('@');
2389
+ if (at <= 0) return { name: raw, range: null };
2390
+ return { name: raw.slice(0, at), range: raw.slice(at + 1) || null };
2391
+ }
2392
+
2393
+ function resolveEntryRelPath(pkgJson) {
2394
+ let entry = pkgJson.main || pkgJson.module ||
2395
+ (typeof pkgJson.browser === 'string' ? pkgJson.browser : '') || 'index.js';
2396
+ entry = String(entry).replace(/^[./]+/, '');
2397
+ return entry || 'index.js';
2398
+ }
2399
+
2400
+ function stripRelPath(rel) {
2401
+ return String(rel || '').replace(/^[./]+/, '');
2402
+ }
2403
+
2404
+ function extractRelativeSpecifiers(code) {
2405
+ const out = new Set();
2406
+ const re = /(?:\brequire\s*\(\s*|\bimport\s+[\s\S]{0,120}?\bfrom\s*|\bimport\s*\(\s*)['"](\.{1,2}\/[^'"]+)['"]/g;
2407
+ let m;
2408
+ while ((m = re.exec(code)) !== null) out.add(m[1]);
2409
+ return Array.from(out);
2410
+ }
2411
+
2412
+ function normalizeRelPath(baseDir, rel) {
2413
+ const parts = String(baseDir || '').split('/').filter(Boolean);
2414
+ for (const seg of String(rel).split('/')) {
2415
+ if (!seg || seg === '.') continue;
2416
+ if (seg === '..') parts.pop();
2417
+ else parts.push(seg);
2418
+ }
2419
+ return parts.join('/');
2420
+ }
2421
+
2422
+ async function fetchTextFromCdn(fetchImpl, url) {
2423
+ try {
2424
+ const res = await fetchImpl(url);
2425
+ if (!res) return null;
2426
+ const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2427
+ if (!ok) return null;
2428
+ if (typeof res.text === 'function') return await res.text();
2429
+ return String(res.body != null ? res.body : '');
2430
+ } catch (_) {
2431
+ return null;
2432
+ }
2433
+ }
2434
+
2435
+ async function resolvePackageMetadata(fetchImpl, name, range) {
2436
+ const urls = range
2437
+ ? [`${CDN_NPM_BASE}/${name}@${range}/package.json`, `${CDN_NPM_BASE}/${name}/package.json`]
2438
+ : [`${CDN_NPM_BASE}/${name}/package.json`];
2439
+ for (const url of urls) {
2440
+ const text = await fetchTextFromCdn(fetchImpl, url);
2441
+ if (!text) continue;
2442
+ try {
2443
+ const parsed = JSON.parse(text);
2444
+ if (parsed && parsed.version) return parsed;
2445
+ } catch (_) {}
2446
+ }
2447
+ return null;
2448
+ }
2449
+
2450
+ // Download a package's entry module, its relative submodules and record its
2451
+ // declared dependencies so the caller can resolve them transitively.
2452
+ async function downloadPackageFiles(fetchImpl, name, range, seen) {
2453
+ const meta = await resolvePackageMetadata(fetchImpl, name, range);
2454
+ if (!meta) {
2455
+ const fallback = OFFLINE_PACKAGE_FALLBACKS[name];
2456
+ if (fallback) {
2457
+ const v = range ? range.replace(/^[\^~>=<\s]+/, '') || '1.0.0' : '1.0.0';
2458
+ return { ok: true, offline: true, version: v, entry: 'index.js', files: [{ rel: 'index.js', content: fallback }], deps: [] };
2459
+ }
2460
+ return { ok: false, reason: `${name}: package metadata not found on the registry (offline?)` };
2461
+ }
2462
+
2463
+ const version = meta.version;
2464
+ const key = `${name}@${version}`;
2465
+ if (seen.has(key)) {
2466
+ return { ok: true, deduped: true, version, entry: resolveEntryRelPath(meta), files: [], deps: [] };
2467
+ }
2468
+ seen.add(key);
2469
+
2470
+ const entry = resolveEntryRelPath(meta);
2471
+ const files = [];
2472
+ const visited = new Set();
2473
+ const queue = [entry];
2474
+ while (queue.length > 0) {
2475
+ const rel = stripRelPath(queue.shift());
2476
+ if (!rel || visited.has(rel)) continue;
2477
+ visited.add(rel);
2478
+ const text = await fetchTextFromCdn(fetchImpl, `${CDN_NPM_BASE}/${name}@${version}/${rel}`);
2479
+ if (text === null) continue;
2480
+ files.push({ rel, content: text });
2481
+ const baseDir = rel.includes('/') ? rel.slice(0, rel.lastIndexOf('/')) : '';
2482
+ for (const spec of extractRelativeSpecifiers(text)) {
2483
+ const target = normalizeRelPath(baseDir, spec);
2484
+ for (const cand of [target, `${target}.js`, `${target}.json`, `${target}/index.js`]) {
2485
+ const c = stripRelPath(cand);
2486
+ if (c && !visited.has(c)) { queue.push(cand); break; }
2487
+ }
2488
+ }
2489
+ }
2490
+ // The declared entry may be missing on the CDN; fall back to index.js.
2491
+ if (!files.some(f => f.rel === entry)) {
2492
+ const idxText = await fetchTextFromCdn(fetchImpl, `${CDN_NPM_BASE}/${name}@${version}/index.js`);
2493
+ if (idxText !== null) files.push({ rel: 'index.js', content: idxText });
2494
+ }
2495
+
2496
+ return { ok: true, version, entry, files, deps: Object.keys(meta.dependencies || {}) };
2497
+ }
2498
+
2499
+ function installTargetDirs(ctx, name) {
2500
+ const dirs = ['/workspace/node_modules/' + name];
2501
+ const cwdTarget = PosixPath.join(ctx.cwd || '/workspace', 'node_modules', name);
2502
+ if (!dirs.includes(cwdTarget)) dirs.push(cwdTarget);
2503
+ return dirs;
2504
+ }
2505
+
2506
+ function writeInstalledPackageFiles(ctx, dirs, name, info) {
2507
+ for (const dir of dirs) {
2508
+ ensureDirSync(ctx.vfs, dir, ctx.emitMutation);
2509
+ for (const f of info.files) {
2510
+ const full = PosixPath.join(dir, f.rel);
2511
+ ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
2512
+ ctx.vfs.writeFileSync(full, f.content);
2513
+ if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
2514
+ }
2515
+ const modPkgPath = PosixPath.join(dir, 'package.json');
2516
+ const modPkg = { name, version: info.version || '1.0.0', main: './' + (info.entry || 'index.js') };
2517
+ ctx.vfs.writeFileSync(modPkgPath, JSON.stringify(modPkg, null, 2) + '\n');
2518
+ if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', modPkgPath);
2519
+ }
2520
+ }
2521
+
2522
+ async function installPackage(pkgSpec, ctx) {
2523
+ const { name: pkgName, range } = parsePackageSpec(pkgSpec);
2524
+ if (!pkgName) return { name: null, ok: false, installed: [], warning: null };
2340
2525
 
2341
2526
  const { path: pkgPath, data: pkgData } = readPackageJson(ctx.vfs, ctx.cwd);
2342
2527
  if (!pkgData.dependencies) pkgData.dependencies = {};
2343
- pkgData.dependencies[pkgName] = pkgVersion;
2344
- writePackageJson(ctx.vfs, pkgPath, pkgData, ctx.emitMutation);
2345
2528
 
2346
- const targetDirs = ['/workspace/node_modules/' + pkgName];
2347
- const cwdTarget = PosixPath.join(ctx.cwd || '/workspace', 'node_modules', pkgName);
2348
- if (!targetDirs.includes(cwdTarget)) targetDirs.push(cwdTarget);
2529
+ const fetchImpl = packageCtxFetch(ctx);
2530
+ const seen = (ctx.shell && ctx.shell._cdnSeen)
2531
+ ? ctx.shell._cdnSeen
2532
+ : (ctx.shell ? (ctx.shell._cdnSeen = new Set()) : new Set());
2533
+
2534
+ const queue = [{ name: pkgName, range, direct: true }];
2535
+ const requested = new Set([pkgName]);
2536
+ const installed = [];
2537
+ let warning = null;
2538
+ let directVersion = null;
2539
+
2540
+ while (queue.length > 0) {
2541
+ const item = queue.shift();
2542
+ const info = fetchImpl
2543
+ ? await downloadPackageFiles(fetchImpl, item.name, item.range, seen)
2544
+ : { ok: false, reason: `${item.name}: no fetch implementation available` };
2545
+
2546
+ if (!info.ok) {
2547
+ // Final fallback: an empty stub so offline demos still resolve the module.
2548
+ writeInstalledPackageFiles(ctx, installTargetDirs(ctx, item.name), item.name, {
2549
+ version: '0.0.0', entry: 'index.js', files: [{ rel: 'index.js', content: 'module.exports = {};\n' }]
2550
+ });
2551
+ if (!warning) warning = info.reason;
2552
+ installed.push({ name: item.name, version: '0.0.0' });
2553
+ continue;
2554
+ }
2349
2555
 
2350
- for (const modDir of targetDirs) {
2351
- ensureDirSync(ctx.vfs, modDir, ctx.emitMutation);
2352
- const modPkgPath = PosixPath.join(modDir, 'package.json');
2353
- const modIndexPath = PosixPath.join(modDir, 'index.js');
2354
- ctx.vfs.writeFileSync(modPkgPath, JSON.stringify({ name: pkgName, version: pkgVersion.replace(/^[\^~]/, ''), main: './index.js' }, null, 2) + '\n');
2355
- if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', modPkgPath);
2556
+ writeInstalledPackageFiles(ctx, installTargetDirs(ctx, item.name), item.name, info);
2557
+ installed.push({ name: item.name, version: info.version || '1.0.0' });
2558
+ if (item.direct) directVersion = info.version || null;
2356
2559
 
2357
- let code = 'module.exports = {};\n';
2358
- if (pkgName === 'is-even') {
2359
- code = 'module.exports = function isEven(n) { return (Number(n) % 2) === 0; };\n';
2360
- } else if (pkgName === 'tiny-invariant') {
2361
- code = 'module.exports = function invariant(condition, message) { if (!condition) throw new Error(message || "Invariant failed"); };\n';
2362
- } else if (pkgName === 'lodash') {
2363
- code = 'module.exports = { isArray: Array.isArray, isObject: function(v) { return v !== null && typeof v === "object"; } };\n';
2560
+ for (const dep of (info.deps || [])) {
2561
+ const parsed = parsePackageSpec(dep);
2562
+ if (parsed.name && !requested.has(parsed.name)) {
2563
+ requested.add(parsed.name);
2564
+ queue.push({ name: parsed.name, range: null, direct: false });
2565
+ }
2364
2566
  }
2365
- ctx.vfs.writeFileSync(modIndexPath, code);
2366
- if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', modIndexPath);
2367
2567
  }
2568
+
2569
+ pkgData.dependencies[pkgName] = range || (directVersion ? `^${directVersion}` : (pkgData.dependencies[pkgName] || 'latest'));
2570
+ writePackageJson(ctx.vfs, pkgPath, pkgData, ctx.emitMutation);
2571
+
2572
+ return { name: pkgName, ok: true, version: directVersion, installed, warning };
2368
2573
  }
2369
2574
 
2370
2575
  function uninstallPackage(pkgName, ctx) {
@@ -4468,6 +4673,7 @@
4468
4673
  targetDir,
4469
4674
  branch: branchOpt,
4470
4675
  fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
4676
+ signal: ctx.signal,
4471
4677
  onFile: (absPath) => ctx.emitMutation('create', absPath),
4472
4678
  onProgress: (ev) => {
4473
4679
  if (!ev) return;
@@ -4508,6 +4714,9 @@
4508
4714
  `Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`;
4509
4715
  return { code: 0, stdout, stderr: '' };
4510
4716
  } catch (err) {
4717
+ if (ctx.signal && ctx.signal.aborted) {
4718
+ return { code: 130, stdout: '', stderr: '', aborted: true };
4719
+ }
4511
4720
  const msg = err && err.message ? err.message : String(err);
4512
4721
  if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
4513
4722
  return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
@@ -4835,6 +5044,7 @@
4835
5044
  targetDir: repoRoot,
4836
5045
  branch: gitState.branch,
4837
5046
  fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
5047
+ signal: ctx.signal,
4838
5048
  onFile: (absPath) => ctx.emitMutation('change', absPath)
4839
5049
  });
4840
5050
  gitState.headSnapshot = Object.assign({}, result.headSnapshot);
@@ -4844,6 +5054,9 @@
4844
5054
  stderr: ''
4845
5055
  };
4846
5056
  } catch (err) {
5057
+ if (ctx.signal && ctx.signal.aborted) {
5058
+ return { code: 130, stdout: '', stderr: '', aborted: true };
5059
+ }
4847
5060
  const msg = err && err.message ? err.message : String(err);
4848
5061
  return { code: 1, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
4849
5062
  }
@@ -5033,6 +5246,18 @@
5033
5246
 
5034
5247
  const sub = args[0];
5035
5248
 
5249
+ if (sub === '--version' || sub === '-v' || sub === '--revision') {
5250
+ return { code: 0, stdout: '1.1.20\n', stderr: '' };
5251
+ }
5252
+
5253
+ if (sub === '--help' || sub === '-h') {
5254
+ return {
5255
+ code: 0,
5256
+ 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',
5257
+ stderr: ''
5258
+ };
5259
+ }
5260
+
5036
5261
  if (sub === 'init') {
5037
5262
  const pkgPath = PosixPath.join(ctx.cwd, 'package.json');
5038
5263
  const dirName = PosixPath.basename(ctx.cwd) || 'app';
@@ -5082,12 +5307,28 @@
5082
5307
  return { code: 0, stdout: 'Done! A package.json file was created in ' + ctx.cwd + '\n', stderr: '' };
5083
5308
  }
5084
5309
 
5085
- if (sub === 'add') {
5310
+ if (sub === 'install' || sub === 'i' || sub === 'ci') {
5086
5311
  const pkgs = args.slice(1).filter(a => !a.startsWith('-'));
5087
- for (const p of pkgs) {
5088
- installPackage(p, ctx);
5312
+ if (pkgs.length === 0) {
5313
+ const { data: pkgData } = readPackageJson(ctx.vfs, ctx.cwd);
5314
+ const deps = Object.keys(pkgData.dependencies || {});
5315
+ const results = [];
5316
+ for (const p of deps) results.push(await installPackage(p, ctx));
5317
+ const warning = results.map(r => r && r.warning).filter(Boolean)[0];
5318
+ return { code: 0, stdout: deps.length === 0 ? 'up to date\n' : `installed ${deps.length} package(s)\n`, stderr: warning ? `bun warn ${warning}\n` : '' };
5089
5319
  }
5090
- return { code: 0, stdout: `saved ${pkgs.length} package(s)\n`, stderr: '' };
5320
+ const results = [];
5321
+ for (const p of pkgs) results.push(await installPackage(p, ctx));
5322
+ const warning = results.map(r => r && r.warning).filter(Boolean)[0];
5323
+ return { code: 0, stdout: `saved ${results.filter(r => r && r.name).length} package(s)\n`, stderr: warning ? `bun warn ${warning}\n` : '' };
5324
+ }
5325
+
5326
+ if (sub === 'add') {
5327
+ const pkgs = args.slice(1).filter(a => !a.startsWith('-'));
5328
+ const results = [];
5329
+ for (const p of pkgs) results.push(await installPackage(p, ctx));
5330
+ const warning = results.map(r => r && r.warning).filter(Boolean)[0];
5331
+ return { code: 0, stdout: `saved ${results.filter(r => r && r.name).length} package(s)\n`, stderr: warning ? `bun warn ${warning}\n` : '' };
5091
5332
  }
5092
5333
 
5093
5334
  if (sub === 'remove' || sub === 'rm') {
@@ -5250,15 +5491,19 @@
5250
5491
  const pkgs = args.slice(1).filter(a => !a.startsWith('-'));
5251
5492
  if (pkgs.length === 0) {
5252
5493
  const { data: pkgData } = readPackageJson(ctx.vfs, ctx.cwd);
5494
+ const results = [];
5253
5495
  for (const p of Object.keys(pkgData.dependencies || {})) {
5254
- installPackage(p, ctx);
5496
+ results.push(await installPackage(p, ctx));
5255
5497
  }
5256
- return { code: 0, stdout: 'up to date\n', stderr: '' };
5498
+ const warning = results.map(r => r && r.warning).filter(Boolean)[0];
5499
+ return { code: 0, stdout: 'up to date\n', stderr: warning ? `npm warn ${warning}\n` : '' };
5257
5500
  }
5501
+ const results = [];
5258
5502
  for (const p of pkgs) {
5259
- installPackage(p, ctx);
5503
+ results.push(await installPackage(p, ctx));
5260
5504
  }
5261
- return { code: 0, stdout: `added ${pkgs.length} package(s) in 0.1s\n`, stderr: '' };
5505
+ const warning = results.map(r => r && r.warning).filter(Boolean)[0];
5506
+ return { code: 0, stdout: `added ${results.filter(r => r && r.name).length} package(s) in 0.1s\n`, stderr: warning ? `npm warn ${warning}\n` : '' };
5262
5507
  }
5263
5508
 
5264
5509
  if (sub === 'uninstall' || sub === 'remove' || sub === 'rm') {
@@ -5483,6 +5728,16 @@
5483
5728
  return PosixPath.resolve(this.cwd, p);
5484
5729
  }
5485
5730
 
5731
+ // True when `name` resolves to a shell function or coreutil (used by the
5732
+ // workbench to route recognised commands straight to the shell instead of
5733
+ // treating flag-looking input such as `node --version` as a JS expression).
5734
+ hasCommand(name) {
5735
+ if (!name) return false;
5736
+ const n = String(name);
5737
+ if (this.functions && Object.prototype.hasOwnProperty.call(this.functions, n)) return true;
5738
+ return !!this.commands && Object.prototype.hasOwnProperty.call(this.commands, n);
5739
+ }
5740
+
5486
5741
  _emitVfsMutation(type, absPath) {
5487
5742
  if (!this.vfs) return;
5488
5743
  const evt = { type, path: absPath, timestamp: Date.now() };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovatorved/code-lab",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Standalone browser-native IDE Workbench, POSIX Shell & Coreutils, PTY Terminal, and Web Worker Node.js/Bun Virtual Runtime.",
5
5
  "main": "./dist/code-lab.js",
6
6
  "module": "./dist/code-lab.esm.js",
package/src/code-lab.css CHANGED
@@ -465,6 +465,24 @@ code-lab,
465
465
  color: #ffffff;
466
466
  }
467
467
 
468
+ .codelab-btn--ctrl-c {
469
+ color: var(--cl-fg-muted);
470
+ border-color: transparent;
471
+ font-weight: 600;
472
+ letter-spacing: 0.02em;
473
+ }
474
+
475
+ .codelab-btn--ctrl-c:hover {
476
+ color: var(--cl-fg);
477
+ border-color: var(--cl-border);
478
+ }
479
+
480
+ .codelab-btn--ctrl-c.is-running {
481
+ color: var(--cl-red);
482
+ border-color: var(--cl-red);
483
+ background: var(--cl-red-muted);
484
+ }
485
+
468
486
  .codelab-btn--test {
469
487
  background: var(--cl-accent);
470
488
  border-color: var(--cl-accent);
@@ -1018,14 +1036,33 @@ code-lab,
1018
1036
 
1019
1037
  .codelab-workspace {
1020
1038
  display: grid;
1021
- grid-template-columns: 196px 1fr;
1039
+ grid-template-columns: var(--cl-explorer-width, 196px) 4px 1fr;
1022
1040
  flex: 1;
1023
1041
  min-height: 160px;
1024
1042
  overflow: hidden;
1025
1043
  }
1026
1044
 
1027
1045
  .codelab.files-collapsed .codelab-workspace {
1028
- grid-template-columns: 0px 1fr;
1046
+ grid-template-columns: 0px 0px 1fr;
1047
+ }
1048
+
1049
+ .codelab.files-collapsed .codelab-splitter-files {
1050
+ display: none;
1051
+ }
1052
+
1053
+ /* Explorer Resize Splitter */
1054
+ .codelab-splitter-files {
1055
+ width: 4px;
1056
+ background: transparent;
1057
+ cursor: col-resize;
1058
+ position: relative;
1059
+ z-index: 6;
1060
+ transition: background 120ms ease;
1061
+ }
1062
+
1063
+ .codelab-splitter-files:hover,
1064
+ .codelab-splitter-files.is-dragging {
1065
+ background: var(--cl-border-strong);
1029
1066
  }
1030
1067
 
1031
1068
  /* File Explorer Sidebar */
@@ -1739,46 +1776,55 @@ code-lab,
1739
1776
  margin: 0 0 20px;
1740
1777
  }
1741
1778
 
1742
- .codelab-empty-editor__files {
1779
+ .codelab-empty-editor__watermark {
1780
+ font-family: var(--cl-font-sans);
1781
+ font-size: 40px;
1782
+ font-weight: 700;
1783
+ letter-spacing: -0.03em;
1784
+ color: var(--cl-fg-faint);
1785
+ opacity: 0.45;
1786
+ margin-bottom: 22px;
1787
+ user-select: none;
1788
+ }
1789
+
1790
+ .codelab-empty-editor__shortcuts {
1743
1791
  display: flex;
1744
- flex-wrap: wrap;
1745
- gap: 8px;
1746
- justify-content: center;
1747
- margin-bottom: 24px;
1748
- width: 100%;
1792
+ flex-direction: column;
1793
+ gap: 6px;
1794
+ margin-bottom: 22px;
1795
+ min-width: 260px;
1749
1796
  }
1750
1797
 
1751
- .codelab-empty-file-btn {
1752
- display: inline-flex;
1798
+ .codelab-empty-shortcut {
1799
+ display: flex;
1753
1800
  align-items: center;
1754
- gap: 6px;
1755
- padding: 6px 10px;
1801
+ justify-content: space-between;
1802
+ gap: 16px;
1803
+ padding: 7px 12px;
1756
1804
  border-radius: var(--cl-radius-sm);
1757
- background: var(--cl-bg-elevated);
1758
- border: 1px solid var(--cl-border);
1759
- color: var(--cl-fg);
1760
- font-family: var(--cl-font-mono);
1761
- font-size: 12px;
1805
+ background: transparent;
1806
+ border: 1px solid transparent;
1807
+ color: var(--cl-fg-muted);
1808
+ font-family: var(--cl-font-sans);
1809
+ font-size: 12.5px;
1762
1810
  cursor: pointer;
1763
1811
  transition: all 120ms ease;
1764
- user-select: none;
1765
1812
  }
1766
1813
 
1767
- .codelab-empty-file-btn:hover {
1814
+ .codelab-empty-shortcut:hover {
1768
1815
  background: var(--cl-bg-hover);
1769
- border-color: var(--cl-border-strong);
1816
+ border-color: var(--cl-border);
1770
1817
  color: var(--cl-fg);
1771
1818
  }
1772
1819
 
1773
- .codelab-empty-file-btn:active {
1774
- background: var(--cl-bg-active);
1775
- }
1776
-
1777
- .codelab-empty-editor__actions {
1778
- display: flex;
1779
- align-items: center;
1780
- gap: 10px;
1781
- justify-content: center;
1820
+ .codelab-empty-shortcut kbd {
1821
+ font-family: var(--cl-font-mono);
1822
+ font-size: 11px;
1823
+ color: var(--cl-fg-muted);
1824
+ background: var(--cl-bg-panel);
1825
+ border: 1px solid var(--cl-border);
1826
+ border-radius: 4px;
1827
+ padding: 1px 6px;
1782
1828
  }
1783
1829
 
1784
1830
  /* ── Bottom Drawer: Tests, Terminal REPL, Virtual Disk & Network ─────────── */
@@ -2933,7 +2979,7 @@ code-lab,
2933
2979
  border-bottom: 1px solid var(--cl-border);
2934
2980
  }
2935
2981
  .codelab-workspace {
2936
- grid-template-columns: 155px 1fr;
2982
+ grid-template-columns: 155px 4px 1fr;
2937
2983
  }
2938
2984
  .codelab-inspector-grid {
2939
2985
  grid-template-columns: 1fr;
@@ -2947,7 +2993,8 @@ code-lab,
2947
2993
  .codelab-workspace {
2948
2994
  grid-template-columns: 1fr;
2949
2995
  }
2950
- .codelab-explorer {
2996
+ .codelab-explorer,
2997
+ .codelab-splitter-files {
2951
2998
  display: none;
2952
2999
  }
2953
3000
  .codelab-topbar__center {