@innovatorved/code-lab 0.1.7 → 0.1.9

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.ts CHANGED
@@ -45,12 +45,23 @@
45
45
  })(typeof globalThis !== 'undefined' ? globalThis : this, function (root) {
46
46
  'use strict';
47
47
 
48
+ const _shellLogger = (root && root.CodeLabLogger && typeof root.CodeLabLogger.createLogger === 'function')
49
+ ? root.CodeLabLogger.createLogger()
50
+ : {
51
+ debug() {},
52
+ info(...args) { if (typeof console !== 'undefined' && console.info) console.info('[code-lab]', ...args); },
53
+ warn(...args) { if (typeof console !== 'undefined' && console.warn) console.warn('[code-lab]', ...args); },
54
+ error(...args) { if (typeof console !== 'undefined' && console.error) console.error('[code-lab]', ...args); }
55
+ };
56
+
48
57
  function getRuntimeModule() {
49
58
  if (typeof root !== 'undefined' && root && root.CodeLabRuntime) return root.CodeLabRuntime;
50
59
  if (typeof globalThis !== 'undefined' && globalThis.CodeLabRuntime) return globalThis.CodeLabRuntime;
51
60
  try {
52
61
  if (typeof require !== 'undefined') return require('./runtime.js');
53
- } catch (_) {}
62
+ } catch (err) {
63
+ _shellLogger.debug('Optional ./runtime.js require skipped in shell.', err);
64
+ }
54
65
  return null;
55
66
  }
56
67
 
@@ -642,7 +653,9 @@
642
653
  if (typeof vfs.statSync === 'function') {
643
654
  isDir = vfs.statSync(full).isDirectory();
644
655
  }
645
- } catch (_) {}
656
+ } catch (err) {
657
+ _shellLogger.debug('Glob statSync failed.', full, err);
658
+ }
646
659
 
647
660
  if (isDir) {
648
661
  traverse(full, rel);
@@ -1964,7 +1977,9 @@
1964
1977
  : name;
1965
1978
  try {
1966
1979
  snap[rel] = String(vfs.readFileSync(full, 'utf8'));
1967
- } catch (_) {}
1980
+ } catch (err) {
1981
+ _shellLogger.debug('Skipped unreadable VFS file in snapshot.', full, err);
1982
+ }
1968
1983
  }
1969
1984
  }
1970
1985
  }
@@ -2068,8 +2083,9 @@
2068
2083
  }
2069
2084
  }
2070
2085
  }
2071
- } catch (_) {
2086
+ } catch (err) {
2072
2087
  // Network or rate limit error on api.github.com; proceed to Strategy B
2088
+ _shellLogger.debug('GitHub REST API tree fetch failed; falling back to jsDelivr.', err);
2073
2089
  }
2074
2090
 
2075
2091
  // Strategy B: jsDelivr Data API (Zero rate limits, fast global edge cache)
@@ -2096,7 +2112,9 @@
2096
2112
  }
2097
2113
  }
2098
2114
  }
2099
- } catch (_) {}
2115
+ } catch (err) {
2116
+ _shellLogger.debug('jsDelivr flat tree fetch failed.', err);
2117
+ }
2100
2118
  }
2101
2119
 
2102
2120
  if (repoNotFound || !rawTreeEntries) {
@@ -2244,7 +2262,9 @@
2244
2262
  }));
2245
2263
  }
2246
2264
  }
2247
- } catch (_) {}
2265
+ } catch (err) {
2266
+ _shellLogger.debug('Optional commit history fetch skipped.', err);
2267
+ }
2248
2268
 
2249
2269
  if (commits.length === 0) {
2250
2270
  commits = [
@@ -2310,7 +2330,9 @@
2310
2330
  try {
2311
2331
  const parsed = JSON.parse(vfs.readFileSync(p, 'utf8'));
2312
2332
  return { path: p, data: parsed };
2313
- } catch (_) {}
2333
+ } catch (err) {
2334
+ _shellLogger.warn(`Invalid JSON in ${p}; falling back to default package metadata.`, err);
2335
+ }
2314
2336
  }
