@innovatorved/code-lab 0.1.7 → 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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.1.7 — Standalone Browser Code IDE & Virtual Runtime
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,6 +15,107 @@
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 () {
19
120
  // @ts-nocheck
20
121
  'use strict';
@@ -38,6 +139,14 @@ if (typeof globalThis !== 'undefined' && typeof globalThis.Bun === 'undefined')
38
139
  */
39
140
 
40
141
  function __initVirtualRuntime(rootScope) {
142
+ const _runtimeLogger = (rootScope && rootScope.CodeLabLogger && typeof rootScope.CodeLabLogger.createLogger === 'function')
143
+ ? rootScope.CodeLabLogger.createLogger()
144
+ : {
145
+ debug() {},
146
+ info() {},
147
+ warn(msg, meta) { if (typeof console !== 'undefined' && console.warn) console.warn('[CodeLab]', msg, meta || ''); },
148
+ error(msg, meta) { if (typeof console !== 'undefined' && console.error) console.error('[CodeLab]', msg, meta || ''); }
149
+ };
41
150
  // =========================================================================
42
151
  // 1. UTF-8 / HEX / BASE64 / BASE64URL CODECS & VIRTUAL BUFFER
43
152
  // =========================================================================
@@ -1597,7 +1706,7 @@ function __initVirtualRuntime(rootScope) {
1597
1706
  },
1598
1707
  final(cb) {
1599
1708
  if (fd !== null) {
1600
- try { fsShim.closeSync(fd); } catch (_) {}
1709
+ try { fsShim.closeSync(fd); } catch (err) { _runtimeLogger.debug('vfs writeStream closeSync failed', err); }
1601
1710
  fd = null;
1602
1711
  }
1603
1712
  cb(null);
@@ -2117,7 +2226,9 @@ function __initVirtualRuntime(rootScope) {
2117
2226
  return pathname + search + hash;
2118
2227
  }
2119
2228
  return resolvedUrl.href;
2120
- } catch (_) {}
2229
+ } catch (err) {
2230
+ _runtimeLogger.debug('url.resolve fallback used', err);
2231
+ }
2121
2232
  }
2122
2233
  if (toStr.startsWith('/')) {
2123
2234
  const m = /^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/?#]+)/.exec(fromStr);
@@ -2556,10 +2667,10 @@ function __initVirtualRuntime(rootScope) {
2556
2667
  for (const [port, entry] of Array.from(table.entries())) {
2557
2668
  if (entry.pid !== undefined && String(entry.pid) === pStr) {
2558
2669
  if (entry.server && typeof entry.server.close === 'function') {
2559
- try { entry.server.close(); } catch (_) {}
2670
+ try { entry.server.close(); } catch (err) { _runtimeLogger.debug('portTable server.close failed', err); }
2560
2671
  }
2561
2672
  if (typeof entry.stop === 'function') {
2562
- try { entry.stop(); } catch (_) {}
2673
+ try { entry.stop(); } catch (err) { _runtimeLogger.debug('portTable entry.stop failed', err); }
2563
2674
  }
2564
2675
  // Avoid a double 'close' emission when entry.server.close() already
2565
2676
  // unregistered the port through unregisterServer().
@@ -3196,7 +3307,7 @@ function __initVirtualRuntime(rootScope) {
3196
3307
  },
3197
3308
  closeAllServers() {
3198
3309
  for (const s of Array.from(activeServers.values())) {
3199
- try { s.close(); } catch (_) {}
3310
+ try { s.close(); } catch (err) { _runtimeLogger.debug('vhttp closeAllServers close failed', err); }
3200
3311
  }
3201
3312
  activeServers.clear();
3202
3313
  }
@@ -4022,7 +4133,7 @@ function __initVirtualRuntime(rootScope) {
4022
4133
 
4023
4134
  function closeAllServers() {
4024
4135
  for (const srv of servers.values()) {
4025
- try { srv.close(); } catch (_) {}
4136
+ try { srv.close(); } catch (err) { _runtimeLogger.debug('vnet closeAllServers close failed', err); }
4026
4137
  }
4027
4138
  servers.clear();
4028
4139
  }
@@ -5102,7 +5213,9 @@ function __initVirtualRuntime(rootScope) {
5102
5213
  try {
5103
5214
  const pkgJson = JSON.parse(content);
5104
5215
  for (const dep of Object.keys(pkgJson.dependencies || {})) addSpec(dep);
5105
- } catch (_) {}
5216
+ } catch (err) {
5217
+ _runtimeLogger.debug('preloadNpmPackages invalid package.json', err);
5218
+ }
5106
5219
  continue;
5107
5220
  }
5108
5221
  const reqRe = /\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
@@ -5131,7 +5244,9 @@ function __initVirtualRuntime(rootScope) {
5131
5244
  const meta = await res.json();
5132
5245
  deps = Object.keys((meta && meta.dependencies) || {});
5133
5246
  }
5134
- } catch (_) {}
5247
+ } catch (err) {
5248
+ _runtimeLogger.debug('preloadNpmPackages metadata fetch failed', { pkg, err });
5249
+ }
5135
5250
  _npmMetadataCache.set(pkg, deps);
5136
5251
  }));
