@innovatorved/code-lab 0.1.6 → 0.1.8
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/ARCHITECTURE.md +34 -16
- package/README.md +17 -7
- package/dist/code-lab.css +26 -0
- package/dist/code-lab.d.ts +271 -1
- package/dist/code-lab.esm.js +2909 -166
- package/dist/code-lab.js +2869 -164
- package/dist/csp.d.ts +86 -0
- package/dist/diagnostics.d.ts +43 -0
- package/dist/extensions/guided-lab.esm.js +66 -0
- package/dist/extensions/guided-lab.js +66 -0
- package/dist/html.d.ts +24 -0
- package/dist/index.d.ts +9 -1
- package/dist/logger.d.ts +60 -0
- package/dist/preview-sw.js +425 -11
- package/dist/runtime.d.ts +6 -27
- package/dist/runtime.esm.js +171 -31
- package/dist/runtime.js +171 -31
- package/dist/schemas.d.ts +366 -25
- package/dist/schemas.esm.js +73 -0
- package/dist/schemas.js +73 -0
- package/dist/scm.d.ts +77 -0
- package/dist/search.d.ts +75 -0
- package/dist/shell.d.ts +18 -47
- package/dist/shell.esm.js +236 -37
- package/dist/shell.js +236 -37
- package/dist/storage.d.ts +57 -0
- package/dist/terminal.d.ts +11 -87
- package/dist/terminal.esm.js +124 -7
- package/dist/terminal.js +124 -7
- package/dist/zip.d.ts +42 -0
- package/package.json +11 -3
- package/src/code-lab.css +26 -0
- package/src/csp.ts +396 -0
- package/src/diagnostics.ts +116 -0
- package/src/html.ts +88 -0
- package/src/index.ts +39 -1
- package/src/logger.ts +139 -0
- package/src/preview-sw.js +97 -11
- package/src/runtime.ts +132 -105
- package/src/schemas.ts +94 -1
- package/src/scm.ts +268 -0
- package/src/search.ts +389 -0
- package/src/shell.ts +410 -369
- package/src/storage.ts +377 -0
- package/src/terminal.ts +898 -918
- package/src/workbench.ts +926 -89
- package/src/zip.ts +326 -0
- package/src/runtime.js +0 -8229
- package/src/shell.js +0 -7257
- package/src/terminal.js +0 -1046
- package/src/workbench.js +0 -7353
package/dist/shell.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab
|
|
3
|
+
* @innovatorved/code-lab v0.1.8 — Standalone Browser Code IDE & Virtual Runtime
|
|
4
4
|
* ============================================================
|
|
5
5
|
* Features:
|
|
6
6
|
* - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
|
|
@@ -15,7 +15,109 @@
|
|
|
15
15
|
* ============================================================
|
|
16
16
|
*/
|
|
17
17
|
const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : {};
|
|
18
|
+
var CodeLabLogger = (() => {
|
|
19
|
+
var __defProp = Object.defineProperty;
|
|
20
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
21
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
22
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// src/logger.ts
|
|
38
|
+
var logger_exports = {};
|
|
39
|
+
__export(logger_exports, {
|
|
40
|
+
CodeLabError: () => CodeLabError,
|
|
41
|
+
DEFAULT_LOGGER: () => DEFAULT_LOGGER,
|
|
42
|
+
LOG_PREFIX: () => LOG_PREFIX,
|
|
43
|
+
createLogger: () => createLogger,
|
|
44
|
+
default: () => logger_default,
|
|
45
|
+
isCodeLabError: () => isCodeLabError
|
|
46
|
+
});
|
|
47
|
+
var LOG_PREFIX = "[code-lab]";
|
|
48
|
+
var CodeLabError = class extends Error {
|
|
49
|
+
code;
|
|
50
|
+
options;
|
|
51
|
+
cause;
|
|
52
|
+
recoverable;
|
|
53
|
+
details;
|
|
54
|
+
context;
|
|
55
|
+
constructor(code, message, options = {}) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = "CodeLabError";
|
|
58
|
+
this.code = code;
|
|
59
|
+
this.options = options;
|
|
60
|
+
this.cause = options.cause;
|
|
61
|
+
this.recoverable = options.recoverable !== false;
|
|
62
|
+
const meta = options.details ?? options.context;
|
|
63
|
+
if (meta !== void 0) {
|
|
64
|
+
this.details = meta;
|
|
65
|
+
this.context = meta;
|
|
66
|
+
}
|
|
67
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function isCodeLabError(value) {
|
|
71
|
+
return Boolean(
|
|
72
|
+
value && typeof value === "object" && (value instanceof CodeLabError || value.name === "CodeLabError" && typeof value.code === "string")
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
function createLogger(options = {}) {
|
|
76
|
+
const sink = options.logger ?? null;
|
|
77
|
+
const debugEnabled = options.debug === true;
|
|
78
|
+
const prefix = options.prefix || LOG_PREFIX;
|
|
79
|
+
const write = (level, args) => {
|
|
80
|
+
if (level === "debug" && !debugEnabled) return;
|
|
81
|
+
if (sink && typeof sink[level] === "function") {
|
|
82
|
+
let sinkError = null;
|
|
83
|
+
try {
|
|
84
|
+
sink[level](...args);
|
|
85
|
+
return;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
sinkError = err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const consoleObj = typeof console !== "undefined" ? console : null;
|
|
91
|
+
const fn = consoleObj ? consoleObj[level] : null;
|
|
92
|
+
if (typeof fn === "function") {
|
|
93
|
+
fn.call(consoleObj, prefix, ...args);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
debug: (...args) => write("debug", args),
|
|
98
|
+
info: (...args) => write("info", args),
|
|
99
|
+
warn: (...args) => write("warn", args),
|
|
100
|
+
error: (...args) => write("error", args)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var DEFAULT_LOGGER = createLogger();
|
|
104
|
+
var _loggerNamespace = {
|
|
105
|
+
LOG_PREFIX,
|
|
106
|
+
CodeLabError,
|
|
107
|
+
isCodeLabError,
|
|
108
|
+
createLogger,
|
|
109
|
+
DEFAULT_LOGGER
|
|
110
|
+
};
|
|
111
|
+
var _globalRoot = typeof globalThis !== "undefined" ? globalThis : null;
|
|
112
|
+
if (_globalRoot && !_globalRoot.CodeLabLogger) {
|
|
113
|
+
_globalRoot.CodeLabLogger = _loggerNamespace;
|
|
114
|
+
}
|
|
115
|
+
var logger_default = _loggerNamespace;
|
|
116
|
+
return __toCommonJS(logger_exports);
|
|
117
|
+
})();
|
|
118
|
+
|
|
18
119
|
(function () {
|
|
120
|
+
// @ts-nocheck
|
|
19
121
|
/**
|
|
20
122
|
* @innovatorved/code-lab - POSIX Shell Engine & UNIX Coreutils
|
|
21
123
|
*
|
|
@@ -62,12 +164,23 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
62
164
|
})(typeof globalThis !== 'undefined' ? globalThis : this, function (root) {
|
|
63
165
|
'use strict';
|
|
64
166
|
|
|
167
|
+
const _shellLogger = (root && root.CodeLabLogger && typeof root.CodeLabLogger.createLogger === 'function')
|
|
168
|
+
? root.CodeLabLogger.createLogger()
|
|
169
|
+
: {
|
|
170
|
+
debug() {},
|
|
171
|
+
info(...args) { if (typeof console !== 'undefined' && console.info) console.info('[code-lab]', ...args); },
|
|
172
|
+
warn(...args) { if (typeof console !== 'undefined' && console.warn) console.warn('[code-lab]', ...args); },
|
|
173
|
+
error(...args) { if (typeof console !== 'undefined' && console.error) console.error('[code-lab]', ...args); }
|
|
174
|
+
};
|
|
175
|
+
|
|
65
176
|
function getRuntimeModule() {
|
|
66
177
|
if (typeof root !== 'undefined' && root && root.CodeLabRuntime) return root.CodeLabRuntime;
|
|
67
178
|
if (typeof globalThis !== 'undefined' && globalThis.CodeLabRuntime) return globalThis.CodeLabRuntime;
|
|
68
179
|
try {
|
|
69
180
|
if (typeof require !== 'undefined') return require('./runtime.js');
|
|
70
|
-
} catch (
|
|
181
|
+
} catch (err) {
|
|
182
|
+
_shellLogger.debug('Optional ./runtime.js require skipped in shell.', err);
|
|
183
|
+
}
|
|
71
184
|
return null;
|
|
72
185
|
}
|
|
73
186
|
|
|
@@ -659,7 +772,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
659
772
|
if (typeof vfs.statSync === 'function') {
|
|
660
773
|
isDir = vfs.statSync(full).isDirectory();
|
|
661
774
|
}
|
|
662
|
-
} catch (
|
|
775
|
+
} catch (err) {
|
|
776
|
+
_shellLogger.debug('Glob statSync failed.', full, err);
|
|
777
|
+
}
|
|
663
778
|
|
|
664
779
|
if (isDir) {
|
|
665
780
|
traverse(full, rel);
|
|
@@ -1981,7 +2096,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
1981
2096
|
: name;
|
|
1982
2097
|
try {
|
|
1983
2098
|
snap[rel] = String(vfs.readFileSync(full, 'utf8'));
|
|
1984
|
-
} catch (
|
|
2099
|
+
} catch (err) {
|
|
2100
|
+
_shellLogger.debug('Skipped unreadable VFS file in snapshot.', full, err);
|
|
2101
|
+
}
|
|
1985
2102
|
}
|
|
1986
2103
|
}
|
|
1987
2104
|
}
|
|
@@ -2003,7 +2120,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2003
2120
|
return 10 + depth * 0.1;
|
|
2004
2121
|
}
|
|
2005
2122
|
|
|
2006
|
-
async function
|
|
2123
|
+
async function _cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
2007
2124
|
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
2008
2125
|
if (onProgress) {
|
|
2009
2126
|
onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
|
|
@@ -2085,8 +2202,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2085
2202
|
}
|
|
2086
2203
|
}
|
|
2087
2204
|
}
|
|
2088
|
-
} catch (
|
|
2205
|
+
} catch (err) {
|
|
2089
2206
|
// Network or rate limit error on api.github.com; proceed to Strategy B
|
|
2207
|
+
_shellLogger.debug('GitHub REST API tree fetch failed; falling back to jsDelivr.', err);
|
|
2090
2208
|
}
|
|
2091
2209
|
|
|
2092
2210
|
// Strategy B: jsDelivr Data API (Zero rate limits, fast global edge cache)
|
|
@@ -2113,7 +2231,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2113
2231
|
}
|
|
2114
2232
|
}
|
|
2115
2233
|
}
|
|
2116
|
-
} catch (
|
|
2234
|
+
} catch (err) {
|
|
2235
|
+
_shellLogger.debug('jsDelivr flat tree fetch failed.', err);
|
|
2236
|
+
}
|
|
2117
2237
|
}
|
|
2118
2238
|
|
|
2119
2239
|
if (repoNotFound || !rawTreeEntries) {
|
|
@@ -2261,7 +2381,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2261
2381
|
}));
|
|
2262
2382
|
}
|
|
2263
2383
|
}
|
|
2264
|
-
} catch (
|
|
2384
|
+
} catch (err) {
|
|
2385
|
+
_shellLogger.debug('Optional commit history fetch skipped.', err);
|
|
2386
|
+
}
|
|
2265
2387
|
|
|
2266
2388
|
if (commits.length === 0) {
|
|
2267
2389
|
commits = [
|
|
@@ -2293,6 +2415,23 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2293
2415
|
};
|
|
2294
2416
|
}
|
|
2295
2417
|
|
|
2418
|
+
// Public wrapper: guarantee an `error` progress event when the clone fails
|
|
2419
|
+
// for any reason (invalid URL, missing vfs, fetch rejection, abort, ...).
|
|
2420
|
+
async function cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
2421
|
+
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
2422
|
+
try {
|
|
2423
|
+
return await _cloneGitHubRepository(repoInput, vfs, options);
|
|
2424
|
+
} catch (err) {
|
|
2425
|
+
if (onProgress) {
|
|
2426
|
+
onProgress({
|
|
2427
|
+
phase: 'error',
|
|
2428
|
+
message: err && err.message ? err.message : String(err)
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
throw err;
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2296
2435
|
// =========================================================================
|
|
2297
2436
|
// Package Management Helpers (npm / bun virtual modules & scripts)
|
|
2298
2437
|
// =========================================================================
|
|
@@ -2310,7 +2449,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2310
2449
|
try {
|
|
2311
2450
|
const parsed = JSON.parse(vfs.readFileSync(p, 'utf8'));
|
|
2312
2451
|
return { path: p, data: parsed };
|
|
2313
|
-
} catch (
|
|
2452
|
+
} catch (err) {
|
|
2453
|
+
_shellLogger.warn(`Invalid JSON in ${p}; falling back to default package metadata.`, err);
|
|
2454
|
+
}
|
|
2314
2455
|
}
|
|
2315
2456
|
return { path: p, data: { name: 'app', dependencies: {}, devDependencies: {}, scripts: {} } };
|
|
2316
2457
|
}
|
|
@@ -2351,13 +2492,20 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2351
2492
|
vfs.rmdirSync(dirPath);
|
|
2352
2493
|
}
|
|
2353
2494
|
if (typeof emitMutation === 'function') emitMutation('delete', dirPath);
|
|
2354
|
-
} catch (
|
|
2495
|
+
} catch (err) {
|
|
2496
|
+
_shellLogger.debug('removeDirRecursive failed.', dirPath, err);
|
|
2497
|
+
}
|
|
2355
2498
|
}
|
|
2356
2499
|
|
|
2357
2500
|
// ---------------------------------------------------------------------------
|
|
2358
2501
|
// Real npm package installation via the jsDelivr CDN
|
|
2359
2502
|
// ---------------------------------------------------------------------------
|
|
2360
2503
|
const CDN_NPM_BASE = 'https://cdn.jsdelivr.net/npm';
|
|
2504
|
+
const CDN_NPM_BASES = [
|
|
2505
|
+
'https://cdn.jsdelivr.net/npm',
|
|
2506
|
+
'https://unpkg.com',
|
|
2507
|
+
'https://esm.sh'
|
|
2508
|
+
];
|
|
2361
2509
|
|
|
2362
2510
|
// Minimal offline registry, used only when the CDN is unreachable so common
|
|
2363
2511
|
// demos still resolve without network access.
|
|
@@ -2503,16 +2651,23 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2503
2651
|
}
|
|
2504
2652
|
|
|
2505
2653
|
async function resolvePackageMetadata(fetchImpl, name, range) {
|
|
2506
|
-
const
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
const
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2654
|
+
for (const base of CDN_NPM_BASES) {
|
|
2655
|
+
const urls = range
|
|
2656
|
+
? [`${base}/${name}@${range}/package.json`, `${base}/${name}/package.json`]
|
|
2657
|
+
: [`${base}/${name}/package.json`];
|
|
2658
|
+
for (const url of urls) {
|
|
2659
|
+
const text = await fetchTextFromCdn(fetchImpl, url);
|
|
2660
|
+
if (!text) continue;
|
|
2661
|
+
try {
|
|
2662
|
+
const parsed = JSON.parse(text);
|
|
2663
|
+
if (parsed && parsed.version) {
|
|
2664
|
+
parsed._resolvedCdnBase = base;
|
|
2665
|
+
return parsed;
|
|
2666
|
+
}
|
|
2667
|
+
} catch (err) {
|
|
2668
|
+
_shellLogger.debug('Invalid package.json metadata from CDN.', url, err);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2516
2671
|
}
|
|
2517
2672
|
return null;
|
|
2518
2673
|
}
|
|
@@ -2530,6 +2685,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2530
2685
|
return { ok: false, reason: `${name}: package metadata not found on the registry (offline?)` };
|
|
2531
2686
|
}
|
|
2532
2687
|
|
|
2688
|
+
const activeCdnBase = meta._resolvedCdnBase || CDN_NPM_BASE;
|
|
2533
2689
|
const version = meta.version;
|
|
2534
2690
|
const key = `${name}@${version}`;
|
|
2535
2691
|
if (seen.has(key)) {
|
|
@@ -2577,7 +2733,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2577
2733
|
frontier = [];
|
|
2578
2734
|
if (batch.length === 0) break;
|
|
2579
2735
|
const texts = await Promise.all(
|
|
2580
|
-
batch.map((rel) => fetchTextFromCdn(fetchImpl, `${
|
|
2736
|
+
batch.map((rel) => fetchTextFromCdn(fetchImpl, `${activeCdnBase}/${name}@${version}/${rel}`))
|
|
2581
2737
|
);
|
|
2582
2738
|
for (let idx = 0; idx < batch.length; idx++) {
|
|
2583
2739
|
const rel = batch[idx];
|
|
@@ -2601,7 +2757,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2601
2757
|
}
|
|
2602
2758
|
// The declared entry may be missing on the CDN; fall back to index.js.
|
|
2603
2759
|
if (!files.some(f => f.rel === entry)) {
|
|
2604
|
-
const idxText = await fetchTextFromCdn(fetchImpl, `${
|
|
2760
|
+
const idxText = await fetchTextFromCdn(fetchImpl, `${activeCdnBase}/${name}@${version}/index.js`);
|
|
2605
2761
|
if (idxText !== null) files.push({ rel: 'index.js', content: idxText });
|
|
2606
2762
|
}
|
|
2607
2763
|
|
|
@@ -2648,7 +2804,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2648
2804
|
// directory target would otherwise raise EISDIR).
|
|
2649
2805
|
try {
|
|
2650
2806
|
if (ctx.vfs.existsSync(full) && ctx.vfs.statSync(full).isDirectory()) continue;
|
|
2651
|
-
} catch (
|
|
2807
|
+
} catch (err) {
|
|
2808
|
+
_shellLogger.debug('Package install statSync check skipped.', full, err);
|
|
2809
|
+
}
|
|
2652
2810
|
ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
|
|
2653
2811
|
ctx.vfs.writeFileSync(full, f.content);
|
|
2654
2812
|
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
|
|
@@ -2726,6 +2884,32 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2726
2884
|
pkgData[depField][pkgName] = range || (directVersion ? `^${directVersion}` : (pkgData[depField][pkgName] || 'latest'));
|
|
2727
2885
|
writePackageJson(ctx.vfs, pkgPath, pkgData, ctx.emitMutation);
|
|
2728
2886
|
|
|
2887
|
+
// Also maintain package-lock.json in the same directory for deterministic lockfile verification
|
|
2888
|
+
try {
|
|
2889
|
+
const lockPath = PosixPath.join(PosixPath.dirname(pkgPath), 'package-lock.json');
|
|
2890
|
+
let lockData = { name: pkgData.name || 'workspace', version: pkgData.version || '1.0.0', lockfileVersion: 3, packages: {} };
|
|
2891
|
+
if (ctx.vfs.existsSync(lockPath)) {
|
|
2892
|
+
const rawLock = String(ctx.vfs.readFileSync(lockPath, 'utf8') || '');
|
|
2893
|
+
const parsedLock = JSON.parse(rawLock);
|
|
2894
|
+
if (parsedLock && typeof parsedLock === 'object') {
|
|
2895
|
+
lockData = parsedLock;
|
|
2896
|
+
if (!lockData.packages || typeof lockData.packages !== 'object') lockData.packages = {};
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
for (const inst of installed) {
|
|
2900
|
+
if (inst && inst.name) {
|
|
2901
|
+
lockData.packages[`node_modules/${inst.name}`] = {
|
|
2902
|
+
version: inst.version || '1.0.0',
|
|
2903
|
+
resolved: `${CDN_NPM_BASE}/${inst.name}@${inst.version || '1.0.0'}`
|
|
2904
|
+
};
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
ctx.vfs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n');
|
|
2908
|
+
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('modify', lockPath);
|
|
2909
|
+
} catch (err) {
|
|
2910
|
+
_shellLogger.debug('Could not write package-lock.json during installPackage.', err);
|
|
2911
|
+
}
|
|
2912
|
+
|
|
2729
2913
|
return { name: pkgName, ok: true, version: directVersion, installed, warning };
|
|
2730
2914
|
}
|
|
2731
2915
|
|
|
@@ -2923,7 +3107,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2923
3107
|
const parsed = JSON.parse(vfs.readFileSync(modPkg, 'utf8'));
|
|
2924
3108
|
if (parsed && parsed.version) return parsed.version;
|
|
2925
3109
|
}
|
|
2926
|
-
} catch (
|
|
3110
|
+
} catch (err) {
|
|
3111
|
+
_shellLogger.debug('Could not read installed module package.json.', pkgName, err);
|
|
3112
|
+
}
|
|
2927
3113
|
try {
|
|
2928
3114
|
for (const dir of [rootDir, '/workspace']) {
|
|
2929
3115
|
const pkgPath = PosixPath.join(dir, 'package.json');
|
|
@@ -2932,7 +3118,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2932
3118
|
const deps = Object.assign({}, parsed.dependencies || {}, parsed.devDependencies || {}, parsed.peerDependencies || {});
|
|
2933
3119
|
if (deps[pkgName]) return normalizeVersionRange(deps[pkgName]);
|
|
2934
3120
|
}
|
|
2935
|
-
} catch (
|
|
3121
|
+
} catch (err) {
|
|
3122
|
+
_shellLogger.debug('Could not read workspace package.json for version resolution.', pkgName, err);
|
|
3123
|
+
}
|
|
2936
3124
|
return 'latest';
|
|
2937
3125
|
}
|
|
2938
3126
|
|
|
@@ -2970,7 +3158,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
2970
3158
|
if (dirFlag) {
|
|
2971
3159
|
walk(full, depth + 1);
|
|
2972
3160
|
} else if (isPreviewScriptPath(name) && scripts.length < maxFiles) {
|
|
2973
|
-
try { scripts.push(vfs.readFileSync(full, 'utf8')); } catch (
|
|
3161
|
+
try { scripts.push(vfs.readFileSync(full, 'utf8')); } catch (err) { _shellLogger.debug('Preview script read skipped.', full, err); }
|
|
2974
3162
|
}
|
|
2975
3163
|
}
|
|
2976
3164
|
};
|
|
@@ -3017,7 +3205,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3017
3205
|
|
|
3018
3206
|
const handler = async (request) => {
|
|
3019
3207
|
let pathname = '/';
|
|
3020
|
-
try { pathname = decodeURIComponent(new URL(request.url).pathname); } catch (
|
|
3208
|
+
try { pathname = decodeURIComponent(new URL(request.url).pathname); } catch (err) { _shellLogger.debug('Preview URL decode failed.', err); }
|
|
3021
3209
|
const rel = pathname.replace(/^\/+/, '');
|
|
3022
3210
|
let target = PosixPath.join(rootDir, rel);
|
|
3023
3211
|
const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
|
|
@@ -3056,7 +3244,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3056
3244
|
if (rm && typeof rm.transpileForBrowser === 'function') {
|
|
3057
3245
|
body = rm.transpileForBrowser(body, target);
|
|
3058
3246
|
}
|
|
3059
|
-
} catch (
|
|
3247
|
+
} catch (err) {
|
|
3248
|
+
_shellLogger.warn(`Preview script transpilation failed for ${target}.`, err);
|
|
3249
|
+
}
|
|
3060
3250
|
}
|
|
3061
3251
|
|
|
3062
3252
|
return new Response(body, { status: 200, headers: { 'content-type': previewMimeFor(target) } });
|
|
@@ -3064,7 +3254,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3064
3254
|
|
|
3065
3255
|
const pid = (ctx.shell && typeof ctx.shell.nextPid === 'number') ? ctx.shell.nextPid++ : (ctx.pid || 1000);
|
|
3066
3256
|
return portTable.registerServer(port, {
|
|
3067
|
-
server: { close() { try { portTable.unregisterServer(port); } catch (
|
|
3257
|
+
server: { close() { try { portTable.unregisterServer(port); } catch (err) { _shellLogger.debug('Preview server unregister failed.', port, err); } } },
|
|
3068
3258
|
fetch: handler,
|
|
3069
3259
|
name: 'code-lab-serve',
|
|
3070
3260
|
pid,
|
|
@@ -3177,7 +3367,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3177
3367
|
let isDir = false;
|
|
3178
3368
|
try {
|
|
3179
3369
|
isDir = ctx.vfs.statSync(resolved).isDirectory();
|
|
3180
|
-
} catch (
|
|
3370
|
+
} catch (err) {
|
|
3371
|
+
_shellLogger.debug('cd statSync failed.', resolved, err);
|
|
3372
|
+
}
|
|
3181
3373
|
|
|
3182
3374
|
if (!isDir) {
|
|
3183
3375
|
return { code: 1, stdout: '', stderr: `cd: ${target}: Not a directory\n` };
|
|
@@ -3277,7 +3469,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3277
3469
|
isDirectory = st.isDirectory();
|
|
3278
3470
|
size = st.size;
|
|
3279
3471
|
mtimeMs = st.mtimeMs || Date.now();
|
|
3280
|
-
} catch (
|
|
3472
|
+
} catch (err) {
|
|
3473
|
+
_shellLogger.debug('ls statSync skipped.', itemPath, err);
|
|
3474
|
+
}
|
|
3281
3475
|
return { name, isDirectory, size, mtimeMs, absPath: itemPath };
|
|
3282
3476
|
});
|
|
3283
3477
|
|
|
@@ -3697,7 +3891,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3697
3891
|
if (st.isDirectory()) walk(full);
|
|
3698
3892
|
else targets.push(full);
|
|
3699
3893
|
}
|
|
3700
|
-
} catch (
|
|
3894
|
+
} catch (err) {
|
|
3895
|
+
_shellLogger.debug('grep directory walk skipped.', dir, err);
|
|
3896
|
+
}
|
|
3701
3897
|
}
|
|
3702
3898
|
if (ctx.vfs.existsSync(absRoot)) {
|
|
3703
3899
|
const st = ctx.vfs.statSync(absRoot);
|
|
@@ -3821,7 +4017,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3821
4017
|
let isDir = false;
|
|
3822
4018
|
try {
|
|
3823
4019
|
isDir = ctx.vfs.statSync(full).isDirectory();
|
|
3824
|
-
} catch (
|
|
4020
|
+
} catch (err) {
|
|
4021
|
+
_shellLogger.debug('find statSync skipped.', full, err);
|
|
4022
|
+
}
|
|
3825
4023
|
|
|
3826
4024
|
const relPath = root === '.'
|
|
3827
4025
|
? './' + full.replace(absRoot.endsWith('/') ? absRoot : absRoot + '/', '')
|
|
@@ -3840,7 +4038,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
3840
4038
|
// Root itself check
|
|
3841
4039
|
if (ctx.vfs.existsSync(absRoot)) {
|
|
3842
4040
|
let isDir = false;
|
|
3843
|
-
try { isDir = ctx.vfs.statSync(absRoot).isDirectory(); } catch (
|
|
4041
|
+
try { isDir = ctx.vfs.statSync(absRoot).isDirectory(); } catch (err) { _shellLogger.debug('find root statSync skipped.', absRoot, err); }
|
|
3844
4042
|
if (!typeFilter || (typeFilter === 'd' && isDir) || (typeFilter === 'f' && !isDir)) {
|
|
3845
4043
|
if (!nameRegex || nameRegex.test(PosixPath.basename(root))) {
|
|
3846
4044
|
results.push(root);
|
|
@@ -4752,7 +4950,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
4752
4950
|
const isLast = i === entries.length - 1;
|
|
4753
4951
|
const full = dirPath === '/' ? '/' + entry : dirPath + '/' + entry;
|
|
4754
4952
|
let isDir = false;
|
|
4755
|
-
try { isDir = ctx.vfs.statSync(full).isDirectory(); } catch (
|
|
4953
|
+
try { isDir = ctx.vfs.statSync(full).isDirectory(); } catch (err) { _shellLogger.debug('tree statSync skipped.', full, err); }
|
|
4756
4954
|
|
|
4757
4955
|
stdout += `${prefix}${isLast ? '└── ' : '├── '}${entry}\n`;
|
|
4758
4956
|
|
|
@@ -4980,10 +5178,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
4980
5178
|
for (const s of ctx.shell.portTable.listServers()) {
|
|
4981
5179
|
if (s.pid !== undefined && String(s.pid) === String(pid)) {
|
|
4982
5180
|
if (s.server && typeof s.server.close === 'function') {
|
|
4983
|
-
try { s.server.close(); } catch (
|
|
5181
|
+
try { s.server.close(); } catch (err) { _shellLogger.debug('kill server.close failed.', err); }
|
|
4984
5182
|
}
|
|
4985
5183
|
if (typeof s.stop === 'function') {
|
|
4986
|
-
try { s.stop(); } catch (
|
|
5184
|
+
try { s.stop(); } catch (err) { _shellLogger.debug('kill server.stop failed.', err); }
|
|
4987
5185
|
}
|
|
4988
5186
|
ctx.shell.portTable.unregisterServer(s.port);
|
|
4989
5187
|
killedPort = true;
|
|
@@ -7274,6 +7472,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
|
|
|
7274
7472
|
};
|
|
7275
7473
|
});
|
|
7276
7474
|
|
|
7475
|
+
|
|
7277
7476
|
})();
|
|
7278
7477
|
|
|
7279
7478
|
const CodeLabShell = _root.CodeLabShell;
|