2315
2337
  return { path: p, data: { name: 'app', dependencies: {}, devDependencies: {}, scripts: {} } };
2316
2338
  }
@@ -2351,13 +2373,20 @@
2351
2373
  vfs.rmdirSync(dirPath);
2352
2374
  }
2353
2375
  if (typeof emitMutation === 'function') emitMutation('delete', dirPath);
2354
- } catch (_) {}
2376
+ } catch (err) {
2377
+ _shellLogger.debug('removeDirRecursive failed.', dirPath, err);
2378
+ }
2355
2379
  }
2356
2380
 
2357
2381
  // ---------------------------------------------------------------------------
2358
2382
  // Real npm package installation via the jsDelivr CDN
2359
2383
  // ---------------------------------------------------------------------------
2360
2384
  const CDN_NPM_BASE = 'https://cdn.jsdelivr.net/npm';
2385
+ const CDN_NPM_BASES = [
2386
+ 'https://cdn.jsdelivr.net/npm',
2387
+ 'https://unpkg.com',
2388
+ 'https://esm.sh'
2389
+ ];
2361
2390
 
2362
2391
  // Minimal offline registry, used only when the CDN is unreachable so common
2363
2392
  // demos still resolve without network access.
@@ -2503,16 +2532,23 @@
2503
2532
  }
2504
2533
 
2505
2534
  async function resolvePackageMetadata(fetchImpl, name, range) {
2506
- const urls = range
2507
- ? [`${CDN_NPM_BASE}/${name}@${range}/package.json`, `${CDN_NPM_BASE}/${name}/package.json`]
2508
- : [`${CDN_NPM_BASE}/${name}/package.json`];
2509
- for (const url of urls) {
2510
- const text = await fetchTextFromCdn(fetchImpl, url);
2511
- if (!text) continue;
2512
- try {
2513
- const parsed = JSON.parse(text);
2514
- if (parsed && parsed.version) return parsed;
2515
- } catch (_) {}
2535
+ for (const base of CDN_NPM_BASES) {
2536
+ const urls = range
2537
+ ? [`${base}/${name}@${range}/package.json`, `${base}/${name}/package.json`]
2538
+ : [`${base}/${name}/package.json`];
2539
+ for (const url of urls) {
2540
+ const text = await fetchTextFromCdn(fetchImpl, url);
2541
+ if (!text) continue;
2542
+ try {
2543
+ const parsed = JSON.parse(text);
2544
+ if (parsed && parsed.version) {
2545
+ parsed._resolvedCdnBase = base;
2546
+ return parsed;
2547
+ }
2548
+ } catch (err) {
2549
+ _shellLogger.debug('Invalid package.json metadata from CDN.', url, err);
2550
+ }
2551
+ }
2516
2552
  }
2517
2553
  return null;
2518
2554
  }
@@ -2530,6 +2566,7 @@
2530
2566
  return { ok: false, reason: `${name}: package metadata not found on the registry (offline?)` };
2531
2567
  }
2532
2568
 
2569
+ const activeCdnBase = meta._resolvedCdnBase || CDN_NPM_BASE;
2533
2570
  const version = meta.version;
2534
2571
  const key = `${name}@${version}`;
2535
2572
  if (seen.has(key)) {
@@ -2577,7 +2614,7 @@
2577
2614
  frontier = [];
2578
2615
  if (batch.length === 0) break;
2579
2616
  const texts = await Promise.all(
2580
- batch.map((rel) => fetchTextFromCdn(fetchImpl, `${CDN_NPM_BASE}/${name}@${version}/${rel}`))
2617
+ batch.map((rel) => fetchTextFromCdn(fetchImpl, `${activeCdnBase}/${name}@${version}/${rel}`))
2581
2618
  );
2582
2619
  for (let idx = 0; idx < batch.length; idx++) {
2583
2620
  const rel = batch[idx];
@@ -2601,7 +2638,7 @@
2601
2638
  }
2602
2639
  // The declared entry may be missing on the CDN; fall back to index.js.
2603
2640
  if (!files.some(f => f.rel === entry)) {
2604
- const idxText = await fetchTextFromCdn(fetchImpl, `${CDN_NPM_BASE}/${name}@${version}/index.js`);
2641
+ const idxText = await fetchTextFromCdn(fetchImpl, `${activeCdnBase}/${name}@${version}/index.js`);
2605
2642
  if (idxText !== null) files.push({ rel: 'index.js', content: idxText });
2606
2643
  }
2607
2644
 
@@ -2648,7 +2685,9 @@
2648
2685
  // directory target would otherwise raise EISDIR).
2649
2686
  try {
2650
2687
  if (ctx.vfs.existsSync(full) && ctx.vfs.statSync(full).isDirectory()) continue;
2651
- } catch (_) {}
2688
+ } catch (err) {
2689
+ _shellLogger.debug('Package install statSync check skipped.', full, err);
2690
+ }
2652
2691
  ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