5137
5252
  for (const pkg of pending) {
@@ -5149,7 +5264,7 @@ function __initVirtualRuntime(rootScope) {
5149
5264
  continue;
5150
5265
  }
5151
5266
  if (typeof onProgress === 'function') {
5152
- try { onProgress(pkg); } catch (_) {}
5267
+ try { onProgress(pkg); } catch (err) { _runtimeLogger.debug('preloadNpmPackages onProgress callback failed', err); }
5153
5268
  }
5154
5269
  if (typeof fetch === 'function') {
5155
5270
  try {
@@ -5159,7 +5274,9 @@ function __initVirtualRuntime(rootScope) {
5159
5274
  if (typeof existingCache.set === 'function') existingCache.set(pkg, text);
5160
5275
  loaded[pkg] = text;
5161
5276
  }
5162
- } catch (_) {}
5277
+ } catch (err) {
5278
+ _runtimeLogger.debug('preloadNpmPackages package fetch failed', { pkg, err });
5279
+ }
5163
5280
  }
5164
5281
  }
5165
5282
  return loaded;
@@ -5351,7 +5468,9 @@ function __initVirtualRuntime(rootScope) {
5351
5468
  const dir = VirtualPath.dirname(abs);
5352
5469
  if (!vfs.existsSync(dir)) vfs.mkdirSync(dir, { recursive: true });
5353
5470
  vfs.writeFileSync(abs, content);
5354
- } catch (_) {}
5471
+ } catch (err) {
5472
+ _runtimeLogger.warn('vfs initial file seed failed', { abs, err });
5473
+ }
5355
5474
  }
5356
5475
  }
5357
5476
  const vhttp = createVirtualHttp(resourceTracker, activePortTable);
@@ -5796,7 +5915,7 @@ function __initVirtualRuntime(rootScope) {
5796
5915
  exitCode = Number(code) || 0;
5797
5916
  if (!hasExited) {
5798
5917
  hasExited = true;
5799
- try { sandboxProcess.emit('exit', exitCode); } catch (_) {}
5918
+ try { sandboxProcess.emit('exit', exitCode); } catch (err) { _runtimeLogger.debug('process exit listener threw', err); }
5800
5919
  }
5801
5920
  if (syncExecDepth > 0) {
5802
5921
  throw new ProcessExitSignal(exitCode);
@@ -5829,8 +5948,8 @@ function __initVirtualRuntime(rootScope) {
5829
5948
  resourceTracker.inFlightHttp.clear();
5830
5949
 
5831
5950
  if (!isBackground) {
5832
- try { vhttp.closeAllServers(); } catch (_) {}
5833
- try { vnet.closeAllServers(); } catch (_) {}
5951
+ try { vhttp.closeAllServers(); } catch (err) { _runtimeLogger.debug('SIGINT vhttp closeAllServers failed', err); }
5952
+ try { vnet.closeAllServers(); } catch (err) { _runtimeLogger.debug('SIGINT vnet closeAllServers failed', err); }
5834
5953
  }
5835
5954
  };
5836
5955
 
@@ -5940,10 +6059,10 @@ function __initVirtualRuntime(rootScope) {
5940
6059
  sandboxConsole.log(`✗ ${fullName}\n ${e && e.stack ? e.stack : e}`);
5941
6060
  } finally {
5942
6061
  for (const ae of hooksSnapshot.afterEachList) {
5943
- try { await ae(); } catch (_) {}
6062
+ try { await ae(); } catch (err) { _runtimeLogger.debug('node:test afterEach hook failed', err); }
5944
6063
  }
5945
6064
  for (const af of hooksSnapshot.afterToRun) {
5946
- try { await af(); } catch (_) {}
6065
+ try { await af(); } catch (err) { _runtimeLogger.debug('node:test after hook failed', err); }
5947
6066
  }
5948
6067
  hooksSnapshot.afterToRun.length = 0;
5949
6068
  }
@@ -5991,7 +6110,7 @@ function __initVirtualRuntime(rootScope) {
5991
6110
  const afters = [...suiteCtx.afterCallbacks];
5992
6111
  const cleanupTask = nodeTestChain.then(async () => {
5993
6112
  for (const af of afters) {
5994
- try { await af(); } catch (_) {}
6113
+ try { await af(); } catch (err) { _runtimeLogger.debug('node:test suite after hook failed', err); }
5995
6114
  }
5996
6115
  });
5997
6116
  nodeTestChain = cleanupTask.catch(() => {});
@@ -6037,7 +6156,7 @@ function __initVirtualRuntime(rootScope) {
6037
6156
  getEntriesByName: (n, t) => (entry.name === n && (!t || entry.entryType === t) ? [entry] : []),
6038
6157
  getEntriesByType: (t) => (entry.entryType === t ? [entry] : [])
6039
6158
  };
6040
- try { obs._cb(list, obs); } catch (_) {}
6159
+ try { obs._cb(list, obs); } catch (err) { _runtimeLogger.debug('PerformanceObserver callback failed', err); }
6041
6160
  }
6042
6161
  }
6043
6162
  }
