@innovatorved/code-lab 0.1.5 → 0.1.6

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/src/shell.js CHANGED
@@ -2373,6 +2373,15 @@
2373
2373
 
2374
2374
  function pickConditionalEntry(value) {
2375
2375
  if (typeof value === 'string') return value;
2376
+ // `exports` subpaths may be an array of fallbacks, e.g.
2377
+ // `"./shams": [{ "types": "...", "default": "./shams.js" }, "./shams.js"]`.
2378
+ if (Array.isArray(value)) {
2379
+ for (const item of value) {
2380
+ const picked = pickConditionalEntry(item);
2381
+ if (picked) return picked;
2382
+ }
2383
+ return null;
2384
+ }
2376
2385
  if (!value || typeof value !== 'object') return null;
2377
2386
  // This runtime executes CommonJS, so it prefers CJS-friendly conditions.
2378
2387
  for (const key of ['require', 'node', 'default', 'browser', 'import', 'module']) {
@@ -2429,17 +2438,50 @@
2429
2438
  return parts.join('/');
2430
2439
  }
2431
2440
 
2441
+ // Small promise-based delay. Used only for CDN retry backoff; falls back to an
2442
+ // immediate resolve if `setTimeout` is unavailable in the host.
2443
+ function cdnBackoff(ms) {
2444
+ return new Promise((resolve) => {
2445
+ if (typeof setTimeout === 'function') setTimeout(resolve, ms);
2446
+ else resolve();
2447
+ });
2448
+ }
2449
+
2432
2450
  async function fetchTextFromCdn(fetchImpl, url) {
2433
- try {
2434
- const res = await fetchImpl(url);
2435
- if (!res) return null;
2436
- const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2437
- if (!ok) return null;
2438
- if (typeof res.text === 'function') return await res.text();
2439
- return String(res.body != null ? res.body : '');
2440
- } catch (_) {
2441
- return null;
2451
+ // A single flaky jsDelivr response used to silently produce an *incomplete*
2452
+ // install (the module graph then failed at require-time). Retry transient
2453
+ // failures (network error, 429/408, 5xx) but treat 4xx as final.
2454
+ const maxAttempts = 3;
2455
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
2456
+ try {
2457
+ const res = await fetchImpl(url);
2458
+ if (!res) {
2459
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2460
+ return null;
2461
+ }
2462
+ const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2463
+ if (!ok) {
2464
+ const transient = res.status >= 500 || res.status === 429 || res.status === 408;
2465
+ if (transient && attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2466
+ return null;
2467
+ }
2468
+ // jsDelivr answers a *directory* path (e.g. `/pkg@1/libcjs/`) with HTTP 200
2469
+ // and an HTML directory listing. Storing that as a module both corrupts the
2470
+ // package and later collides with the real directory (EISDIR).
2471
+ const contentType = (res.headers && typeof res.headers.get === 'function')
2472
+ ? (res.headers.get('content-type') || '')
2473
+ : '';
2474
+ const isHtmlUrl = /\.html?(?:[?#]|$)/i.test(url);
2475
+ if (/text\/html/i.test(contentType) && !isHtmlUrl) return null;
2476
+ const text = typeof res.text === 'function' ? await res.text() : String(res.body != null ? res.body : '');
2477
+ if (!isHtmlUrl && /^\s*(?:<!doctype\s+html|<html[\s>]|<head[\s>])/i.test(text)) return null;
2478
+ return text;
2479
+ } catch (_) {
2480
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2481
+ return null;
2482
+ }
2442
2483
  }
2484
+ return null;
2443
2485
  }
2444
2486
 
2445
2487
  async function resolvePackageMetadata(fetchImpl, name, range) {
@@ -2482,14 +2524,25 @@
2482
2524
  const visited = new Set();
2483
2525
  // Seed with the package entry plus any declared `exports` subpaths, so a
2484
2526
  // later `require('pkg/subpath')` (e.g. `entities/decode`) resolves offline.
2485
- const seed = [entry, `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`];
2527
+ // A `main` may point at a *directory* (e.g. chalk: `"main": "source"`); Node
2528
+ // resolves that to `<dir>/index.<ext>`, so those candidates must be seeded
2529
+ // too or the package installs with only its manifest.
2530
+ const seed = [
2531
+ entry,
2532
+ `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`,
2533
+ `${entry}/index.js`, `${entry}/index.json`, `${entry}/index.mjs`, `${entry}/index.cjs`
2534
+ ];
2486
2535
  const expMap = meta.exports;
2487
2536
  if (expMap && typeof expMap === 'object') {
2488
- let subCount = 0;
2537
+ // Seed *every* declared subpath. A low cap silently dropped the tail of
2538
+ // packages that list each file in `exports` (lit-html has 29 keys, so
2539
+ // `lit-html/is-server.js` was never fetched and `require` failed later).
2540
+ // Wildcard keys (`./*`) need no seeding — their files are reached through
2541
+ // the relative-require closure or fetched on demand.
2489
2542
  for (const key of Object.keys(expMap)) {
2490
- if (key === '.' || key.slice(0, 2) !== './' || subCount >= 25) continue;
2543
+ if (key === '.' || key.slice(0, 2) !== './' || key.includes('*')) continue;
2491
2544
  const target = pickConditionalEntry(expMap[key]);
2492
- if (target) { seed.push(target); subCount++; }
2545
+ if (target) seed.push(target);
2493
2546
  }
2494
2547
  }
2495
2548
  let frontier = seed;
@@ -2497,7 +2550,9 @@
2497
2550
  const batch = [];
2498
2551
  for (const raw of frontier) {
2499
2552
  const rel = stripRelPath(raw);
2500
- if (!rel || visited.has(rel)) continue;
2553
+ // Directory targets (e.g. `exports["./lib/"] === "./libcjs/"`) must never
2554
+ // be fetched as files — that is what produced the EISDIR crash.
2555
+ if (!rel || rel.endsWith('/') || visited.has(rel)) continue;
2501
2556
  visited.add(rel);
2502
2557
  batch.push(rel);
2503
2558
  }
@@ -2533,15 +2588,29 @@
2533
2588
  }
2534
2589
 
2535
2590
  // Declared dependencies plus non-optional peer dependencies (npm v7+ style),
2536
- // so e.g. `npm install react-dom` also pulls in `react`.
2537
- const depNames = Object.keys(meta.dependencies || {});
2591
+ // so e.g. `npm install react-dom` also pulls in `react`. The *ranges* are
2592
+ // preserved (not just the names) so transitives resolve to the version the
2593
+ // parent actually asked for — e.g. chalk@4 needs ansi-styles@^4, which itself
2594
+ // needs color-convert. Resolving transitive names as "latest" silently breaks
2595
+ // the tree (ansi-styles@6 has no deps at all).
2596
+ const depSpecs = [];
2597
+ const depSeen = new Set();
2598
+ const declared = meta.dependencies || {};
2599
+ for (const depName of Object.keys(declared)) {
2600
+ if (depSeen.has(depName)) continue;
2601
+ depSeen.add(depName);
2602
+ depSpecs.push({ name: depName, range: declared[depName] || null });
2603
+ }
2538
2604
  const peerMeta = meta.peerDependenciesMeta || {};
2539
- for (const peer of Object.keys(meta.peerDependencies || {})) {
2605
+ const peers = meta.peerDependencies || {};
2606
+ for (const peer of Object.keys(peers)) {
2540
2607
  if (peerMeta[peer] && peerMeta[peer].optional) continue;
2541
- if (depNames.indexOf(peer) === -1) depNames.push(peer);
2608
+ if (depSeen.has(peer)) continue;
2609
+ depSeen.add(peer);
2610
+ depSpecs.push({ name: peer, range: peers[peer] || null });
2542
2611
  }
2543
2612
 
2544
- return { ok: true, version, entry, files, deps: depNames, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2613
+ return { ok: true, version, entry, files, deps: depSpecs, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2545
2614
  }
2546
2615
 
2547
2616
  function installTargetDirs(ctx, name) {
@@ -2555,7 +2624,13 @@
2555
2624
  for (const dir of dirs) {
2556
2625
  ensureDirSync(ctx.vfs, dir, ctx.emitMutation);
2557
2626
  for (const f of info.files) {
2627
+ if (!f || !f.rel || f.rel.endsWith('/')) continue;
2558
2628
  const full = PosixPath.join(dir, f.rel);
2629
+ // Never overwrite a directory with a file body (defensive: a stray
2630
+ // directory target would otherwise raise EISDIR).
2631
+ try {
2632
+ if (ctx.vfs.existsSync(full) && ctx.vfs.statSync(full).isDirectory()) continue;
2633
+ } catch (_) {}
2559
2634
  ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
2560
2635
  ctx.vfs.writeFileSync(full, f.content);
2561
2636
  if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
@@ -2621,10 +2696,11 @@
2621
2696
  if (item.direct) directVersion = info.version || null;
2622
2697
 
2623
2698
  for (const dep of (info.deps || [])) {
2624
- const parsed = parsePackageSpec(dep);
2625
- if (parsed.name && !requested.has(parsed.name)) {
2626
- requested.add(parsed.name);
2627
- queue.push({ name: parsed.name, range: null, direct: false });
2699
+ const depName = (dep && typeof dep === 'object') ? dep.name : parsePackageSpec(dep).name;
2700
+ const depRange = (dep && typeof dep === 'object') ? dep.range : parsePackageSpec(dep).range;
2701
+ if (depName && !requested.has(depName)) {
2702
+ requested.add(depName);
2703
+ queue.push({ name: depName, range: depRange || null, direct: false });
2628
2704
  }
2629
2705
  }
2630
2706
  }
@@ -2981,21 +3057,29 @@
2981
3057
  // Common dev-server commands that cannot run inside the virtual runtime are
2982
3058
  // transparently redirected to the built-in preview server.
2983
3059
  const PREVIEW_TOOL_RE = /\b(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|serve|http-server)\b/;
3060
+ // The same tools, when typed directly at the prompt (`ng serve`, `vite`).
3061
+ // `serve` is omitted: it is a first-class builtin shell command.
3062
+ const DIRECT_DEV_TOOL_RE = /^(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|http-server)$/;
2984
3063
 
2985
- function tryDevScriptFallback(scriptName, cmd, ctx) {
3064
+ function tryDevScriptFallback(scriptName, cmd, ctx, opts) {
2986
3065
  if (!PREVIEW_TOOL_RE.test(cmd)) return null;
2987
3066
  // Only fall back when the referenced tool is not actually installed.
2988
3067
  const bin = (cmd.match(PREVIEW_TOOL_RE) || [])[1];
3068
+ const force = Boolean(opts && opts.force);
2989
3069
  const binPath = PosixPath.join('/workspace/node_modules/.bin', bin);
2990
- if (ctx.vfs.existsSync(binPath)) return null;
3070
+ if (!force && ctx.vfs.existsSync(binPath)) return null;
2991
3071
  const portMatch = cmd.match(/--port(?:=|\s+)(\d+)/);
2992
3072
  const defaultPorts = { ng: 4200, vite: 5173, astro: 4321, next: 3000 };
2993
3073
  const port = portMatch ? Number(portMatch[1]) : (defaultPorts[bin] || 3000);
2994
- const entry = registerPreviewServer(ctx, ctx.cwd, port);
3074
+ const rootDir = typeof ctx.resolvePath === 'function' ? ctx.resolvePath('.') : (ctx.cwd || '/workspace');
3075
+ const entry = registerPreviewServer(ctx, rootDir, port);
2995
3076
  if (!entry) return null;
3077
+ const note = force
3078
+ ? `${bin} is a native dev server and cannot execute inside this virtual runtime — using the CodeLab preview server instead.`
3079
+ : `${bin} is not available in this virtual runtime — using the CodeLab preview server instead.`;
2996
3080
  return {
2997
3081
  code: 0,
2998
- stdout: `\n> ${scriptName}\n> ${cmd}\n\n ${bin} is not available in this virtual runtime — using the CodeLab preview server instead.\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`,
3082
+ stdout: `\n> ${scriptName}\n> ${cmd}\n\n ${note}\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`,
2999
3083
  stderr: ''
3000
3084
  };
3001
3085
  }
@@ -7094,6 +7178,13 @@
7094
7178
  Object.assign(context.env, this.env);
7095
7179
  context.cwd = this.cwd;
7096
7180
  }
7181
+ } else if (DIRECT_DEV_TOOL_RE.test(cmdName)) {
7182
+ // A native dev server (vite/ng/astro/…) typed directly. It cannot run in
7183
+ // this runtime — whether or not it was installed — so route it to the
7184
+ // built-in preview server rather than reporting a misleading "command
7185
+ // not found".
7186
+ const fb = tryDevScriptFallback(cmdName, [cmdName, ...args].join(' '), cmdCtx, { force: true });
7187
+ res = fb || { code: 127, stdout: '', stderr: `shell: ${cmdName}: command not found\n` };
7097
7188
  } else if (typeof this.options.onProcessSpawn === 'function') {
7098
7189
  const spawned = await this.options.onProcessSpawn(cmdName, args, {
7099
7190
  cwd: this.cwd,
package/src/shell.ts CHANGED
@@ -2423,6 +2423,15 @@ function __initShellModule(root: any) {
2423
2423
 
2424
2424
  function pickConditionalEntry(value) {
2425
2425
  if (typeof value === 'string') return value;
2426
+ // `exports` subpaths may be an array of fallbacks, e.g.
2427
+ // `"./shams": [{ "types": "...", "default": "./shams.js" }, "./shams.js"]`.
2428
+ if (Array.isArray(value)) {
2429
+ for (const item of value) {
2430
+ const picked = pickConditionalEntry(item);
2431
+ if (picked) return picked;
2432
+ }
2433
+ return null;
2434
+ }
2426
2435
  if (!value || typeof value !== 'object') return null;
2427
2436
  // This runtime executes CommonJS, so it prefers CJS-friendly conditions.
2428
2437
  for (const key of ['require', 'node', 'default', 'browser', 'import', 'module']) {
@@ -2479,17 +2488,50 @@ function __initShellModule(root: any) {
2479
2488
  return parts.join('/');
2480
2489
  }
2481
2490
 
2491
+ // Small promise-based delay. Used only for CDN retry backoff; falls back to an
2492
+ // immediate resolve if `setTimeout` is unavailable in the host.
2493
+ function cdnBackoff(ms) {
2494
+ return new Promise((resolve) => {
2495
+ if (typeof setTimeout === 'function') setTimeout(resolve, ms);
2496
+ else resolve();
2497
+ });
2498
+ }
2499
+
2482
2500
  async function fetchTextFromCdn(fetchImpl, url) {
2483
- try {
2484
- const res = await fetchImpl(url);
2485
- if (!res) return null;
2486
- const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2487
- if (!ok) return null;
2488
- if (typeof res.text === 'function') return await res.text();
2489
- return String(res.body != null ? res.body : '');
2490
- } catch (_) {
2491
- return null;
2501
+ // A single flaky jsDelivr response used to silently produce an *incomplete*
2502
+ // install (the module graph then failed at require-time). Retry transient
2503
+ // failures (network error, 429/408, 5xx) but treat 4xx as final.
2504
+ const maxAttempts = 3;
2505
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
2506
+ try {
2507
+ const res = await fetchImpl(url);
2508
+ if (!res) {
2509
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2510
+ return null;
2511
+ }
2512
+ const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2513
+ if (!ok) {
2514
+ const transient = res.status >= 500 || res.status === 429 || res.status === 408;
2515
+ if (transient && attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2516
+ return null;
2517
+ }
2518
+ // jsDelivr answers a *directory* path (e.g. `/pkg@1/libcjs/`) with HTTP 200
2519
+ // and an HTML directory listing. Storing that as a module both corrupts the
2520
+ // package and later collides with the real directory (EISDIR).
2521
+ const contentType = (res.headers && typeof res.headers.get === 'function')
2522
+ ? (res.headers.get('content-type') || '')
2523
+ : '';
2524
+ const isHtmlUrl = /\.html?(?:[?#]|$)/i.test(url);
2525
+ if (/text\/html/i.test(contentType) && !isHtmlUrl) return null;
2526
+ const text = typeof res.text === 'function' ? await res.text() : String(res.body != null ? res.body : '');
2527
+ if (!isHtmlUrl && /^\s*(?:<!doctype\s+html|<html[\s>]|<head[\s>])/i.test(text)) return null;
2528
+ return text;
2529
+ } catch (_) {
2530
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2531
+ return null;
2532
+ }
2492
2533
  }
2534
+ return null;
2493
2535
  }
2494
2536
 
2495
2537
  async function resolvePackageMetadata(fetchImpl, name, range) {
@@ -2532,14 +2574,25 @@ function __initShellModule(root: any) {
2532
2574
  const visited = new Set();
2533
2575
  // Seed with the package entry plus any declared `exports` subpaths, so a
2534
2576
  // later `require('pkg/subpath')` (e.g. `entities/decode`) resolves offline.
2535
- const seed = [entry, `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`];
2577
+ // A `main` may point at a *directory* (e.g. chalk: `"main": "source"`); Node
2578
+ // resolves that to `<dir>/index.<ext>`, so those candidates must be seeded
2579
+ // too or the package installs with only its manifest.
2580
+ const seed = [
2581
+ entry,
2582
+ `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`,
2583
+ `${entry}/index.js`, `${entry}/index.json`, `${entry}/index.mjs`, `${entry}/index.cjs`
2584
+ ];
2536
2585
  const expMap = meta.exports;
2537
2586
  if (expMap && typeof expMap === 'object') {
2538
- let subCount = 0;
2587
+ // Seed *every* declared subpath. A low cap silently dropped the tail of
2588
+ // packages that list each file in `exports` (lit-html has 29 keys, so
2589
+ // `lit-html/is-server.js` was never fetched and `require` failed later).
2590
+ // Wildcard keys (`./*`) need no seeding — their files are reached through
2591
+ // the relative-require closure or fetched on demand.
2539
2592
  for (const key of Object.keys(expMap)) {
2540
- if (key === '.' || key.slice(0, 2) !== './' || subCount >= 25) continue;
2593
+ if (key === '.' || key.slice(0, 2) !== './' || key.includes('*')) continue;
2541
2594
  const target = pickConditionalEntry(expMap[key]);
2542
- if (target) { seed.push(target); subCount++; }
2595
+ if (target) seed.push(target);
2543
2596
  }
2544
2597
  }
2545
2598
  let frontier = seed;
@@ -2547,7 +2600,9 @@ function __initShellModule(root: any) {
2547
2600
  const batch = [];
2548
2601
  for (const raw of frontier) {
2549
2602
  const rel = stripRelPath(raw);
2550
- if (!rel || visited.has(rel)) continue;
2603
+ // Directory targets (e.g. `exports["./lib/"] === "./libcjs/"`) must never
2604
+ // be fetched as files — that is what produced the EISDIR crash.
2605
+ if (!rel || rel.endsWith('/') || visited.has(rel)) continue;
2551
2606
  visited.add(rel);
2552
2607
  batch.push(rel);
2553
2608
  }
@@ -2583,15 +2638,29 @@ function __initShellModule(root: any) {
2583
2638
  }
2584
2639
 
2585
2640
  // Declared dependencies plus non-optional peer dependencies (npm v7+ style),
2586
- // so e.g. `npm install react-dom` also pulls in `react`.
2587
- const depNames = Object.keys(meta.dependencies || {});
2641
+ // so e.g. `npm install react-dom` also pulls in `react`. The *ranges* are
2642
+ // preserved (not just the names) so transitives resolve to the version the
2643
+ // parent actually asked for — e.g. chalk@4 needs ansi-styles@^4, which itself
2644
+ // needs color-convert. Resolving transitive names as "latest" silently breaks
2645
+ // the tree (ansi-styles@6 has no deps at all).
2646
+ const depSpecs: Array<{ name: string; range: string | null }> = [];
2647
+ const depSeen = new Set<string>();
2648
+ const declared = (meta.dependencies || {}) as Record<string, string>;
2649
+ for (const depName of Object.keys(declared)) {
2650
+ if (depSeen.has(depName)) continue;
2651
+ depSeen.add(depName);
2652
+ depSpecs.push({ name: depName, range: declared[depName] || null });
2653
+ }
2588
2654
  const peerMeta = meta.peerDependenciesMeta || {};
2589
- for (const peer of Object.keys(meta.peerDependencies || {})) {
2655
+ const peers = (meta.peerDependencies || {}) as Record<string, string>;
2656
+ for (const peer of Object.keys(peers)) {
2590
2657
  if (peerMeta[peer] && peerMeta[peer].optional) continue;
2591
- if (depNames.indexOf(peer) === -1) depNames.push(peer);
2658
+ if (depSeen.has(peer)) continue;
2659
+ depSeen.add(peer);
2660
+ depSpecs.push({ name: peer, range: peers[peer] || null });
2592
2661
  }
2593
2662
 
2594
- return { ok: true, version, entry, files, deps: depNames, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2663
+ return { ok: true, version, entry, files, deps: depSpecs, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2595
2664
  }
2596
2665
 
2597
2666
  function installTargetDirs(ctx, name) {
@@ -2605,7 +2674,13 @@ function __initShellModule(root: any) {
2605
2674
  for (const dir of dirs) {
2606
2675
  ensureDirSync(ctx.vfs, dir, ctx.emitMutation);
2607
2676
  for (const f of info.files) {
2677
+ if (!f || !f.rel || f.rel.endsWith('/')) continue;
2608
2678
  const full = PosixPath.join(dir, f.rel);
2679
+ // Never overwrite a directory with a file body (defensive: a stray
2680
+ // directory target would otherwise raise EISDIR).
2681
+ try {
2682
+ if (ctx.vfs.existsSync(full) && ctx.vfs.statSync(full).isDirectory()) continue;
2683
+ } catch (_) {}
2609
2684
  ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
2610
2685
  ctx.vfs.writeFileSync(full, f.content);
2611
2686
  if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
@@ -2671,10 +2746,11 @@ function __initShellModule(root: any) {
2671
2746
  if (item.direct) directVersion = info.version || null;
2672
2747
 
2673
2748
  for (const dep of (info.deps || [])) {
2674
- const parsed = parsePackageSpec(dep);
2675
- if (parsed.name && !requested.has(parsed.name)) {
2676
- requested.add(parsed.name);
2677
- queue.push({ name: parsed.name, range: null, direct: false });
2749
+ const depName = (dep && typeof dep === 'object') ? dep.name : parsePackageSpec(dep).name;
2750
+ const depRange = (dep && typeof dep === 'object') ? dep.range : parsePackageSpec(dep).range;
2751
+ if (depName && !requested.has(depName)) {
2752
+ requested.add(depName);
2753
+ queue.push({ name: depName, range: depRange || null, direct: false });
2678
2754
  }
2679
2755
  }
2680
2756
  }
@@ -3031,21 +3107,29 @@ function __initShellModule(root: any) {
3031
3107
  // Common dev-server commands that cannot run inside the virtual runtime are
3032
3108
  // transparently redirected to the built-in preview server.
3033
3109
  const PREVIEW_TOOL_RE = /\b(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|serve|http-server)\b/;
3110
+ // The same tools, when typed directly at the prompt (`ng serve`, `vite`).
3111
+ // `serve` is omitted: it is a first-class builtin shell command.
3112
+ const DIRECT_DEV_TOOL_RE = /^(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|http-server)$/;
3034
3113
 
3035
- function tryDevScriptFallback(scriptName, cmd, ctx) {
3114
+ function tryDevScriptFallback(scriptName, cmd, ctx, opts) {
3036
3115
  if (!PREVIEW_TOOL_RE.test(cmd)) return null;
3037
3116
  // Only fall back when the referenced tool is not actually installed.
3038
3117
  const bin = (cmd.match(PREVIEW_TOOL_RE) || [])[1];
3118
+ const force = Boolean(opts && opts.force);
3039
3119
  const binPath = PosixPath.join('/workspace/node_modules/.bin', bin);
3040
- if (ctx.vfs.existsSync(binPath)) return null;
3120
+ if (!force && ctx.vfs.existsSync(binPath)) return null;
3041
3121
  const portMatch = cmd.match(/--port(?:=|\s+)(\d+)/);
3042
3122
  const defaultPorts = { ng: 4200, vite: 5173, astro: 4321, next: 3000 };
3043
3123
  const port = portMatch ? Number(portMatch[1]) : (defaultPorts[bin] || 3000);
3044
- const entry = registerPreviewServer(ctx, ctx.cwd, port);
3124
+ const rootDir = typeof ctx.resolvePath === 'function' ? ctx.resolvePath('.') : (ctx.cwd || '/workspace');
3125
+ const entry = registerPreviewServer(ctx, rootDir, port);
3045
3126
  if (!entry) return null;
3127
+ const note = force
3128
+ ? `${bin} is a native dev server and cannot execute inside this virtual runtime — using the CodeLab preview server instead.`
3129
+ : `${bin} is not available in this virtual runtime — using the CodeLab preview server instead.`;
3046
3130
  return {
3047
3131
  code: 0,
3048
- stdout: `\n> ${scriptName}\n> ${cmd}\n\n ${bin} is not available in this virtual runtime — using the CodeLab preview server instead.\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`,
3132
+ stdout: `\n> ${scriptName}\n> ${cmd}\n\n ${note}\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`,
3049
3133
  stderr: ''
3050
3134
  };
3051
3135
  }
@@ -7144,6 +7228,13 @@ function __initShellModule(root: any) {
7144
7228
  Object.assign(context.env, this.env);
7145
7229
  context.cwd = this.cwd;
7146
7230
  }
7231
+ } else if (DIRECT_DEV_TOOL_RE.test(cmdName)) {
7232
+ // A native dev server (vite/ng/astro/…) typed directly. It cannot run in
7233
+ // this runtime — whether or not it was installed — so route it to the
7234
+ // built-in preview server rather than reporting a misleading "command
7235
+ // not found".
7236
+ const fb = tryDevScriptFallback(cmdName, [cmdName, ...args].join(' '), cmdCtx, { force: true });
7237
+ res = fb || { code: 127, stdout: '', stderr: `shell: ${cmdName}: command not found\n` };
7147
7238
  } else if (typeof this.options.onProcessSpawn === 'function') {
7148
7239
  const spawned = await this.options.onProcessSpawn(cmdName, args, {
7149
7240
  cwd: this.cwd,