2653
2692
  ctx.vfs.writeFileSync(full, f.content);
2654
2693
  if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
@@ -2726,6 +2765,32 @@
2726
2765
  pkgData[depField][pkgName] = range || (directVersion ? `^${directVersion}` : (pkgData[depField][pkgName] || 'latest'));
2727
2766
  writePackageJson(ctx.vfs, pkgPath, pkgData, ctx.emitMutation);
2728
2767
 
2768
+ // Also maintain package-lock.json in the same directory for deterministic lockfile verification
2769
+ try {
2770
+ const lockPath = PosixPath.join(PosixPath.dirname(pkgPath), 'package-lock.json');
2771
+ let lockData = { name: pkgData.name || 'workspace', version: pkgData.version || '1.0.0', lockfileVersion: 3, packages: {} };
2772
+ if (ctx.vfs.existsSync(lockPath)) {
2773
+ const rawLock = String(ctx.vfs.readFileSync(lockPath, 'utf8') || '');
2774
+ const parsedLock = JSON.parse(rawLock);
2775
+ if (parsedLock && typeof parsedLock === 'object') {
2776
+ lockData = parsedLock;
2777
+ if (!lockData.packages || typeof lockData.packages !== 'object') lockData.packages = {};
2778
+ }
2779
+ }
2780
+ for (const inst of installed) {
2781
+ if (inst && inst.name) {
2782
+ lockData.packages[`node_modules/${inst.name}`] = {
2783
+ version: inst.version || '1.0.0',
2784
+ resolved: `${CDN_NPM_BASE}/${inst.name}@${inst.version || '1.0.0'}`
2785
+ };
2786
+ }
2787
+ }
2788
+ ctx.vfs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n');
2789
+ if (typeof ctx.emitMutation === 'function') ctx.emitMutation('modify', lockPath);
2790
+ } catch (err) {
2791
+ _shellLogger.debug('Could not write package-lock.json during installPackage.', err);
2792
+ }
2793
+
2729
2794
  return { name: pkgName, ok: true, version: directVersion, installed, warning };
2730
2795
  }
2731
2796
 
@@ -2923,7 +2988,9 @@
2923
2988
  const parsed = JSON.parse(vfs.readFileSync(modPkg, 'utf8'));
2924
2989
  if (parsed && parsed.version) return parsed.version;
2925
2990
  }
2926
- } catch (_) {}
2991
+ } catch (err) {
2992
+ _shellLogger.debug('Could not read installed module package.json.', pkgName, err);
2993
+ }
2927
2994
  try {
2928
2995
  for (const dir of [rootDir, '/workspace']) {
2929
2996
  const pkgPath = PosixPath.join(dir, 'package.json');
@@ -2932,7 +2999,9 @@
2932
2999
  const deps = Object.assign({}, parsed.dependencies || {}, parsed.devDependencies || {}, parsed.peerDependencies || {});
2933
3000
  if (deps[pkgName]) return normalizeVersionRange(deps[pkgName]);
2934
3001
  }
2935
- } catch (_) {}
3002
+ } catch (err) {
3003
+ _shellLogger.debug('Could not read workspace package.json for version resolution.', pkgName, err);
3004
+ }
2936
3005
  return 'latest';
2937
3006
  }
2938
3007
 
@@ -2955,10 +3024,10 @@
2955
3024
  return imports;