@@ -6142,7 +6261,7 @@ function __initVirtualRuntime(rootScope) {
6142
6261
  getEntriesByName: (n, t) => buffered.filter((e) => e.name === n && (!t || e.entryType === t)),
6143
6262
  getEntriesByType: (t) => buffered.filter((e) => e.entryType === t)
6144
6263
  };
6145
- queueMicrotask(() => { try { this._cb(list, this); } catch (_) {} });
6264
+ queueMicrotask(() => { try { this._cb(list, this); } catch (err) { _runtimeLogger.debug('PerformanceObserver buffered callback failed', err); } });
6146
6265
  }
6147
6266
  }
6148
6267
  }
@@ -7413,7 +7532,9 @@ function __initVirtualRuntime(rootScope) {
7413
7532
  const resolvedEntry = resolveFileOrDirCandidates(VirtualPath.resolve(base, entryRel));
7414
7533
  if (resolvedEntry) return resolvedEntry;
7415
7534
  }
7416
- } catch (_) {}
7535
+ } catch (err) {
7536
+ _runtimeLogger.debug('resolveFileOrDirCandidates package.json parse failed', err);
7537
+ }
7417
7538
  }
7418
7539
  const indexCandidates = ['index.js', 'index.ts', 'index.mjs', 'index.cjs', 'index.json'];
7419
7540
  for (const idx of indexCandidates) {
@@ -7483,7 +7604,9 @@ function __initVirtualRuntime(rootScope) {
7483
7604
  if (found) return found;
7484
7605
  }
7485
7606
  }
7486
- } catch (_) {}
7607
+ } catch (err) {
7608
+ _runtimeLogger.debug('resolveModulePath subpath package.json parse failed', err);
7609
+ }
7487
7610
  }
7488
7611
  const foundSub = resolveFileOrDirCandidates(VirtualPath.join(pkgRoot, subpath));
7489
7612
  if (foundSub) return foundSub;
@@ -7525,7 +7648,9 @@ function __initVirtualRuntime(rootScope) {
7525
7648
  if (isLocal && activePortTable) {
7526
7649
  return await activePortTable.dispatchRequest(urlStr, finalInit);
7527
7650
  }
7528
- } catch (_) {}
7651
+ } catch (err) {
7652
+ _runtimeLogger.debug('virtualFetch local URL dispatch skipped', err);
7653
+ }
7529
7654
 
