@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/dist/shell.esm.js CHANGED
@@ -2391,6 +2391,15 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2391
2391
 
2392
2392
  function pickConditionalEntry(value) {
2393
2393
  if (typeof value === 'string') return value;
2394
+ // `exports` subpaths may be an array of fallbacks, e.g.
2395
+ // `"./shams": [{ "types": "...", "default": "./shams.js" }, "./shams.js"]`.
2396
+ if (Array.isArray(value)) {
2397
+ for (const item of value) {
2398
+ const picked = pickConditionalEntry(item);
2399
+ if (picked) return picked;
2400
+ }
2401
+ return null;
2402
+ }
2394
2403
  if (!value || typeof value !== 'object') return null;
2395
2404
  // This runtime executes CommonJS, so it prefers CJS-friendly conditions.
2396
2405
  for (const key of ['require', 'node', 'default', 'browser', 'import', 'module']) {
@@ -2447,17 +2456,50 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2447
2456
  return parts.join('/');
2448
2457
  }
2449
2458
 
2459
+ // Small promise-based delay. Used only for CDN retry backoff; falls back to an
2460
+ // immediate resolve if `setTimeout` is unavailable in the host.
2461
+ function cdnBackoff(ms) {
2462
+ return new Promise((resolve) => {
2463
+ if (typeof setTimeout === 'function') setTimeout(resolve, ms);
2464
+ else resolve();
2465
+ });
2466
+ }
2467
+
2450
2468
  async function fetchTextFromCdn(fetchImpl, url) {
2451
- try {
2452
- const res = await fetchImpl(url);
2453
- if (!res) return null;
2454
- const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2455
- if (!ok) return null;
2456
- if (typeof res.text === 'function') return await res.text();
2457
- return String(res.body != null ? res.body : '');
2458
- } catch (_) {
2459
- return null;
2469
+ // A single flaky jsDelivr response used to silently produce an *incomplete*
2470
+ // install (the module graph then failed at require-time). Retry transient
2471
+ // failures (network error, 429/408, 5xx) but treat 4xx as final.
2472
+ const maxAttempts = 3;
2473
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
2474
+ try {
2475
+ const res = await fetchImpl(url);
2476
+ if (!res) {
2477
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2478
+ return null;
2479
+ }
2480
+ const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2481
+ if (!ok) {
2482
+ const transient = res.status >= 500 || res.status === 429 || res.status === 408;
2483
+ if (transient && attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2484
+ return null;
2485
+ }
2486
+ // jsDelivr answers a *directory* path (e.g. `/pkg@1/libcjs/`) with HTTP 200
2487
+ // and an HTML directory listing. Storing that as a module both corrupts the
2488
+ // package and later collides with the real directory (EISDIR).
2489
+ const contentType = (res.headers && typeof res.headers.get === 'function')
2490
+ ? (res.headers.get('content-type') || '')
2491
+ : '';
2492
+ const isHtmlUrl = /\.html?(?:[?#]|$)/i.test(url);
2493
+ if (/text\/html/i.test(contentType) && !isHtmlUrl) return null;
2494
+ const text = typeof res.text === 'function' ? await res.text() : String(res.body != null ? res.body : '');
2495
+ if (!isHtmlUrl && /^\s*(?:<!doctype\s+html|<html[\s>]|<head[\s>])/i.test(text)) return null;
2496
+ return text;
2497
+ } catch (_) {
2498
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2499
+ return null;
2500
+ }
2460
2501
  }
2502
+ return null;
2461
2503
  }
2462
2504
 
2463
2505
  async function resolvePackageMetadata(fetchImpl, name, range) {
@@ -2500,14 +2542,25 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2500
2542
  const visited = new Set();
2501
2543
  // Seed with the package entry plus any declared `exports` subpaths, so a
2502
2544
  // later `require('pkg/subpath')` (e.g. `entities/decode`) resolves offline.
2503
- const seed = [entry, `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`];
2545
+ // A `main` may point at a *directory* (e.g. chalk: `"main": "source"`); Node
2546
+ // resolves that to `<dir>/index.<ext>`, so those candidates must be seeded
2547
+ // too or the package installs with only its manifest.
2548
+ const seed = [
2549
+ entry,
2550
+ `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`,
2551
+ `${entry}/index.js`, `${entry}/index.json`, `${entry}/index.mjs`, `${entry}/index.cjs`
2552
+ ];
2504
2553
  const expMap = meta.exports;
2505
2554
  if (expMap && typeof expMap === 'object') {
2506
- let subCount = 0;
2555
+ // Seed *every* declared subpath. A low cap silently dropped the tail of
2556
+ // packages that list each file in `exports` (lit-html has 29 keys, so
2557
+ // `lit-html/is-server.js` was never fetched and `require` failed later).
2558
+ // Wildcard keys (`./*`) need no seeding — their files are reached through
2559
+ // the relative-require closure or fetched on demand.
2507
2560
  for (const key of Object.keys(expMap)) {
2508
- if (key === '.' || key.slice(0, 2) !== './' || subCount >= 25) continue;
2561
+ if (key === '.' || key.slice(0, 2) !== './' || key.includes('*')) continue;
2509
2562
  const target = pickConditionalEntry(expMap[key]);
2510
- if (target) { seed.push(target); subCount++; }
2563
+ if (target) seed.push(target);
2511
2564
  }
2512
2565
  }
2513
2566
  let frontier = seed;
@@ -2515,7 +2568,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2515
2568
  const batch = [];
2516
2569
  for (const raw of frontier) {
2517
2570
  const rel = stripRelPath(raw);
2518
- if (!rel || visited.has(rel)) continue;
2571
+ // Directory targets (e.g. `exports["./lib/"] === "./libcjs/"`) must never
2572
+ // be fetched as files — that is what produced the EISDIR crash.
2573
+ if (!rel || rel.endsWith('/') || visited.has(rel)) continue;
2519
2574
  visited.add(rel);
2520
2575
  batch.push(rel);
2521
2576
  }
@@ -2551,15 +2606,29 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2551
2606
  }
2552
2607
 
2553
2608
  // Declared dependencies plus non-optional peer dependencies (npm v7+ style),
2554
- // so e.g. `npm install react-dom` also pulls in `react`.
2555
- const depNames = Object.keys(meta.dependencies || {});
2609
+ // so e.g. `npm install react-dom` also pulls in `react`. The *ranges* are
2610
+ // preserved (not just the names) so transitives resolve to the version the
2611
+ // parent actually asked for — e.g. chalk@4 needs ansi-styles@^4, which itself
2612
+ // needs color-convert. Resolving transitive names as "latest" silently breaks
2613
+ // the tree (ansi-styles@6 has no deps at all).
2614
+ const depSpecs = [];
2615
+ const depSeen = new Set();
2616
+ const declared = meta.dependencies || {};
2617
+ for (const depName of Object.keys(declared)) {
2618
+ if (depSeen.has(depName)) continue;
2619
+ depSeen.add(depName);
2620
+ depSpecs.push({ name: depName, range: declared[depName] || null });
2621
+ }
2556
2622
  const peerMeta = meta.peerDependenciesMeta || {};
2557
- for (const peer of Object.keys(meta.peerDependencies || {})) {
2623
+ const peers = meta.peerDependencies || {};
2624
+ for (const peer of Object.keys(peers)) {
2558
2625
  if (peerMeta[peer] && peerMeta[peer].optional) continue;
2559
- if (depNames.indexOf(peer) === -1) depNames.push(peer);
2626
+ if (depSeen.has(peer)) continue;
2627
+ depSeen.add(peer);
2628
+ depSpecs.push({ name: peer, range: peers[peer] || null });
2560
2629
  }
2561
2630
 
2562
- return { ok: true, version, entry, files, deps: depNames, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2631
+ return { ok: true, version, entry, files, deps: depSpecs, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2563
2632
  }
2564
2633
 
2565
2634
  function installTargetDirs(ctx, name) {
@@ -2573,7 +2642,13 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2573
2642
  for (const dir of dirs) {
2574
2643
  ensureDirSync(ctx.vfs, dir, ctx.emitMutation);
2575
2644
  for (const f of info.files) {
2645
+ if (!f || !f.rel || f.rel.endsWith('/')) continue;
2576
2646
  const full = PosixPath.join(dir, f.rel);
2647
+ // Never overwrite a directory with a file body (defensive: a stray
2648
+ // directory target would otherwise raise EISDIR).
2649
+ try {
2650
+ if (ctx.vfs.existsSync(full) && ctx.vfs.statSync(full).isDirectory()) continue;
2651
+ } catch (_) {}
2577
2652
  ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
2578
2653
  ctx.vfs.writeFileSync(full, f.content);
2579
2654
  if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
@@ -2639,10 +2714,11 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2639
2714
  if (item.direct) directVersion = info.version || null;
2640
2715
 
2641
2716
  for (const dep of (info.deps || [])) {
2642
- const parsed = parsePackageSpec(dep);
2643
- if (parsed.name && !requested.has(parsed.name)) {
2644
- requested.add(parsed.name);
2645
- queue.push({ name: parsed.name, range: null, direct: false });
2717
+ const depName = (dep && typeof dep === 'object') ? dep.name : parsePackageSpec(dep).name;
2718
+ const depRange = (dep && typeof dep === 'object') ? dep.range : parsePackageSpec(dep).range;
2719
+ if (depName && !requested.has(depName)) {
2720
+ requested.add(depName);
2721
+ queue.push({ name: depName, range: depRange || null, direct: false });
2646
2722
  }
2647
2723
  }
2648
2724
  }
@@ -2999,21 +3075,29 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2999
3075
  // Common dev-server commands that cannot run inside the virtual runtime are
3000
3076
  // transparently redirected to the built-in preview server.
3001
3077
  const PREVIEW_TOOL_RE = /\b(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|serve|http-server)\b/;
3078
+ // The same tools, when typed directly at the prompt (`ng serve`, `vite`).
3079
+ // `serve` is omitted: it is a first-class builtin shell command.
3080
+ const DIRECT_DEV_TOOL_RE = /^(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|http-server)$/;
3002
3081
 
3003
- function tryDevScriptFallback(scriptName, cmd, ctx) {
3082
+ function tryDevScriptFallback(scriptName, cmd, ctx, opts) {
3004
3083
  if (!PREVIEW_TOOL_RE.test(cmd)) return null;
3005
3084
  // Only fall back when the referenced tool is not actually installed.
3006
3085
  const bin = (cmd.match(PREVIEW_TOOL_RE) || [])[1];
3086
+ const force = Boolean(opts && opts.force);
3007
3087
  const binPath = PosixPath.join('/workspace/node_modules/.bin', bin);
3008
- if (ctx.vfs.existsSync(binPath)) return null;
3088
+ if (!force && ctx.vfs.existsSync(binPath)) return null;
3009
3089
  const portMatch = cmd.match(/--port(?:=|\s+)(\d+)/);
3010
3090
  const defaultPorts = { ng: 4200, vite: 5173, astro: 4321, next: 3000 };
3011
3091
  const port = portMatch ? Number(portMatch[1]) : (defaultPorts[bin] || 3000);
3012
- const entry = registerPreviewServer(ctx, ctx.cwd, port);
3092
+ const rootDir = typeof ctx.resolvePath === 'function' ? ctx.resolvePath('.') : (ctx.cwd || '/workspace');
3093
+ const entry = registerPreviewServer(ctx, rootDir, port);
3013
3094
  if (!entry) return null;
3095
+ const note = force
3096
+ ? `${bin} is a native dev server and cannot execute inside this virtual runtime — using the CodeLab preview server instead.`
3097
+ : `${bin} is not available in this virtual runtime — using the CodeLab preview server instead.`;
3014
3098
  return {
3015
3099
  code: 0,
3016
- 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`,
3100
+ stdout: `\n> ${scriptName}\n> ${cmd}\n\n ${note}\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`,
3017
3101
  stderr: ''
3018
3102
  };
3019
3103
  }
@@ -7112,6 +7196,13 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
7112
7196
  Object.assign(context.env, this.env);
7113
7197
  context.cwd = this.cwd;
7114
7198
  }
7199
+ } else if (DIRECT_DEV_TOOL_RE.test(cmdName)) {
7200
+ // A native dev server (vite/ng/astro/…) typed directly. It cannot run in
7201
+ // this runtime — whether or not it was installed — so route it to the
7202
+ // built-in preview server rather than reporting a misleading "command
7203
+ // not found".
7204
+ const fb = tryDevScriptFallback(cmdName, [cmdName, ...args].join(' '), cmdCtx, { force: true });
7205
+ res = fb || { code: 127, stdout: '', stderr: `shell: ${cmdName}: command not found\n` };
7115
7206
  } else if (typeof this.options.onProcessSpawn === 'function') {
7116
7207
  const spawned = await this.options.onProcessSpawn(cmdName, args, {
7117
7208
  cwd: this.cwd,
package/dist/shell.js CHANGED
@@ -2392,6 +2392,15 @@
2392
2392
 
2393
2393
  function pickConditionalEntry(value) {
2394
2394
  if (typeof value === 'string') return value;
2395
+ // `exports` subpaths may be an array of fallbacks, e.g.
2396
+ // `"./shams": [{ "types": "...", "default": "./shams.js" }, "./shams.js"]`.
2397
+ if (Array.isArray(value)) {
2398
+ for (const item of value) {
2399
+ const picked = pickConditionalEntry(item);
2400
+ if (picked) return picked;
2401
+ }
2402
+ return null;
2403
+ }
2395
2404
  if (!value || typeof value !== 'object') return null;
2396
2405
  // This runtime executes CommonJS, so it prefers CJS-friendly conditions.
2397
2406
  for (const key of ['require', 'node', 'default', 'browser', 'import', 'module']) {
@@ -2448,17 +2457,50 @@
2448
2457
  return parts.join('/');
2449
2458
  }
2450
2459
 
2460
+ // Small promise-based delay. Used only for CDN retry backoff; falls back to an
2461
+ // immediate resolve if `setTimeout` is unavailable in the host.
2462
+ function cdnBackoff(ms) {
2463
+ return new Promise((resolve) => {
2464
+ if (typeof setTimeout === 'function') setTimeout(resolve, ms);
2465
+ else resolve();
2466
+ });
2467
+ }
2468
+
2451
2469
  async function fetchTextFromCdn(fetchImpl, url) {
2452
- try {
2453
- const res = await fetchImpl(url);
2454
- if (!res) return null;
2455
- const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2456
- if (!ok) return null;
2457
- if (typeof res.text === 'function') return await res.text();
2458
- return String(res.body != null ? res.body : '');
2459
- } catch (_) {
2460
- return null;
2470
+ // A single flaky jsDelivr response used to silently produce an *incomplete*
2471
+ // install (the module graph then failed at require-time). Retry transient
2472
+ // failures (network error, 429/408, 5xx) but treat 4xx as final.
2473
+ const maxAttempts = 3;
2474
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
2475
+ try {
2476
+ const res = await fetchImpl(url);
2477
+ if (!res) {
2478
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2479
+ return null;
2480
+ }
2481
+ const ok = (res.ok === true) || res.status === 200 || res.status === undefined;
2482
+ if (!ok) {
2483
+ const transient = res.status >= 500 || res.status === 429 || res.status === 408;
2484
+ if (transient && attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2485
+ return null;
2486
+ }
2487
+ // jsDelivr answers a *directory* path (e.g. `/pkg@1/libcjs/`) with HTTP 200
2488
+ // and an HTML directory listing. Storing that as a module both corrupts the
2489
+ // package and later collides with the real directory (EISDIR).
2490
+ const contentType = (res.headers && typeof res.headers.get === 'function')
2491
+ ? (res.headers.get('content-type') || '')
2492
+ : '';
2493
+ const isHtmlUrl = /\.html?(?:[?#]|$)/i.test(url);
2494
+ if (/text\/html/i.test(contentType) && !isHtmlUrl) return null;
2495
+ const text = typeof res.text === 'function' ? await res.text() : String(res.body != null ? res.body : '');
2496
+ if (!isHtmlUrl && /^\s*(?:<!doctype\s+html|<html[\s>]|<head[\s>])/i.test(text)) return null;
2497
+ return text;
2498
+ } catch (_) {
2499
+ if (attempt < maxAttempts) { await cdnBackoff(attempt * 150); continue; }
2500
+ return null;
2501
+ }
2461
2502
  }
2503
+ return null;
2462
2504
  }
2463
2505
 
2464
2506
  async function resolvePackageMetadata(fetchImpl, name, range) {
@@ -2501,14 +2543,25 @@
2501
2543
  const visited = new Set();
2502
2544
  // Seed with the package entry plus any declared `exports` subpaths, so a
2503
2545
  // later `require('pkg/subpath')` (e.g. `entities/decode`) resolves offline.
2504
- const seed = [entry, `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`];
2546
+ // A `main` may point at a *directory* (e.g. chalk: `"main": "source"`); Node
2547
+ // resolves that to `<dir>/index.<ext>`, so those candidates must be seeded
2548
+ // too or the package installs with only its manifest.
2549
+ const seed = [
2550
+ entry,
2551
+ `${entry}.js`, `${entry}.json`, `${entry}.mjs`, `${entry}.cjs`,
2552
+ `${entry}/index.js`, `${entry}/index.json`, `${entry}/index.mjs`, `${entry}/index.cjs`
2553
+ ];
2505
2554
  const expMap = meta.exports;
2506
2555
  if (expMap && typeof expMap === 'object') {
2507
- let subCount = 0;
2556
+ // Seed *every* declared subpath. A low cap silently dropped the tail of
2557
+ // packages that list each file in `exports` (lit-html has 29 keys, so
2558
+ // `lit-html/is-server.js` was never fetched and `require` failed later).
2559
+ // Wildcard keys (`./*`) need no seeding — their files are reached through
2560
+ // the relative-require closure or fetched on demand.
2508
2561
  for (const key of Object.keys(expMap)) {
2509
- if (key === '.' || key.slice(0, 2) !== './' || subCount >= 25) continue;
2562
+ if (key === '.' || key.slice(0, 2) !== './' || key.includes('*')) continue;
2510
2563
  const target = pickConditionalEntry(expMap[key]);
2511
- if (target) { seed.push(target); subCount++; }
2564
+ if (target) seed.push(target);
2512
2565
  }
2513
2566
  }
2514
2567
  let frontier = seed;
@@ -2516,7 +2569,9 @@
2516
2569
  const batch = [];
2517
2570
  for (const raw of frontier) {
2518
2571
  const rel = stripRelPath(raw);
2519
- if (!rel || visited.has(rel)) continue;
2572
+ // Directory targets (e.g. `exports["./lib/"] === "./libcjs/"`) must never
2573
+ // be fetched as files — that is what produced the EISDIR crash.
2574
+ if (!rel || rel.endsWith('/') || visited.has(rel)) continue;
2520
2575
  visited.add(rel);
2521
2576
  batch.push(rel);
2522
2577
  }
@@ -2552,15 +2607,29 @@
2552
2607
  }
2553
2608
 
2554
2609
  // Declared dependencies plus non-optional peer dependencies (npm v7+ style),
2555
- // so e.g. `npm install react-dom` also pulls in `react`.
2556
- const depNames = Object.keys(meta.dependencies || {});
2610
+ // so e.g. `npm install react-dom` also pulls in `react`. The *ranges* are
2611
+ // preserved (not just the names) so transitives resolve to the version the
2612
+ // parent actually asked for — e.g. chalk@4 needs ansi-styles@^4, which itself
2613
+ // needs color-convert. Resolving transitive names as "latest" silently breaks
2614
+ // the tree (ansi-styles@6 has no deps at all).
2615
+ const depSpecs = [];
2616
+ const depSeen = new Set();
2617
+ const declared = meta.dependencies || {};
2618
+ for (const depName of Object.keys(declared)) {
2619
+ if (depSeen.has(depName)) continue;
2620
+ depSeen.add(depName);
2621
+ depSpecs.push({ name: depName, range: declared[depName] || null });
2622
+ }
2557
2623
  const peerMeta = meta.peerDependenciesMeta || {};
2558
- for (const peer of Object.keys(meta.peerDependencies || {})) {
2624
+ const peers = meta.peerDependencies || {};
2625
+ for (const peer of Object.keys(peers)) {
2559
2626
  if (peerMeta[peer] && peerMeta[peer].optional) continue;
2560
- if (depNames.indexOf(peer) === -1) depNames.push(peer);
2627
+ if (depSeen.has(peer)) continue;
2628
+ depSeen.add(peer);
2629
+ depSpecs.push({ name: peer, range: peers[peer] || null });
2561
2630
  }
2562
2631
 
2563
- return { ok: true, version, entry, files, deps: depNames, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2632
+ return { ok: true, version, entry, files, deps: depSpecs, pkgExports: (meta.exports && typeof meta.exports === 'object') ? meta.exports : null };
2564
2633
  }
2565
2634
 
2566
2635
  function installTargetDirs(ctx, name) {
@@ -2574,7 +2643,13 @@
2574
2643
  for (const dir of dirs) {
2575
2644
  ensureDirSync(ctx.vfs, dir, ctx.emitMutation);
2576
2645
  for (const f of info.files) {
2646
+ if (!f || !f.rel || f.rel.endsWith('/')) continue;
2577
2647
  const full = PosixPath.join(dir, f.rel);
2648
+ // Never overwrite a directory with a file body (defensive: a stray
2649
+ // directory target would otherwise raise EISDIR).
2650
+ try {
2651
+ if (ctx.vfs.existsSync(full) && ctx.vfs.statSync(full).isDirectory()) continue;
2652
+ } catch (_) {}
2578
2653
  ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
2579
2654
  ctx.vfs.writeFileSync(full, f.content);
2580
2655
  if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
@@ -2640,10 +2715,11 @@
2640
2715
  if (item.direct) directVersion = info.version || null;
2641
2716
 
2642
2717
  for (const dep of (info.deps || [])) {
2643
- const parsed = parsePackageSpec(dep);
2644
- if (parsed.name && !requested.has(parsed.name)) {
2645
- requested.add(parsed.name);
2646
- queue.push({ name: parsed.name, range: null, direct: false });
2718
+ const depName = (dep && typeof dep === 'object') ? dep.name : parsePackageSpec(dep).name;
2719
+ const depRange = (dep && typeof dep === 'object') ? dep.range : parsePackageSpec(dep).range;
2720
+ if (depName && !requested.has(depName)) {
2721
+ requested.add(depName);
2722
+ queue.push({ name: depName, range: depRange || null, direct: false });
2647
2723
  }
2648
2724
  }
2649
2725
  }
@@ -3000,21 +3076,29 @@
3000
3076
  // Common dev-server commands that cannot run inside the virtual runtime are
3001
3077
  // transparently redirected to the built-in preview server.
3002
3078
  const PREVIEW_TOOL_RE = /\b(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|serve|http-server)\b/;
3079
+ // The same tools, when typed directly at the prompt (`ng serve`, `vite`).
3080
+ // `serve` is omitted: it is a first-class builtin shell command.
3081
+ const DIRECT_DEV_TOOL_RE = /^(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|http-server)$/;
3003
3082
 
3004
- function tryDevScriptFallback(scriptName, cmd, ctx) {
3083
+ function tryDevScriptFallback(scriptName, cmd, ctx, opts) {
3005
3084
  if (!PREVIEW_TOOL_RE.test(cmd)) return null;
3006
3085
  // Only fall back when the referenced tool is not actually installed.
3007
3086
  const bin = (cmd.match(PREVIEW_TOOL_RE) || [])[1];
3087
+ const force = Boolean(opts && opts.force);
3008
3088
  const binPath = PosixPath.join('/workspace/node_modules/.bin', bin);
3009
- if (ctx.vfs.existsSync(binPath)) return null;
3089
+ if (!force && ctx.vfs.existsSync(binPath)) return null;
3010
3090
  const portMatch = cmd.match(/--port(?:=|\s+)(\d+)/);
3011
3091
  const defaultPorts = { ng: 4200, vite: 5173, astro: 4321, next: 3000 };
3012
3092
  const port = portMatch ? Number(portMatch[1]) : (defaultPorts[bin] || 3000);
3013
- const entry = registerPreviewServer(ctx, ctx.cwd, port);
3093
+ const rootDir = typeof ctx.resolvePath === 'function' ? ctx.resolvePath('.') : (ctx.cwd || '/workspace');
3094
+ const entry = registerPreviewServer(ctx, rootDir, port);
3014
3095
  if (!entry) return null;
3096
+ const note = force
3097
+ ? `${bin} is a native dev server and cannot execute inside this virtual runtime — using the CodeLab preview server instead.`
3098
+ : `${bin} is not available in this virtual runtime — using the CodeLab preview server instead.`;
3015
3099
  return {
3016
3100
  code: 0,
3017
- 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`,
3101
+ stdout: `\n> ${scriptName}\n> ${cmd}\n\n ${note}\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`,
3018
3102
  stderr: ''
3019
3103
  };
3020
3104
  }
@@ -7113,6 +7197,13 @@
7113
7197
  Object.assign(context.env, this.env);
7114
7198
  context.cwd = this.cwd;
7115
7199
  }
7200
+ } else if (DIRECT_DEV_TOOL_RE.test(cmdName)) {
7201
+ // A native dev server (vite/ng/astro/…) typed directly. It cannot run in
7202
+ // this runtime — whether or not it was installed — so route it to the
7203
+ // built-in preview server rather than reporting a misleading "command
7204
+ // not found".
7205
+ const fb = tryDevScriptFallback(cmdName, [cmdName, ...args].join(' '), cmdCtx, { force: true });
7206
+ res = fb || { code: 127, stdout: '', stderr: `shell: ${cmdName}: command not found\n` };
7116
7207
  } else if (typeof this.options.onProcessSpawn === 'function') {
7117
7208
  const spawned = await this.options.onProcessSpawn(cmdName, args, {
7118
7209
  cwd: this.cwd,
@@ -1071,6 +1071,9 @@ const createTerminal = CodeLabTerminal.createTerminal;
1071
1071
  const createPTYTerminalEngine = CodeLabTerminal.createPTYTerminalEngine;
1072
1072
  const ansiToHtml = CodeLabTerminal.ansiToHtml;
1073
1073
  const parseAnsiToHtml = CodeLabTerminal.parseAnsiToHtml;
1074
+ const escapeHtml = CodeLabTerminal.escapeHtml;
1075
+ const ANSI_CODE_MAP = CodeLabTerminal.ANSI_CODE_MAP;
1076
+ const resolveAnsiControlCodes = CodeLabTerminal.resolveAnsiControlCodes;
1074
1077
 
1075
1078
  export {
1076
1079
  CodeLabTerminal,
@@ -1078,6 +1081,9 @@ export {
1078
1081
  createTerminal,
1079
1082
  createPTYTerminalEngine,
1080
1083
  ansiToHtml,
1081
- parseAnsiToHtml
1084
+ parseAnsiToHtml,
1085
+ escapeHtml,
1086
+ ANSI_CODE_MAP,
1087
+ resolveAnsiControlCodes
1082
1088
  };
1083
1089
  export default CodeLabTerminal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovatorved/code-lab",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "./schemas": {
41
41
  "types": "./dist/schemas.d.ts",
42
- "import": "./dist/schemas.js",
42
+ "import": "./dist/schemas.esm.js",
43
43
  "require": "./dist/schemas.js",
44
44
  "default": "./dist/schemas.js"
45
45
  },
@@ -50,7 +50,8 @@
50
50
  "./sample": "./dist/sample.html",
51
51
  "./preview-sw.js": "./dist/preview-sw.js",
52
52
  "./preview-sw": "./dist/preview-sw.js",
53
- "./sw": "./dist/preview-sw.js"
53
+ "./sw": "./dist/preview-sw.js",
54
+ "./package.json": "./package.json"
54
55
  },
55
56
  "files": [
56
57
  "dist",
@@ -72,7 +73,7 @@
72
73
  "build": "bun run tools/bundle.js",
73
74
  "typecheck": "bun x tsc --noEmit",
74
75
  "test": "bun run tests/test-all-builds.js",
75
- "test:all": "bun run tools/bundle.js && bun run tests/test-all-builds.js && bun run tests/test-runtime-advanced.js && bun run tests/test-option1-shell-bun-http.js && bun run tests/test-frameworks.js && bun run tests/test-coreutils-adversarial.js && bun run tests/test-stress-shell.js && bun run tests/test-workbench-ui.js && bun run tests/test-terminal-streaming.js && bun run tests/test-git-clone-streaming.js && bun run tests/test-m1-adversarial-challenger.js && bun run tests/test-m1-interruption-lifecycle-stress.js && bun run tests/test-gfm-markdown.js && bun run tests/test-m2-adversarial-syntax.js && bun run tests/test-m2-adversarial-interactive.js && bun run tests/test-web-preview.js && bun run tests/test-preview-sw.js",
76
+ "test:all": "bun run tools/bundle.js && bun run tests/test-all-builds.js && bun run tests/test-runtime-advanced.js && bun run tests/test-option1-shell-bun-http.js && bun run tests/test-frameworks.js && bun run tests/test-esm-exports.js && bun run tests/test-installer-integrity.js && bun run tests/test-coreutils-adversarial.js && bun run tests/test-stress-shell.js && bun run tests/test-workbench-ui.js && bun run tests/test-terminal-streaming.js && bun run tests/test-git-clone-streaming.js && bun run tests/test-m1-adversarial-challenger.js && bun run tests/test-m1-interruption-lifecycle-stress.js && bun run tests/test-gfm-markdown.js && bun run tests/test-m2-adversarial-syntax.js && bun run tests/test-m2-adversarial-interactive.js && bun run tests/test-web-preview.js && bun run tests/test-preview-sw.js",
76
77
  "pack:check": "bun pm pack --dry-run"
77
78
  },
78
79
  "dependencies": {