2956
3025
  }
2957
3026
 
2958
- function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
2959
- const scripts = [];
3027
+ function collectPreviewScriptFiles(vfs, rootDir, maxFiles = 200) {
3028
+ const files = [];
2960
3029
  const walk = (dir, depth) => {
2961
- if (depth > 8 || scripts.length >= maxFiles) return;
3030
+ if (depth > 8 || files.length >= maxFiles) return;
2962
3031
  let entries = [];
2963
3032
  try { entries = vfs.readdirSync(dir); } catch (_) { return; }
2964
3033
  for (const name of entries) {
@@ -2969,13 +3038,23 @@
2969
3038
  const dirFlag = st && (typeof st.isDirectory === 'function' ? st.isDirectory() : st.isDirectory);
2970
3039
  if (dirFlag) {
2971
3040
  walk(full, depth + 1);
2972
- } else if (isPreviewScriptPath(name) && scripts.length < maxFiles) {
2973
- try { scripts.push(vfs.readFileSync(full, 'utf8')); } catch (_) {}
3041
+ } else if (isPreviewScriptPath(name) && files.length < maxFiles) {
3042
+ try {
3043
+ const content = vfs.readFileSync(full, 'utf8');
3044
+ const rel = full.startsWith(rootDir + '/') ? full.slice(rootDir.length + 1) : name;
3045
+ files.push({ full, rel, content });
3046
+ } catch (err) {
3047
+ _shellLogger.debug('Preview script read skipped.', full, err);
3048
+ }
2974
3049
  }
2975
3050
  }
2976
3051
  };
2977
3052
  walk(rootDir, 0);
2978
- return scripts;
3053
+ return files;
3054
+ }
3055
+
3056
+ function collectPreviewScripts(vfs, rootDir, maxFiles = 200) {
3057
+ return collectPreviewScriptFiles(vfs, rootDir, maxFiles).map((f) => f.content);
2979
3058
  }
2980
3059
 
