@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.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
|
|
@@ -16,7 +16,109 @@
|
|
|
16
16
|
*/
|
|
17
17
|
(function (root) {
|
|
18
18
|
'use strict';
|
|
19
|
+
var CodeLabLogger = (() => {
|
|
20
|
+
var __defProp = Object.defineProperty;
|
|
21
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
22
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
23
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
|
|
38
|
+
// src/logger.ts
|
|
39
|
+
var logger_exports = {};
|
|
40
|
+
__export(logger_exports, {
|
|
41
|
+
CodeLabError: () => CodeLabError,
|
|
42
|
+
DEFAULT_LOGGER: () => DEFAULT_LOGGER,
|
|
43
|
+
LOG_PREFIX: () => LOG_PREFIX,
|
|
44
|
+
createLogger: () => createLogger,
|
|
45
|
+
default: () => logger_default,
|
|
46
|
+
isCodeLabError: () => isCodeLabError
|
|
47
|
+
});
|
|
48
|
+
var LOG_PREFIX = "[code-lab]";
|
|
49
|
+
var CodeLabError = class extends Error {
|
|
50
|
+
code;
|
|
51
|
+
options;
|
|
52
|
+
cause;
|
|
53
|
+
recoverable;
|
|
54
|
+
details;
|
|
55
|
+
context;
|
|
56
|
+
constructor(code, message, options = {}) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = "CodeLabError";
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.options = options;
|
|
61
|
+
this.cause = options.cause;
|
|
62
|
+
this.recoverable = options.recoverable !== false;
|
|
63
|
+
const meta = options.details ?? options.context;
|
|
64
|
+
if (meta !== void 0) {
|
|
65
|
+
this.details = meta;
|
|
66
|
+
this.context = meta;
|
|
67
|
+
}
|
|
68
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function isCodeLabError(value) {
|
|
72
|
+
return Boolean(
|
|
73
|
+
value && typeof value === "object" && (value instanceof CodeLabError || value.name === "CodeLabError" && typeof value.code === "string")
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function createLogger(options = {}) {
|
|
77
|
+
const sink = options.logger ?? null;
|
|
78
|
+
const debugEnabled = options.debug === true;
|
|
79
|
+
const prefix = options.prefix || LOG_PREFIX;
|
|
80
|
+
const write = (level, args) => {
|
|
81
|
+
if (level === "debug" && !debugEnabled) return;
|
|
82
|
+
if (sink && typeof sink[level] === "function") {
|
|
83
|
+
let sinkError = null;
|
|
84
|
+
try {
|
|
85
|
+
sink[level](...args);
|
|
86
|
+
return;
|
|
87
|
+
} catch (err) {
|
|
88
|
+
sinkError = err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const consoleObj = typeof console !== "undefined" ? console : null;
|
|
92
|
+
const fn = consoleObj ? consoleObj[level] : null;
|
|
93
|
+
if (typeof fn === "function") {
|
|
94
|
+
fn.call(consoleObj, prefix, ...args);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
debug: (...args) => write("debug", args),
|
|
99
|
+
info: (...args) => write("info", args),
|
|
100
|
+
warn: (...args) => write("warn", args),
|
|
101
|
+
error: (...args) => write("error", args)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
var DEFAULT_LOGGER = createLogger();
|
|
105
|
+
var _loggerNamespace = {
|
|
106
|
+
LOG_PREFIX,
|
|
107
|
+
CodeLabError,
|
|
108
|
+
isCodeLabError,
|
|
109
|
+
createLogger,
|
|
110
|
+
DEFAULT_LOGGER
|
|
111
|
+
};
|
|
112
|
+
var _globalRoot = typeof globalThis !== "undefined" ? globalThis : null;
|
|
113
|
+
if (_globalRoot && !_globalRoot.CodeLabLogger) {
|
|
114
|
+
_globalRoot.CodeLabLogger = _loggerNamespace;
|
|
115
|
+
}
|
|
116
|
+
var logger_default = _loggerNamespace;
|
|
117
|
+
return __toCommonJS(logger_exports);
|
|
118
|
+
})();
|
|
119
|
+
|
|
19
120
|
(function () {
|
|
121
|
+
// @ts-nocheck
|
|
20
122
|
/**
|
|
21
123
|
* @innovatorved/code-lab - POSIX Shell Engine & UNIX Coreutils
|
|
22
124
|
*
|
|
@@ -63,12 +165,23 @@
|
|
|
63
165
|
})(typeof globalThis !== 'undefined' ? globalThis : this, function (root) {
|
|
64
166
|
'use strict';
|
|
65
167
|
|
|
168
|
+
const _shellLogger = (root && root.CodeLabLogger && typeof root.CodeLabLogger.createLogger === 'function')
|
|
169
|
+
? root.CodeLabLogger.createLogger()
|
|
170
|
+
: {
|
|
171
|
+
debug() {},
|
|
172
|
+
info(...args) { if (typeof console !== 'undefined' && console.info) console.info('[code-lab]', ...args); },
|
|
173
|
+
warn(...args) { if (typeof console !== 'undefined' && console.warn) console.warn('[code-lab]', ...args); },
|
|
174
|
+
error(...args) { if (typeof console !== 'undefined' && console.error) console.error('[code-lab]', ...args); }
|
|
175
|
+
};
|
|
176
|
+
|
|
66
177
|
function getRuntimeModule() {
|
|
67
178
|
if (typeof root !== 'undefined' && root && root.CodeLabRuntime) return root.CodeLabRuntime;
|
|
68
179
|
if (typeof globalThis !== 'undefined' && globalThis.CodeLabRuntime) return globalThis.CodeLabRuntime;
|
|
69
180
|
try {
|
|
70
181
|
if (typeof require !== 'undefined') return require('./runtime.js');
|
|
71
|
-
} catch (
|
|
182
|
+
} catch (err) {
|
|
183
|
+
_shellLogger.debug('Optional ./runtime.js require skipped in shell.', err);
|
|
184
|
+
}
|
|
72
185
|
return null;
|
|
73
186
|
}
|
|
74
187
|
|
|
@@ -660,7 +773,9 @@
|
|
|
660
773
|
if (typeof vfs.statSync === 'function') {
|
|
661
774
|
isDir = vfs.statSync(full).isDirectory();
|
|
662
775
|
}
|
|
663
|
-
} catch (
|
|
776
|
+
} catch (err) {
|
|
777
|
+
_shellLogger.debug('Glob statSync failed.', full, err);
|
|
778
|
+
}
|
|
664
779
|
|
|
665
780
|
if (isDir) {
|
|
666
781
|
traverse(full, rel);
|
|
@@ -1982,7 +2097,9 @@
|
|
|
1982
2097
|
: name;
|
|
1983
2098
|
try {
|
|
1984
2099
|
snap[rel] = String(vfs.readFileSync(full, 'utf8'));
|
|
1985
|
-
} catch (
|
|
2100
|
+
} catch (err) {
|
|
2101
|
+
_shellLogger.debug('Skipped unreadable VFS file in snapshot.', full, err);
|
|
2102
|
+
}
|
|
1986
2103
|
}
|
|
1987
2104
|
}
|
|
1988
2105
|
}
|
|
@@ -2004,7 +2121,7 @@
|
|
|
2004
2121
|
return 10 + depth * 0.1;
|
|
2005
2122
|
}
|
|
2006
2123
|
|
|
2007
|
-
async function
|
|
2124
|
+
async function _cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
2008
2125
|
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
2009
2126
|
if (onProgress) {
|
|
2010
2127
|
onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
|
|
@@ -2086,8 +2203,9 @@
|
|
|
2086
2203
|
}
|
|
2087
2204
|
}
|
|
2088
2205
|
}
|
|
2089
|
-
} catch (
|
|
2206
|
+
} catch (err) {
|
|
2090
2207
|
// Network or rate limit error on api.github.com; proceed to Strategy B
|
|
2208
|
+
_shellLogger.debug('GitHub REST API tree fetch failed; falling back to jsDelivr.', err);
|
|
2091
2209
|
}
|
|
2092
2210
|
|
|
2093
2211
|
// Strategy B: jsDelivr Data API (Zero rate limits, fast global edge cache)
|
|
@@ -2114,7 +2232,9 @@
|
|
|
2114
2232
|
}
|
|
2115
2233
|
}
|
|
2116
2234
|
}
|
|
2117
|
-
} catch (
|
|
2235
|
+
} catch (err) {
|
|
2236
|
+
_shellLogger.debug('jsDelivr flat tree fetch failed.', err);
|
|
2237
|
+
}
|
|
2118
2238
|
}
|
|
2119
2239
|
|
|
2120
2240
|
if (repoNotFound || !rawTreeEntries) {
|
|
@@ -2262,7 +2382,9 @@
|
|
|
2262
2382
|
}));
|
|
2263
2383
|
}
|
|
2264
2384
|
}
|
|
2265
|
-
} catch (
|
|
2385
|
+
} catch (err) {
|
|
2386
|
+
_shellLogger.debug('Optional commit history fetch skipped.', err);
|
|
2387
|
+
}
|
|
2266
2388
|
|
|
2267
2389
|
if (commits.length === 0) {
|
|
2268
2390
|
commits = [
|
|
@@ -2294,6 +2416,23 @@
|
|
|
2294
2416
|
};
|
|
2295
2417
|
}
|
|
2296
2418
|
|
|
2419
|
+
// Public wrapper: guarantee an `error` progress event when the clone fails
|
|
2420
|
+
// for any reason (invalid URL, missing vfs, fetch rejection, abort, ...).
|
|
2421
|
+
async function cloneGitHubRepository(repoInput, vfs, options = {}) {
|
|
2422
|
+
const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
|
|
2423
|
+
try {
|
|
2424
|
+
return await _cloneGitHubRepository(repoInput, vfs, options);
|
|
2425
|
+
} catch (err) {
|
|
2426
|
+
if (onProgress) {
|
|
2427
|
+
onProgress({
|
|
2428
|
+
phase: 'error',
|
|
2429
|
+
message: err && err.message ? err.message : String(err)
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
throw err;
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2297
2436
|
// =========================================================================
|
|
2298
2437
|
// Package Management Helpers (npm / bun virtual modules & scripts)
|
|
2299
2438
|
// =========================================================================
|
|
@@ -2311,7 +2450,9 @@
|
|
|
2311
2450
|
try {
|
|
2312
2451
|
const parsed = JSON.parse(vfs.readFileSync(p, 'utf8'));
|
|
2313
2452
|
return { path: p, data: parsed };
|
|
2314
|
-
} catch (
|
|
2453
|
+
} catch (err) {
|
|
2454
|
+
_shellLogger.warn(`Invalid JSON in ${p}; falling back to default package metadata.`, err);
|
|
2455
|
+
}
|
|
2315
2456
|
}
|
|
2316
2457
|
return { path: p, data: { name: 'app', dependencies: {}, devDependencies: {}, scripts: {} } };
|
|
2317
2458
|
}
|
|
@@ -2352,13 +2493,20 @@
|
|
|
2352
2493
|
vfs.rmdirSync(dirPath);
|
|
2353
2494
|
}
|
|
2354
2495
|
if (typeof emitMutation === 'function') emitMutation('delete', dirPath);
|
|
2355
|
-
} catch (
|
|
2496
|
+
} catch (err) {
|
|
2497
|
+
_shellLogger.debug('removeDirRecursive failed.', dirPath, err);
|
|
2498
|
+
}
|
|
2356
2499
|
}
|
|
2357
2500
|
|
|
2358
2501
|
// ---------------------------------------------------------------------------
|
|
2359
2502
|
// Real npm package installation via the jsDelivr CDN
|
|
2360
2503
|
// ---------------------------------------------------------------------------
|
|
2361
2504
|
const CDN_NPM_BASE = 'https://cdn.jsdelivr.net/npm';
|
|
2505
|
+
const CDN_NPM_BASES = [
|
|
2506
|
+
'https://cdn.jsdelivr.net/npm',
|
|
2507
|
+
'https://unpkg.com',
|
|
2508
|
+
'https://esm.sh'
|
|
2509
|
+
];
|
|
2362
2510
|
|
|
2363
2511
|
// Minimal offline registry, used only when the CDN is unreachable so common
|
|
2364
2512
|
// demos still resolve without network access.
|
|
@@ -2504,16 +2652,23 @@
|
|
|
2504
2652
|
}
|
|
2505
2653
|
|
|
2506
2654
|
async function resolvePackageMetadata(fetchImpl, name, range) {
|
|
2507
|
-
const
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
const
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2655
|
+
for (const base of CDN_NPM_BASES) {
|
|
2656
|
+
const urls = range
|
|
2657
|
+
? [`${base}/${name}@${range}/package.json`, `${base}/${name}/package.json`]
|
|
2658
|
+
: [`${base}/${name}/package.json`];
|
|
2659
|
+
for (const url of urls) {
|
|
2660
|
+
const text = await fetchTextFromCdn(fetchImpl, url);
|
|
2661
|
+
if (!text) continue;
|
|
2662
|
+
try {
|
|
2663
|
+
const parsed = JSON.parse(text);
|
|
2664
|
+
if (parsed && parsed.version) {
|
|
2665
|
+
parsed._resolvedCdnBase = base;
|
|
2666
|
+
return parsed;
|
|
2667
|
+
}
|
|
2668
|
+
} catch (err) {
|
|
2669
|
+
_shellLogger.debug('Invalid package.json metadata from CDN.', url, err);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2517
2672
|
}
|
|
2518
2673
|
return null;
|
|
2519
2674
|
}
|
|
@@ -2531,6 +2686,7 @@
|
|
|
2531
2686
|
return { ok: false, reason: `${name}: package metadata not found on the registry (offline?)` };
|
|
2532
2687
|
}
|
|
2533
2688
|
|
|
2689
|
+
const activeCdnBase = meta._resolvedCdnBase || CDN_NPM_BASE;
|
|
2534
2690
|
const version = meta.version;
|
|
2535
2691
|
const key = `${name}@${version}`;
|
|
2536
2692
|
if (seen.has(key)) {
|
|
@@ -2578,7 +2734,7 @@
|
|
|
2578
2734
|
frontier = [];
|
|
2579
2735
|
if (batch.length === 0) break;
|
|
2580
2736
|
const texts = await Promise.all(
|
|
2581
|
-
batch.map((rel) => fetchTextFromCdn(fetchImpl, `${
|
|
2737
|
+
batch.map((rel) => fetchTextFromCdn(fetchImpl, `${activeCdnBase}/${name}@${version}/${rel}`))
|
|
2582
2738
|
);
|
|
2583
2739
|
for (let idx = 0; idx < batch.length; idx++) {
|
|
2584
2740
|
const rel = batch[idx];
|
|
@@ -2602,7 +2758,7 @@
|
|
|
2602
2758
|
}
|
|
2603
2759
|
// The declared entry may be missing on the CDN; fall back to index.js.
|
|
2604
2760
|
if (!files.some(f => f.rel === entry)) {
|
|
2605
|
-
const idxText = await fetchTextFromCdn(fetchImpl, `${
|
|
2761
|
+
const idxText = await fetchTextFromCdn(fetchImpl, `${activeCdnBase}/${name}@${version}/index.js`);
|
|
2606
2762
|
if (idxText !== null) files.push({ rel: 'index.js', content: idxText });
|
|
2607
2763
|
}
|
|
2608
2764
|
|
|
@@ -2649,7 +2805,9 @@
|
|
|
2649
2805
|
// directory target would otherwise raise EISDIR).
|
|
2650
2806
|
try {
|
|
2651
2807
|
if (ctx.vfs.existsSync(full) && ctx.vfs.statSync(full).isDirectory()) continue;
|
|
2652
|
-
} catch (
|
|
2808
|
+
} catch (err) {
|
|
2809
|
+
_shellLogger.debug('Package install statSync check skipped.', full, err);
|
|
2810
|
+
}
|
|
2653
2811
|
ensureDirSync(ctx.vfs, PosixPath.dirname(full), ctx.emitMutation);
|
|
2654
2812
|
ctx.vfs.writeFileSync(full, f.content);
|
|
2655
2813
|
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('create', full);
|
|
@@ -2727,6 +2885,32 @@
|
|
|
2727
2885
|
pkgData[depField][pkgName] = range || (directVersion ? `^${directVersion}` : (pkgData[depField][pkgName] || 'latest'));
|
|
2728
2886
|
writePackageJson(ctx.vfs, pkgPath, pkgData, ctx.emitMutation);
|
|
2729
2887
|
|
|
2888
|
+
// Also maintain package-lock.json in the same directory for deterministic lockfile verification
|
|
2889
|
+
try {
|
|
2890
|
+
const lockPath = PosixPath.join(PosixPath.dirname(pkgPath), 'package-lock.json');
|
|
2891
|
+
let lockData = { name: pkgData.name || 'workspace', version: pkgData.version || '1.0.0', lockfileVersion: 3, packages: {} };
|
|
2892
|
+
if (ctx.vfs.existsSync(lockPath)) {
|
|
2893
|
+
const rawLock = String(ctx.vfs.readFileSync(lockPath, 'utf8') || '');
|
|
2894
|
+
const parsedLock = JSON.parse(rawLock);
|
|
2895
|
+
if (parsedLock && typeof parsedLock === 'object') {
|
|
2896
|
+
lockData = parsedLock;
|
|
2897
|
+
if (!lockData.packages || typeof lockData.packages !== 'object') lockData.packages = {};
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
for (const inst of installed) {
|
|
2901
|
+
if (inst && inst.name) {
|
|
2902
|
+
lockData.packages[`node_modules/${inst.name}`] = {
|
|
2903
|
+
version: inst.version || '1.0.0',
|
|
2904
|
+
resolved: `${CDN_NPM_BASE}/${inst.name}@${inst.version || '1.0.0'}`
|
|
2905
|
+
};
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
ctx.vfs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n');
|
|
2909
|
+
if (typeof ctx.emitMutation === 'function') ctx.emitMutation('modify', lockPath);
|
|
2910
|
+
} catch (err) {
|
|
2911
|
+
_shellLogger.debug('Could not write package-lock.json during installPackage.', err);
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2730
2914
|
return { name: pkgName, ok: true, version: directVersion, installed, warning };
|
|
2731
2915
|
}
|
|
2732
2916
|
|
|
@@ -2924,7 +3108,9 @@
|
|
|
2924
3108
|
const parsed = JSON.parse(vfs.readFileSync(modPkg, 'utf8'));
|
|
2925
3109
|
if (parsed && parsed.version) return parsed.version;
|
|
2926
3110
|
}
|
|
2927
|
-
} catch (
|
|
3111
|
+
} catch (err) {
|
|
3112
|
+
_shellLogger.debug('Could not read installed module package.json.', pkgName, err);
|
|
3113
|
+
}
|
|
2928
3114
|
try {
|
|
2929
3115
|
for (const dir of [rootDir, '/workspace']) {
|
|
2930
3116
|
const pkgPath = PosixPath.join(dir, 'package.json');
|
|
@@ -2933,7 +3119,9 @@
|
|
|
2933
3119
|
const deps = Object.assign({}, parsed.dependencies || {}, parsed.devDependencies || {}, parsed.peerDependencies || {});
|
|
2934
3120
|
if (deps[pkgName]) return normalizeVersionRange(deps[pkgName]);
|
|
2935
3121
|
}
|
|
2936
|
-
} catch (
|
|
3122
|
+
} catch (err) {
|
|
3123
|
+
_shellLogger.debug('Could not read workspace package.json for version resolution.', pkgName, err);
|
|
3124
|
+
}
|
|
2937
3125
|
return 'latest';
|
|
2938
3126
|
}
|
|
2939
3127
|
|
|
@@ -2971,7 +3159,7 @@
|
|
|
2971
3159
|
if (dirFlag) {
|
|
2972
3160
|
walk(full, depth + 1);
|
|
2973
3161
|
} else if (isPreviewScriptPath(name) && scripts.length < maxFiles) {
|
|
2974
|
-
try { scripts.push(vfs.readFileSync(full, 'utf8')); } catch (
|
|
3162
|
+
try { scripts.push(vfs.readFileSync(full, 'utf8')); } catch (err) { _shellLogger.debug('Preview script read skipped.', full, err); }
|
|
2975
3163
|
}
|
|
2976
3164
|
}
|
|
2977
3165
|
};
|
|
@@ -3018,7 +3206,7 @@
|
|
|
3018
3206
|
|
|
3019
3207
|
const handler = async (request) => {
|
|
3020
3208
|
let pathname = '/';
|
|
3021
|
-
try { pathname = decodeURIComponent(new URL(request.url).pathname); } catch (
|
|
3209
|
+
try { pathname = decodeURIComponent(new URL(request.url).pathname); } catch (err) { _shellLogger.debug('Preview URL decode failed.', err); }
|
|
3022
3210
|
const rel = pathname.replace(/^\/+/, '');
|
|
3023
3211
|
let target = PosixPath.join(rootDir, rel);
|
|
3024
3212
|
const hasExt = /\.[A-Za-z0-9]+$/.test(rel);
|
|
@@ -3057,7 +3245,9 @@
|
|
|
3057
3245
|
if (rm && typeof rm.transpileForBrowser === 'function') {
|
|
3058
3246
|
body = rm.transpileForBrowser(body, target);
|
|
3059
3247
|
}
|
|
3060
|
-
} catch (
|
|
3248
|
+
} catch (err) {
|
|
3249
|
+
_shellLogger.warn(`Preview script transpilation failed for ${target}.`, err);
|
|
3250
|
+
}
|
|
3061
3251
|
}
|
|
3062
3252
|
|
|
3063
3253
|
return new Response(body, { status: 200, headers: { 'content-type': previewMimeFor(target) } });
|
|
@@ -3065,7 +3255,7 @@
|
|
|
3065
3255
|
|
|
3066
3256
|
const pid = (ctx.shell && typeof ctx.shell.nextPid === 'number') ? ctx.shell.nextPid++ : (ctx.pid || 1000);
|
|
3067
3257
|
return portTable.registerServer(port, {
|
|
3068
|
-
server: { close() { try { portTable.unregisterServer(port); } catch (
|
|
3258
|
+
server: { close() { try { portTable.unregisterServer(port); } catch (err) { _shellLogger.debug('Preview server unregister failed.', port, err); } } },
|
|
3069
3259
|
fetch: handler,
|
|
3070
3260
|
name: 'code-lab-serve',
|
|
3071
3261
|
pid,
|
|
@@ -3178,7 +3368,9 @@
|
|
|
3178
3368
|
let isDir = false;
|
|
3179
3369
|
try {
|
|
3180
3370
|
isDir = ctx.vfs.statSync(resolved).isDirectory();
|
|
3181
|
-
} catch (
|
|
3371
|
+
} catch (err) {
|
|
3372
|
+
_shellLogger.debug('cd statSync failed.', resolved, err);
|
|
3373
|
+
}
|
|
3182
3374
|
|
|
3183
3375
|
if (!isDir) {
|
|
3184
3376
|
return { code: 1, stdout: '', stderr: `cd: ${target}: Not a directory\n` };
|
|
@@ -3278,7 +3470,9 @@
|
|
|
3278
3470
|
isDirectory = st.isDirectory();
|
|
3279
3471
|
size = st.size;
|
|
3280
3472
|
mtimeMs = st.mtimeMs || Date.now();
|
|
3281
|
-
} catch (
|
|
3473
|
+
} catch (err) {
|
|
3474
|
+
_shellLogger.debug('ls statSync skipped.', itemPath, err);
|
|
3475
|
+
}
|
|
3282
3476
|
return { name, isDirectory, size, mtimeMs, absPath: itemPath };
|
|
3283
3477
|
});
|
|
3284
3478
|
|
|
@@ -3698,7 +3892,9 @@
|
|
|
3698
3892
|
if (st.isDirectory()) walk(full);
|
|
3699
3893
|
else targets.push(full);
|
|
3700
3894
|
}
|
|
3701
|
-
} catch (
|
|
3895
|
+
} catch (err) {
|
|
3896
|
+
_shellLogger.debug('grep directory walk skipped.', dir, err);
|
|
3897
|
+
}
|
|
3702
3898
|
}
|
|
3703
3899
|
if (ctx.vfs.existsSync(absRoot)) {
|
|
3704
3900
|
const st = ctx.vfs.statSync(absRoot);
|
|
@@ -3822,7 +4018,9 @@
|
|
|
3822
4018
|
let isDir = false;
|
|
3823
4019
|
try {
|
|
3824
4020
|
isDir = ctx.vfs.statSync(full).isDirectory();
|
|
3825
|
-
} catch (
|
|
4021
|
+
} catch (err) {
|
|
4022
|
+
_shellLogger.debug('find statSync skipped.', full, err);
|
|
4023
|
+
}
|
|
3826
4024
|
|
|
3827
4025
|
const relPath = root === '.'
|
|
3828
4026
|
? './' + full.replace(absRoot.endsWith('/') ? absRoot : absRoot + '/', '')
|
|
@@ -3841,7 +4039,7 @@
|
|
|
3841
4039
|
// Root itself check
|
|
3842
4040
|
if (ctx.vfs.existsSync(absRoot)) {
|
|
3843
4041
|
let isDir = false;
|
|
3844
|
-
try { isDir = ctx.vfs.statSync(absRoot).isDirectory(); } catch (
|
|
4042
|
+
try { isDir = ctx.vfs.statSync(absRoot).isDirectory(); } catch (err) { _shellLogger.debug('find root statSync skipped.', absRoot, err); }
|
|
3845
4043
|
if (!typeFilter || (typeFilter === 'd' && isDir) || (typeFilter === 'f' && !isDir)) {
|
|
3846
4044
|
if (!nameRegex || nameRegex.test(PosixPath.basename(root))) {
|
|
3847
4045
|
results.push(root);
|
|
@@ -4753,7 +4951,7 @@
|
|
|
4753
4951
|
const isLast = i === entries.length - 1;
|
|
4754
4952
|
const full = dirPath === '/' ? '/' + entry : dirPath + '/' + entry;
|
|
4755
4953
|
let isDir = false;
|
|
4756
|
-
try { isDir = ctx.vfs.statSync(full).isDirectory(); } catch (
|
|
4954
|
+
try { isDir = ctx.vfs.statSync(full).isDirectory(); } catch (err) { _shellLogger.debug('tree statSync skipped.', full, err); }
|
|
4757
4955
|
|
|
4758
4956
|
stdout += `${prefix}${isLast ? '└── ' : '├── '}${entry}\n`;
|
|
4759
4957
|
|
|
@@ -4981,10 +5179,10 @@
|
|
|
4981
5179
|
for (const s of ctx.shell.portTable.listServers()) {
|
|
4982
5180
|
if (s.pid !== undefined && String(s.pid) === String(pid)) {
|
|
4983
5181
|
if (s.server && typeof s.server.close === 'function') {
|
|
4984
|
-
try { s.server.close(); } catch (
|
|
5182
|
+
try { s.server.close(); } catch (err) { _shellLogger.debug('kill server.close failed.', err); }
|
|
4985
5183
|
}
|
|
4986
5184
|
if (typeof s.stop === 'function') {
|
|
4987
|
-
try { s.stop(); } catch (
|
|
5185
|
+
try { s.stop(); } catch (err) { _shellLogger.debug('kill server.stop failed.', err); }
|
|
4988
5186
|
}
|
|
4989
5187
|
ctx.shell.portTable.unregisterServer(s.port);
|
|
4990
5188
|
killedPort = true;
|
|
@@ -7275,6 +7473,7 @@
|
|
|
7275
7473
|
};
|
|
7276
7474
|
});
|
|
7277
7475
|
|
|
7476
|
+
|
|
7278
7477
|
})();
|
|
7279
7478
|
|
|
7280
7479
|
if (typeof module !== 'undefined' && module.exports) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @innovatorved/code-lab — Cascading Multi-Project Durable Workspace Storage
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* Provides durable multi-project workspace persistence with automatic tiered
|
|
5
|
+
* fallback:
|
|
6
|
+
* 1. IndexedDB (`indexeddb`) — high-capacity asynchronous browser store
|
|
7
|
+
* 2. LocalStorage (`localstorage`) — synchronous key-value fallback
|
|
8
|
+
* 3. In-Memory Map (`memory`) — guaranteed zero-dependency fallback for
|
|
9
|
+
* headless tests, SSR, or restricted/incognito sandboxes
|
|
10
|
+
*
|
|
11
|
+
* Strict leaf module: fully typed, zero explicit any, zero empty catches.
|
|
12
|
+
*/
|
|
13
|
+
export type StorageBackendType = 'indexeddb' | 'localstorage' | 'memory';
|
|
14
|
+
export interface StoredProject {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
files: Record<string, string>;
|
|
18
|
+
updatedAt: number;
|
|
19
|
+
createdAt?: number;
|
|
20
|
+
entry?: string;
|
|
21
|
+
testEntry?: string;
|
|
22
|
+
version?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ProjectSummary {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
updatedAt: number;
|
|
28
|
+
fileCount: number;
|
|
29
|
+
}
|
|
30
|
+
export interface WorkspaceStorageOptions {
|
|
31
|
+
dbName?: string;
|
|
32
|
+
storeName?: string;
|
|
33
|
+
storagePrefix?: string;
|
|
34
|
+
preferredBackend?: StorageBackendType;
|
|
35
|
+
}
|
|
36
|
+
export declare class WorkspaceStorage {
|
|
37
|
+
private readonly dbName;
|
|
38
|
+
private readonly storeName;
|
|
39
|
+
private readonly storagePrefix;
|
|
40
|
+
private backendType;
|
|
41
|
+
private readonly memoryStore;
|
|
42
|
+
private dbPromise;
|
|
43
|
+
constructor(options?: WorkspaceStorageOptions);
|
|
44
|
+
getBackendType(): StorageBackendType;
|
|
45
|
+
private openIdb;
|
|
46
|
+
private downgradeFromIdb;
|
|
47
|
+
saveProject(project: StoredProject): Promise<boolean>;
|
|
48
|
+
loadProject(id: string): Promise<StoredProject | null>;
|
|
49
|
+
listProjects(): Promise<ProjectSummary[]>;
|
|
50
|
+
deleteProject(id: string): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
export declare function createWorkspaceStorage(options?: WorkspaceStorageOptions): WorkspaceStorage;
|
|
53
|
+
declare const _default: {
|
|
54
|
+
WorkspaceStorage: typeof WorkspaceStorage;
|
|
55
|
+
createWorkspaceStorage: typeof createWorkspaceStorage;
|
|
56
|
+
};
|
|
57
|
+
export default _default;
|
package/dist/terminal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @innovatorved/code-lab - Pure-JS
|
|
2
|
+
* @innovatorved/code-lab - Pure-JS PTY Terminal Emulator Component
|
|
3
3
|
*
|
|
4
4
|
* High-fidelity, self-contained terminal emulator engine providing:
|
|
5
5
|
* - Inline prompt with cwd awareness (codelab:${cwd}$ )
|
|
@@ -13,90 +13,14 @@
|
|
|
13
13
|
*
|
|
14
14
|
* (C) 2026 InnovatorVed / CodeLab. MIT License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
text: string;
|
|
18
|
-
type?: string;
|
|
19
|
-
}
|
|
20
|
-
export interface CompletionResult {
|
|
21
|
-
matches: string[];
|
|
22
|
-
token: string;
|
|
23
|
-
tokenStart: number;
|
|
24
|
-
}
|
|
25
|
-
export interface TerminalOptions {
|
|
26
|
-
container?: any;
|
|
27
|
-
logs?: TerminalLogItem[];
|
|
28
|
-
cwd?: string;
|
|
29
|
-
replMode?: boolean;
|
|
30
|
-
prompt?: string | null;
|
|
31
|
-
history?: string[];
|
|
32
|
-
onCommand?: ((command: string) => void) | null;
|
|
33
|
-
getCompletions?: ((buffer: string, cursor: number) => CompletionResult | null) | null;
|
|
34
|
-
onKey?: ((event: any) => boolean | void) | null;
|
|
35
|
-
onInterrupt?: (() => void) | null;
|
|
36
|
-
}
|
|
16
|
+
declare const _hostTerminal: any;
|
|
37
17
|
export declare const ANSI_CODE_MAP: Record<number, string>;
|
|
38
|
-
export declare const
|
|
39
|
-
export declare
|
|
40
|
-
export declare
|
|
41
|
-
export declare
|
|
42
|
-
export declare
|
|
43
|
-
export declare const
|
|
44
|
-
export declare
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
logs: TerminalLogItem[];
|
|
48
|
-
cwd: string;
|
|
49
|
-
replMode: boolean;
|
|
50
|
-
promptOverride: string | null;
|
|
51
|
-
history: string[];
|
|
52
|
-
historyIdx: number;
|
|
53
|
-
savedBuffer: string;
|
|
54
|
-
buffer: string;
|
|
55
|
-
cursor: number;
|
|
56
|
-
searchMode: boolean;
|
|
57
|
-
searchQuery: string;
|
|
58
|
-
searchMatchIdx: number;
|
|
59
|
-
_readLineQueue: Array<(line: string) => void>;
|
|
60
|
-
onCommand: ((command: string) => void) | null;
|
|
61
|
-
getCompletions: ((buffer: string, cursor: number) => CompletionResult | null) | null;
|
|
62
|
-
onKey: ((event: any) => boolean | void) | null;
|
|
63
|
-
onInterrupt: (() => void) | null;
|
|
64
|
-
_activeLineCommitted: boolean;
|
|
65
|
-
_cursorCol: number;
|
|
66
|
-
_pendingEscape: string;
|
|
67
|
-
_targetLineIdx: number;
|
|
68
|
-
_needsRewrite: boolean;
|
|
69
|
-
_activeLineEl: any;
|
|
70
|
-
_mounted: boolean;
|
|
71
|
-
_listeners: Array<any>;
|
|
72
|
-
constructor(container?: any, options?: TerminalOptions);
|
|
73
|
-
getPrompt(): string;
|
|
74
|
-
setPrompt(p: string | null): void;
|
|
75
|
-
setCwd(cwd: string): void;
|
|
76
|
-
setReplMode(enabled: boolean): void;
|
|
77
|
-
writeStreamChunk(data: any, type?: string): void;
|
|
78
|
-
write(data: any, type?: string): void;
|
|
79
|
-
writeln(data: any, type?: string): void;
|
|
80
|
-
_getActiveLine(type: string): TerminalLogItem;
|
|
81
|
-
_appendDomLine(line: TerminalLogItem): void;
|
|
82
|
-
_updateActiveDomLine(): void;
|
|
83
|
-
_getActiveLineSync(): TerminalLogItem | null;
|
|
84
|
-
_scrollToBottom(): void;
|
|
85
|
-
clear(): void;
|
|
86
|
-
getHistory(): string[];
|
|
87
|
-
readLine(promptText?: string): Promise<string>;
|
|
88
|
-
focus(): void;
|
|
89
|
-
mount(container: any): void;
|
|
90
|
-
_cleanupListeners(): void;
|
|
91
|
-
destroy(): void;
|
|
92
|
-
_addListener(target: any, type: string, handler: any): void;
|
|
93
|
-
_bindEvents(): void;
|
|
94
|
-
_findReverseSearchMatch(query: string, startIdx?: number): number;
|
|
95
|
-
handleKeyDown(e: any): void;
|
|
96
|
-
autoComplete(): void;
|
|
97
|
-
submitLine(): void;
|
|
98
|
-
updateActiveLine(): void;
|
|
99
|
-
render(): void;
|
|
100
|
-
}
|
|
101
|
-
export declare function createTerminal(container?: any, options?: TerminalOptions): PTYTerminalEngine;
|
|
102
|
-
export declare const createPTYTerminalEngine: typeof createTerminal;
|
|
18
|
+
export declare const ansi256ToColor: (n: number | string) => string | null;
|
|
19
|
+
export declare const escapeHtml: (str: any) => string;
|
|
20
|
+
export declare const resolveAnsiControlCodes: (raw: any) => string;
|
|
21
|
+
export declare const ansiToHtml: (str: any) => string;
|
|
22
|
+
export declare const parseAnsiToHtml: (str: any) => string;
|
|
23
|
+
export declare const PTYTerminalEngine: any;
|
|
24
|
+
export declare const createTerminal: (container?: any, options?: any) => any;
|
|
25
|
+
export declare const createPTYTerminalEngine: (container?: any, options?: any) => any;
|
|
26
|
+
export default _hostTerminal;
|