7530
7655
  if (typeof globalThis.fetch === 'function') {
7531
7656
  return await globalThis.fetch(urlOrReq, init);
@@ -7692,7 +7817,9 @@ function __initVirtualRuntime(rootScope) {
7692
7817
  if (err instanceof SyntaxError && (/\bawait\b/.test(body) || /await/i.test(err.message))) {
7693
7818
  try {
7694
7819
  return new AsyncFunction(...argNames, body);
7695
- } catch (_) {}
7820
+ } catch (asyncErr) {
7821
+ _runtimeLogger.debug('AsyncFunction compilation fallback failed', asyncErr);
7822
+ }
7696
7823
  }
7697
7824
  if (
7698
7825
  err &&
@@ -7746,7 +7873,9 @@ function __initVirtualRuntime(rootScope) {
7746
7873
  if (signal && onAbort) {
7747
7874
  try {
7748
7875
  signal.removeEventListener('abort', onAbort);
7749
- } catch (_) {}
7876
+ } catch (err) {
7877
+ _runtimeLogger.debug('raceWithAbort removeEventListener failed', err);
7878
+ }
7750
7879
  }
7751
7880
  };
7752
7881
 
@@ -7905,11 +8034,11 @@ function __initVirtualRuntime(rootScope) {
7905
8034
  }
7906
8035
  } finally {
7907
8036
  if (signal && signalListener) {
7908
- try { signal.removeEventListener('abort', signalListener); } catch (_) {}
8037
+ try { signal.removeEventListener('abort', signalListener); } catch (err) { _runtimeLogger.debug('executeInVirtualRuntime removeEventListener failed', err); }
7909
8038
  }
7910
8039
  if (!hasExited) {
7911
8040
  hasExited = true;
7912
- try { sandboxProcess.emit('exit', exitCode); } catch (_) {}
8041
+ try { sandboxProcess.emit('exit', exitCode); } catch (err) { _runtimeLogger.debug('executeInVirtualRuntime exit listener failed', err); }
7913
8042
  }
7914
8043
  for (const rawId of resourceTracker.allTimers) {
7915
8044
  clearTimeout(rawId);
@@ -8017,7 +8146,16 @@ function createWorkerRuntimeSource() {
8017
8146
  return `'use strict';\nself.__virtualRuntime = (${__initVirtualRuntime.toString()})(self);\n(${__workerMessageLoop.toString()})(self);\n`;
8018
8147
  }
8019
8148
 
8020
- const _hostRuntime = __initVirtualRuntime(typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : global));
8149
+ const _hostScope = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : global);
8150
+ const _hostLogger = (_hostScope && _hostScope.CodeLabLogger && typeof _hostScope.CodeLabLogger.createLogger === 'function')
8151
+ ? _hostScope.CodeLabLogger.createLogger()
8152
+ : {
8153
+ debug() {},
8154
+ info() {},
8155
+ warn(msg, meta) { if (typeof console !== 'undefined' && console.warn) console.warn('[CodeLab]', msg, meta || ''); },
8156
+ error(msg, meta) { if (typeof console !== 'undefined' && console.error) console.error('[CodeLab]', msg, meta || ''); }
8157
+ };
8158
+ const _hostRuntime = __initVirtualRuntime(_hostScope);
8021
8159
  _hostRuntime.createWorkerRuntimeSource = createWorkerRuntimeSource;
8022
8160
 
8023
8161
  let _cachedWorkerUrl = null;
@@ -8041,7 +8179,7 @@ function _ensureWarmWorker() {
8041
8179
 
8042
8180
  function _destroyWarmWorker() {
8043
8181
  if (_warmWorker) {
8044
- try { _warmWorker.terminate(); } catch (_) {}
8182
+ try { _warmWorker.terminate(); } catch (err) { _hostLogger.debug('warmWorker.terminate failed', err); }
8045
8183
  _warmWorker = null;
8046
8184
  }
8047
8185
  _warmWorkerBusy = false;
@@ -8096,7 +8234,7 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
8096
8234
 
8097
8235
  function releaseWorker(terminateWorker) {
8098
8236
  if (options.signal && abortListener) {
8099
- try { options.signal.removeEventListener('abort', abortListener); } catch (_) {}
8237
+ try { options.signal.removeEventListener('abort', abortListener); } catch (err) { _hostLogger.debug('executeInWorker removeEventListener failed', err); }
8100
8238
  abortListener = null;
8101
8239
  }
8102
8240
  _activeWorkerJobs.delete(requestId);
@@ -8111,7 +8249,7 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
8111
8249
  }
8112
8250
  }
8113
8251
  } else {
8114
- try { worker.terminate(); } catch (_) {}
8252
+ try { worker.terminate(); } catch (err) { _hostLogger.debug('worker.terminate failed', err); }
8115
8253
  }
8116
8254
  }
8117
8255