2981
3060
  function injectPreviewExtras(html, importMap) {
@@ -3000,12 +3079,6 @@
3000
3079
  const taken = new Set((typeof portTable.listServers === 'function' ? portTable.listServers() : []).map((s) => Number(s.port)));
3001
3080
  while (taken.has(port)) port++;
3002
3081
 
3003
- const specifiers = new Set();
3004
- for (const content of collectPreviewScripts(ctx.vfs, rootDir)) {
3005
- for (const s of extractBareSpecifiers(content)) specifiers.add(s);
3006
- }
3007
- const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
3008
-
3009
3082
  const exists = (p) => { try { return ctx.vfs.existsSync(p); } catch (_) { return false; } };
3010
3083
  const isDir = (p) => {
3011
3084
  try {
@@ -3013,11 +3086,112 @@
3013
3086
  return Boolean(st && (typeof st.isDirectory === 'function' ? st.isDirectory() : st.isDirectory));
3014
3087
  } catch (_) { return false; }
3015
3088
  };
3089
+ const isFile = (p) => exists(p) && !isDir(p);
3016
3090
  const readText = (p) => { try { return ctx.vfs.readFileSync(p, 'utf8'); } catch (_) { return null; } };
3017
3091
 
3092
+ const resolveLocalTarget = (baseDir, rawSpec) => {
3093
+ if (!rawSpec || typeof rawSpec !== 'string') return null;
3094
+ const clean = rawSpec.split(/[?#]/)[0].trim();
3095
+ if (!clean || /^(?:https?:|data:|blob:|\/\/)/i.test(clean)) return null;
3096
+ const candidateBase = clean.startsWith('/')
3097
+ ? PosixPath.join(rootDir, clean.replace(/^\/+/, ''))
3098
+ : PosixPath.join(baseDir, clean);
3099
+ if (isFile(candidateBase)) return candidateBase;
3100
+ const cands = [
3101
+ candidateBase + '.tsx', candidateBase + '.ts', candidateBase + '.jsx', candidateBase + '.js',
3102
+ candidateBase + '.mjs', candidateBase + '.cjs',
3103
+ PosixPath.join(candidateBase, 'index.tsx'), PosixPath.join(candidateBase, 'index.ts'),
3104
+ PosixPath.join(candidateBase, 'index.jsx'), PosixPath.join(candidateBase, 'index.js')
3105
+ ];
3106
+ for (const c of cands) {
3107
+ if (isFile(c)) return c;
3108
+ }
3109
+ return null;
3110
+ };
3111
+
3112
+ const toLocalImportKey = (fullPath) => {
3113
+ const rel = fullPath.startsWith(rootDir + '/') ? fullPath.slice(rootDir.length + 1) : fullPath.replace(/^\/+/, '');
3114
+ return `@codelab-local/${rel}`;
3115
+ };
3116
+
3117
+ const transpileAndRewriteLocalImports = (code, sourcePath) => {
3118
+ let out = code;
3119
+ try {
3120
+ const rm = getRuntimeModule();
3121
+ if (rm && typeof rm.transpileForBrowser === 'function') {
3122
+ out = rm.transpileForBrowser(out, sourcePath);
3123
+ }
3124
+ } catch (err) {
3125
+ _shellLogger.warn(`Preview script transpilation failed for ${sourcePath}.`, err);
3126
+ }
3127
+ const fromDir = PosixPath.dirname(sourcePath);
3128
+ const rewriteSpec = (spec) => {
3129
+ if (!spec || (!spec.startsWith('.') && !spec.startsWith('/'))) return spec;
3130
+ const resolved = resolveLocalTarget(fromDir, spec);
3131
+ return resolved ? toLocalImportKey(resolved) : spec;
3132
+ };
3133
+ out = out.replace(/(\b(?:from|import)\s*['"])(\.{1,2}\/[^'"]+|\/[^'"]+)(['"])/g, (_, pre, spec, post) => `${pre}${rewriteSpec(spec)}${post}`);
3134
+ out = out.replace(/(\bimport\s*\(\s*['"])(\.{1,2}\/[^'"]+|\/[^'"]+)(['"]\s*\))/g, (_, pre, spec, post) => `${pre}${rewriteSpec(spec)}${post}`);
3135
+ return out;
3136
+ };
3137
+
3138
+ const buildHtmlPreviewResponse = (htmlBody, htmlTargetPath) => {
3139
+ const scriptFiles = collectPreviewScriptFiles(ctx.vfs, rootDir);
3140
+ const specifiers = new Set();
3141
+ for (const f of scriptFiles) {
3142
+ for (const s of extractBareSpecifiers(f.content)) specifiers.add(s);
3143
+ }
3144
+ // Also scan inline module scripts in HTML for bare specifiers
3145
+ const inlineScriptRe = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
3146
+ let inlineMatch;
3147
+ while ((inlineMatch = inlineScriptRe.exec(htmlBody)) !== null) {
3148
+ if (inlineMatch[1]) {
3149
+ for (const s of extractBareSpecifiers(inlineMatch[1])) specifiers.add(s);
3150
+ }
3151
+ }
3152
+
3153
+ const importMap = buildPreviewImportMap(ctx.vfs, rootDir, specifiers);
3154
+ for (const f of scriptFiles) {
3155
+ const compiled = transpileAndRewriteLocalImports(f.content, f.full);
3156
+ const key = toLocalImportKey(f.full);
3157
+ importMap[key] = `data:text/javascript;charset=utf-8,${encodeURIComponent(compiled)}`;
3158
+ }
3159
+
3160
+ const htmlDir = PosixPath.dirname(htmlTargetPath);
3161
+ let transformedHtml = htmlBody;
3162
+
3163
+ // Inline local <link rel="stylesheet" href="..."> so styles work in opaque-origin / srcdoc frames
3164
+ transformedHtml = transformedHtml.replace(/<link\b([^>]*?)>/gi, (fullTag, attrs) => {
3165
+ if (!/\brel\s*=\s*["']stylesheet["']/i.test(attrs)) return fullTag;
3166
+ const hrefMatch = /\bhref\s*=\s*["']([^"']+)["']/i.exec(attrs);
3167
+ if (!hrefMatch) return fullTag;
3168
+ const cssTarget = resolveLocalTarget(htmlDir, hrefMatch[1]);
3169
+ if (!cssTarget || !/\.css$/i.test(cssTarget)) return fullTag;
3170
+ const cssContent = readText(cssTarget);
3171
+ if (cssContent === null) return fullTag;
3172
+ return `<style data-codelab-href="${hrefMatch[1].replace(/"/g, '&quot;')}">\n${cssContent}\n</style>`;
3173
+ });
3174
+
3175
+ // Inline local <script ... src="..."></script> so entry modules & scripts execute reliably in opaque-origin / srcdoc frames
3176
+ transformedHtml = transformedHtml.replace(/<script\b([^>]*?)>\s*<\/script>/gi, (fullTag, attrs) => {
3177
+ const srcMatch = /\bsrc\s*=\s*["']([^"']+)["']/i.exec(attrs);
3178
+ if (!srcMatch) return fullTag;
3179
+ const scriptTarget = resolveLocalTarget(htmlDir, srcMatch[1]);
3180
+ if (!scriptTarget || !isPreviewScriptPath(scriptTarget)) return fullTag;
3181
+ const rawScript = readText(scriptTarget);
3182
+ if (rawScript === null) return fullTag;
3183
+ const compiled = transpileAndRewriteLocalImports(rawScript, scriptTarget);
3184
+ const isMod = /\btype\s*=\s*["']module["']/i.test(attrs) || /\.(?:tsx|ts|jsx|mjs)$/i.test(scriptTarget);
3185
+ const typeAttr = isMod ? ' type="module"' : '';
3186
+ return `<script${typeAttr} data-codelab-src="${srcMatch[1].replace(/"/g, '&quot;')}">\n${compiled}\n</script>`;
3187
+ });
3188
+
3189
+ return injectPreviewExtras(transformedHtml, importMap);
3190
+ };
3191
+
3018
3192
  const handler = async (request) => {
3019
3193
  let pathname = '/';
3020
- try { pathname = decodeURIComponent(new URL(request.url).pathname); } catch (_) {}
3194
+ try { pathname = decodeURIComponent(new URL(request.url).pathname); } catch (err) { _shellLogger.debug('Preview URL decode failed.', err); }
3021
3195
  const rel = pathname.replace(/^\/+/, '');
3022
3196
  let target = PosixPath.join(rootDir, rel);
3023
3197
  const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
@@ -3049,14 +3223,16 @@
3049
3223
  let body = readText(target);
3050
3224
  if (body === null) body = '';
3051
3225
  if (/\.html?$/i.test(target)) {
3052
- body = injectPreviewExtras(body, importMap);
3226
+ body = buildHtmlPreviewResponse(body, target);
3053
3227
  } else if (isPreviewScriptPath(target)) {
3054
3228
  try {
3055
3229
  const rm = getRuntimeModule();
3056
3230
  if (rm && typeof rm.transpileForBrowser === 'function') {
3057
3231
  body = rm.transpileForBrowser(body, target);
3058
3232
  }
3059
- } catch (_) {}
3233
+ } catch (err) {
3234
+ _shellLogger.warn(`Preview script transpilation failed for ${target}.`, err);
3235
+ }
3060
3236
  }
3061
3237
 
3062
3238
  return new Response(body, { status: 200, headers: { 'content-type': previewMimeFor(target) } });
@@ -3064,7 +3240,7 @@
3064
3240
 
3065
3241
  const pid = (ctx.shell && typeof ctx.shell.nextPid === 'number') ? ctx.shell.nextPid++ : (ctx.pid || 1000);
3066
3242
  return portTable.registerServer(port, {
3067
- server: { close() { try { portTable.unregisterServer(port); } catch (_) {} } },
3243
+ server: { close() { try { portTable.unregisterServer(port); } catch (err) { _shellLogger.debug('Preview server unregister failed.', port, err); } } },
3068
3244
  fetch: handler,
3069
3245
  name: 'code-lab-serve',
3070
3246
  pid,
@@ -3177,7 +3353,9 @@
3177
3353
  let isDir = false;
3178
3354
  try {
3179
3355
  isDir = ctx.vfs.statSync(resolved).isDirectory();
3180
- } catch (_) {}
3356
+ } catch (err) {
3357
+ _shellLogger.debug('cd statSync failed.', resolved, err);
3358
+ }
3181
3359
 
3182
3360
  if (!isDir) {
3183
3361
  return { code: 1, stdout: '', stderr: `cd: ${target}: Not a directory\n` };
@@ -3277,7 +3455,9 @@
3277
3455
  isDirectory = st.isDirectory();
3278
3456
  size = st.size;
3279
3457
  mtimeMs = st.mtimeMs || Date.now();
3280
- } catch (_) {}
3458
+ } catch (err) {
3459
+ _shellLogger.debug('ls statSync skipped.', itemPath, err);
3460
+ }
3281
3461
  return { name, isDirectory, size, mtimeMs, absPath: itemPath };
3282
3462
  });
3283
3463
 
@@ -3697,7 +3877,9 @@
3697
3877
  if (st.isDirectory()) walk(full);
3698
3878
  else targets.push(full);
3699
3879
  }
3700
- } catch (_) {}
3880
+ } catch (err) {
3881
+ _shellLogger.debug('grep directory walk skipped.', dir, err);
3882
+ }
3701
3883
  }
3702
3884
  if (ctx.vfs.existsSync(absRoot)) {
3703
3885
  const st = ctx.vfs.statSync(absRoot);
@@ -3821,7 +4003,9 @@
3821
4003
  let isDir = false;
3822
4004
  try {
3823
4005
  isDir = ctx.vfs.statSync(full).isDirectory();
3824
- } catch (_) {}
4006
+ } catch (err) {
4007
+ _shellLogger.debug('find statSync skipped.', full, err);
4008
+ }
3825
4009
 
3826
4010
  const relPath = root === '.'
3827
4011
  ? './' + full.replace(absRoot.endsWith('/') ? absRoot : absRoot + '/', '')
@@ -3840,7 +4024,7 @@
3840
4024
  // Root itself check
3841
4025
  if (ctx.vfs.existsSync(absRoot)) {
3842
4026
  let isDir = false;
3843
- try { isDir = ctx.vfs.statSync(absRoot).isDirectory(); } catch (_) {}
4027
+ try { isDir = ctx.vfs.statSync(absRoot).isDirectory(); } catch (err) { _shellLogger.debug('find root statSync skipped.', absRoot, err); }
3844
4028
  if (!typeFilter || (typeFilter === 'd' && isDir) || (typeFilter === 'f' && !isDir)) {
3845
4029
  if (!nameRegex || nameRegex.test(PosixPath.basename(root))) {
3846
4030
  results.push(root);
@@ -4752,7 +4936,7 @@
4752
4936
  const isLast = i === entries.length - 1;
4753
4937
  const full = dirPath === '/' ? '/' + entry : dirPath + '/' + entry;
4754
4938
  let isDir = false;
4755
- try { isDir = ctx.vfs.statSync(full).isDirectory(); } catch (_) {}
4939
+ try { isDir = ctx.vfs.statSync(full).isDirectory(); } catch (err) { _shellLogger.debug('tree statSync skipped.', full, err); }
4756
4940
 
4757
4941
  stdout += `${prefix}${isLast ? '└── ' : '├── '}${entry}\n`;
4758
4942
 
@@ -4980,10 +5164,10 @@
4980
5164
  for (const s of ctx.shell.portTable.listServers()) {
4981
5165
  if (s.pid !== undefined && String(s.pid) === String(pid)) {
4982
5166
  if (s.server && typeof s.server.close === 'function') {
4983
- try { s.server.close(); } catch (_) {}
5167
+ try { s.server.close(); } catch (err) { _shellLogger.debug('kill server.close failed.', err); }
4984
5168
  }
4985
5169
  if (typeof s.stop === 'function') {
4986
- try { s.stop(); } catch (_) {}
5170
+ try { s.stop(); } catch (err) { _shellLogger.debug('kill server.stop failed.', err); }
4987
5171
  }
4988
5172
  ctx.shell.portTable.unregisterServer(s.port);
4989
5173
  killedPort = true;