@innovatorved/code-lab 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-lab.d.ts +3 -1
- package/dist/code-lab.esm.js +541 -32
- package/dist/code-lab.js +531 -31
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.esm.js +455 -15
- package/dist/runtime.js +412 -4
- package/dist/schemas.esm.js +4191 -0
- package/dist/schemas.js +4207 -0
- package/dist/shell.esm.js +118 -27
- package/dist/shell.js +118 -27
- package/dist/terminal.esm.js +7 -1
- package/package.json +5 -4
- package/src/runtime.js +412 -4
- package/src/runtime.ts +413 -4
- package/src/shell.js +118 -27
- package/src/shell.ts +118 -27
package/src/runtime.js
CHANGED
|
@@ -809,9 +809,78 @@ function __initVirtualRuntime(rootScope) {
|
|
|
809
809
|
crc = CRC32_TABLE[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8);
|
|
810
810
|
}
|
|
811
811
|
return (crc ^ 0xffffffff) >>> 0;
|
|
812
|
+
},
|
|
813
|
+
// The full Node zlib constant surface. Packages such as axios read these at
|
|
814
|
+
// module-load time (e.g. `zlib.constants.Z_SYNC_FLUSH`) even when they never
|
|
815
|
+
// actually compress, so a missing table breaks the whole module graph.
|
|
816
|
+
constants: {
|
|
817
|
+
Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4,
|
|
818
|
+
Z_BLOCK: 5, Z_TREES: 6, Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1,
|
|
819
|
+
Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4, Z_BUF_ERROR: -5,
|
|
820
|
+
Z_VERSION_ERROR: -6, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9,
|
|
821
|
+
Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4,
|
|
822
|
+
Z_DEFAULT_STRATEGY: 0, ZLIB_VERNUM: 0x1310, DEFLATE: 1, INFLATE: 2, GZIP: 3,
|
|
823
|
+
GUNZIP: 4, DEFLATERAW: 5, INFLATERAW: 6, UNZIP: 7, BROTLI_DECODE: 8,
|
|
824
|
+
BROTLI_ENCODE: 9, Z_MIN_WINDOWBITS: 8, Z_MAX_WINDOWBITS: 15,
|
|
825
|
+
Z_DEFAULT_WINDOWBITS: 15, Z_MIN_CHUNK: 64, Z_MAX_CHUNK: Infinity,
|
|
826
|
+
Z_DEFAULT_CHUNK: 16384, Z_MIN_MEMLEVEL: 1, Z_MAX_MEMLEVEL: 9,
|
|
827
|
+
Z_DEFAULT_MEMLEVEL: 8, Z_MIN_LEVEL: -1, Z_MAX_LEVEL: 9, Z_DEFAULT_LEVEL: -1
|
|
812
828
|
}
|
|
813
829
|
};
|
|
814
830
|
|
|
831
|
+
// Compression: delegate to the host's real zlib when the runtime is embedded in
|
|
832
|
+
// Node (same process). In a pure browser worker there is no synchronous zlib, so
|
|
833
|
+
// the async APIs use CompressionStream/DecompressionStream and the *Sync variants
|
|
834
|
+
// throw a descriptive error instead of silently corrupting data.
|
|
835
|
+
(() => {
|
|
836
|
+
let hostZlib = null;
|
|
837
|
+
try { hostZlib = (typeof require === 'function') ? require('zlib') : null; } catch (_) { hostZlib = null; }
|
|
838
|
+
const names = [
|
|
839
|
+
'gzip', 'gunzip', 'deflate', 'inflate', 'deflateRaw', 'inflateRaw', 'unzip',
|
|
840
|
+
'gzipSync', 'gunzipSync', 'deflateSync', 'inflateSync', 'deflateRawSync', 'inflateRawSync', 'unzipSync',
|
|
841
|
+
'createGzip', 'createGunzip', 'createDeflate', 'createInflate', 'createDeflateRaw', 'createInflateRaw'
|
|
842
|
+
];
|
|
843
|
+
if (hostZlib) {
|
|
844
|
+
for (const n of names) {
|
|
845
|
+
if (typeof hostZlib[n] === 'function') VirtualZlib[n] = hostZlib[n].bind(hostZlib);
|
|
846
|
+
}
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const asyncVariant = (format, kind) => (data, optsOrCb, maybeCb) => {
|
|
850
|
+
const cb = typeof optsOrCb === 'function' ? optsOrCb : (typeof maybeCb === 'function' ? maybeCb : null);
|
|
851
|
+
const p = (async () => {
|
|
852
|
+
if (typeof CompressionStream === 'undefined' || typeof DecompressionStream === 'undefined' || typeof Response === 'undefined') {
|
|
853
|
+
throw new Error('zlib.' + kind + ' is not supported in this environment');
|
|
854
|
+
}
|
|
855
|
+
const decompress = /^(gunzip|unzip|inflate)/.test(kind);
|
|
856
|
+
const stream = decompress ? new DecompressionStream(format) : new CompressionStream(format);
|
|
857
|
+
const writer = stream.writable.getWriter();
|
|
858
|
+
const input = data instanceof Uint8Array ? data : VirtualBuffer.from(data);
|
|
859
|
+
writer.write(input);
|
|
860
|
+
writer.close();
|
|
861
|
+
const ab = await new Response(stream.readable).arrayBuffer();
|
|
862
|
+
return VirtualBuffer.from(ab);
|
|
863
|
+
})();
|
|
864
|
+
if (cb) { p.then((out) => cb(null, out), (err) => cb(err)); return undefined; }
|
|
865
|
+
return p;
|
|
866
|
+
};
|
|
867
|
+
VirtualZlib.gzip = asyncVariant('gzip', 'gzip');
|
|
868
|
+
VirtualZlib.gunzip = asyncVariant('gzip', 'gunzip');
|
|
869
|
+
VirtualZlib.unzip = asyncVariant('gzip', 'unzip');
|
|
870
|
+
VirtualZlib.deflate = asyncVariant('deflate', 'deflate');
|
|
871
|
+
VirtualZlib.inflate = asyncVariant('deflate', 'inflate');
|
|
872
|
+
VirtualZlib.deflateRaw = asyncVariant('deflate-raw', 'deflateRaw');
|
|
873
|
+
VirtualZlib.inflateRaw = asyncVariant('deflate-raw', 'inflateRaw');
|
|
874
|
+
const unsupported = (kind) => () => { throw new Error('zlib.' + kind + ' is not supported in a browser worker (use the async API)'); };
|
|
875
|
+
VirtualZlib.gzipSync = unsupported('gzipSync');
|
|
876
|
+
VirtualZlib.gunzipSync = unsupported('gunzipSync');
|
|
877
|
+
VirtualZlib.deflateSync = unsupported('deflateSync');
|
|
878
|
+
VirtualZlib.inflateSync = unsupported('inflateSync');
|
|
879
|
+
VirtualZlib.deflateRawSync = unsupported('deflateRawSync');
|
|
880
|
+
VirtualZlib.inflateRawSync = unsupported('inflateRawSync');
|
|
881
|
+
VirtualZlib.unzipSync = unsupported('unzipSync');
|
|
882
|
+
})();
|
|
883
|
+
|
|
815
884
|
// =========================================================================
|
|
816
885
|
// 4. PATH & OS SHIMS
|
|
817
886
|
// =========================================================================
|
|
@@ -4850,7 +4919,13 @@ function __initVirtualRuntime(rootScope) {
|
|
|
4850
4919
|
return cleaned ? `const { ${cleaned} } = require(${mod.trim()});` : '';
|
|
4851
4920
|
});
|
|
4852
4921
|
code = code.replace(/\bimport\s+([A-Za-z_$][A-Za-z0-9_$]*)\s+from\s+([^\n;]+);?/gm, 'const $1 = (function(m){ return m && m.__esModule ? m.default : m; })(require($2));');
|
|
4853
|
-
|
|
4922
|
+
// Dynamic `import("pkg")` — resolve through the CJS loader instead of the
|
|
4923
|
+
// host's dynamic import, which cannot see the virtual filesystem.
|
|
4924
|
+
code = code.replace(/\bimport\s*\(\s*(\x00__LIT_\d+__\x00)\s*\)/g, 'Promise.resolve().then(() => require($1))');
|
|
4925
|
+
// Side-effect import `import"pkg"` / `import "pkg"`. By this point the
|
|
4926
|
+
// specifier is literal-masked, and minified modules emit no whitespace
|
|
4927
|
+
// between `import` and the string, so `\s*` (not `\s+`) is required.
|
|
4928
|
+
code = code.replace(/\bimport\s*(\x00__LIT_\d+__\x00)\s*;?/gm, 'require($1);');
|
|
4854
4929
|
|
|
4855
4930
|
// Convert ES module exports
|
|
4856
4931
|
const exportedNames = [];
|
|
@@ -4983,8 +5058,12 @@ function __initVirtualRuntime(rootScope) {
|
|
|
4983
5058
|
const builtinSet = new Set([
|
|
4984
5059
|
'fs', 'fs/promises', 'path', 'os', 'crypto', 'zlib', 'http', 'https', 'net',
|
|
4985
5060
|
'dns', 'dns/promises', 'string_decoder', 'child_process', 'process',
|
|
4986
|
-
'assert', 'assert/strict', 'events', 'util', 'url', 'querystring',
|
|
4987
|
-
'stream', 'stream/promises', '
|
|
5061
|
+
'assert', 'assert/strict', 'events', 'util', 'util/types', 'url', 'querystring',
|
|
5062
|
+
'stream', 'stream/promises', 'stream/web', 'stream/consumers', 'test', 'perf_hooks',
|
|
5063
|
+
'timers', 'timers/promises', 'buffer', 'tty', 'tls', 'dgram', 'readline', 'readline/promises',
|
|
5064
|
+
'async_hooks', 'worker_threads', 'v8', 'vm', 'module', 'constants', 'domain',
|
|
5065
|
+
'diagnostics_channel', 'http2', 'cluster', 'repl', 'inspector', 'trace_events',
|
|
5066
|
+
'wasi', 'console',
|
|
4988
5067
|
'bun', 'bun:test', 'bun:sqlite'
|
|
4989
5068
|
]);
|
|
4990
5069
|
|
|
@@ -6894,6 +6973,285 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6894
6973
|
})();
|
|
6895
6974
|
|
|
6896
6975
|
// Built-in Node module table
|
|
6976
|
+
// ── Additional Node builtin shims ────────────────────────────────────────
|
|
6977
|
+
// Widely-used packages require these at load time (e.g. `debug` requires
|
|
6978
|
+
// `tty`). Without an entry `require('tty')` throws MODULE_NOT_FOUND and the
|
|
6979
|
+
// whole app fails to start. Implementations are deliberately minimal but
|
|
6980
|
+
// shape-compatible; anything that genuinely cannot work in the sandbox
|
|
6981
|
+
// throws an explicit, descriptive error rather than silently misbehaving.
|
|
6982
|
+
const VirtualTty = {
|
|
6983
|
+
isatty() { return false; },
|
|
6984
|
+
ReadStream: class TtyReadStream extends EventEmitter {},
|
|
6985
|
+
WriteStream: class TtyWriteStream extends EventEmitter {
|
|
6986
|
+
constructor(fd) { super(); this.fd = fd; this.columns = 80; this.rows = 24; this.isTTY = false; }
|
|
6987
|
+
getColorDepth() { return 1; }
|
|
6988
|
+
hasColors() { return false; }
|
|
6989
|
+
cursorTo() { return true; }
|
|
6990
|
+
clearLine() { return true; }
|
|
6991
|
+
moveCursor() { return true; }
|
|
6992
|
+
}
|
|
6993
|
+
};
|
|
6994
|
+
|
|
6995
|
+
function makeReadlineInterface() {
|
|
6996
|
+
const iface = new EventEmitter();
|
|
6997
|
+
iface.terminal = false;
|
|
6998
|
+
iface.line = '';
|
|
6999
|
+
iface.cursor = 0;
|
|
7000
|
+
iface.question = (query, cb) => { if (typeof cb === 'function') queueMicrotask(() => cb('')); };
|
|
7001
|
+
iface.prompt = () => {};
|
|
7002
|
+
iface.setPrompt = () => {};
|
|
7003
|
+
iface.getPrompt = () => '';
|
|
7004
|
+
iface.write = () => {};
|
|
7005
|
+
iface.pause = () => iface;
|
|
7006
|
+
iface.resume = () => iface;
|
|
7007
|
+
iface.close = () => { queueMicrotask(() => iface.emit('close')); return iface; };
|
|
7008
|
+
iface[Symbol.asyncIterator] = async function* () {};
|
|
7009
|
+
return iface;
|
|
7010
|
+
}
|
|
7011
|
+
const VirtualReadline = {
|
|
7012
|
+
createInterface: makeReadlineInterface,
|
|
7013
|
+
Interface: class ReadlineInterface extends EventEmitter {},
|
|
7014
|
+
clearLine: () => true,
|
|
7015
|
+
clearScreenDown: () => true,
|
|
7016
|
+
cursorTo: () => true,
|
|
7017
|
+
moveCursor: () => true,
|
|
7018
|
+
emitKeypressEvents: () => {}
|
|
7019
|
+
};
|
|
7020
|
+
const VirtualReadlinePromises = {
|
|
7021
|
+
createInterface: () => {
|
|
7022
|
+
const iface = makeReadlineInterface();
|
|
7023
|
+
iface.question = () => Promise.resolve('');
|
|
7024
|
+
return iface;
|
|
7025
|
+
},
|
|
7026
|
+
Interface: class ReadlinePromisesInterface extends EventEmitter {}
|
|
7027
|
+
};
|
|
7028
|
+
|
|
7029
|
+
const VirtualAsyncHooks = {
|
|
7030
|
+
AsyncLocalStorage: class AsyncLocalStorage {
|
|
7031
|
+
constructor() { this._store = undefined; }
|
|
7032
|
+
getStore() { return this._store; }
|
|
7033
|
+
run(store, fn, ...args) {
|
|
7034
|
+
const prev = this._store;
|
|
7035
|
+
this._store = store;
|
|
7036
|
+
try { return fn(...args); } finally { this._store = prev; }
|
|
7037
|
+
}
|
|
7038
|
+
exit(fn, ...args) {
|
|
7039
|
+
const prev = this._store;
|
|
7040
|
+
this._store = undefined;
|
|
7041
|
+
try { return fn(...args); } finally { this._store = prev; }
|
|
7042
|
+
}
|
|
7043
|
+
enterWith(store) { this._store = store; }
|
|
7044
|
+
disable() { this._store = undefined; }
|
|
7045
|
+
},
|
|
7046
|
+
AsyncResource: class AsyncResource {
|
|
7047
|
+
constructor(type) { this.type = type || 'AsyncResource'; }
|
|
7048
|
+
runInAsyncScope(fn, thisArg, ...args) { return fn.apply(thisArg, args); }
|
|
7049
|
+
emitDestroy() { return this; }
|
|
7050
|
+
asyncId() { return 0; }
|
|
7051
|
+
triggerAsyncId() { return 0; }
|
|
7052
|
+
static bind(fn) { return fn; }
|
|
7053
|
+
},
|
|
7054
|
+
createHook() { return { enable() {}, disable() {} }; },
|
|
7055
|
+
executionAsyncId() { return 0; },
|
|
7056
|
+
triggerAsyncId() { return 0; },
|
|
7057
|
+
executionAsyncResource() { return null; }
|
|
7058
|
+
};
|
|
7059
|
+
|
|
7060
|
+
const VirtualWorkerThreads = {
|
|
7061
|
+
isMainThread: true,
|
|
7062
|
+
threadId: 0,
|
|
7063
|
+
parentPort: null,
|
|
7064
|
+
workerData: null,
|
|
7065
|
+
resourceLimits: {},
|
|
7066
|
+
SHARE_ENV: Symbol('nodejs.worker_threads.SHARE_ENV'),
|
|
7067
|
+
receiveMessageOnPort() { return undefined; },
|
|
7068
|
+
Worker: class Worker extends EventEmitter {
|
|
7069
|
+
constructor(filename) {
|
|
7070
|
+
super();
|
|
7071
|
+
this.threadId = -1;
|
|
7072
|
+
this.filename = filename;
|
|
7073
|
+
queueMicrotask(() => this.emit('error', new Error('worker_threads.Worker is not supported in the virtual runtime.')));
|
|
7074
|
+
}
|
|
7075
|
+
postMessage() {}
|
|
7076
|
+
terminate() { return Promise.resolve(0); }
|
|
7077
|
+
ref() { return this; }
|
|
7078
|
+
unref() { return this; }
|
|
7079
|
+
},
|
|
7080
|
+
MessageChannel: class MessageChannel {},
|
|
7081
|
+
MessagePort: class MessagePort extends EventEmitter {}
|
|
7082
|
+
};
|
|
7083
|
+
|
|
7084
|
+
const VirtualV8 = {
|
|
7085
|
+
serialize(value) { return VirtualBuffer.from(JSON.stringify(value === undefined ? null : value), 'utf8'); },
|
|
7086
|
+
deserialize(buf) { try { return JSON.parse(String(buf)); } catch (_) { return undefined; } },
|
|
7087
|
+
getHeapStatistics() {
|
|
7088
|
+
return {
|
|
7089
|
+
total_heap_size: 0, total_heap_size_executable: 0, total_physical_size: 0,
|
|
7090
|
+
total_available_size: 0, used_heap_size: 0, heap_size_limit: 0,
|
|
7091
|
+
malloced_memory: 0, peak_malloced_memory: 0, does_zap_garbage: 0,
|
|
7092
|
+
number_of_native_contexts: 1, number_of_detached_contexts: 0
|
|
7093
|
+
};
|
|
7094
|
+
},
|
|
7095
|
+
getHeapSpaceStatistics() { return []; },
|
|
7096
|
+
setFlagsFromString() {},
|
|
7097
|
+
cachedDataVersionTag() { return 0; },
|
|
7098
|
+
Serializer: class Serializer {
|
|
7099
|
+
constructor() { this._value = undefined; }
|
|
7100
|
+
writeHeader() {}
|
|
7101
|
+
writeValue(value) { this._value = value; }
|
|
7102
|
+
releaseBuffer() { return VirtualBuffer.from(JSON.stringify(this._value === undefined ? null : this._value), 'utf8'); }
|
|
7103
|
+
},
|
|
7104
|
+
Deserializer: class Deserializer {
|
|
7105
|
+
constructor(buffer) { this._buffer = buffer; }
|
|
7106
|
+
readHeader() { return true; }
|
|
7107
|
+
readValue() { try { return JSON.parse(String(this._buffer)); } catch (_) { return undefined; } }
|
|
7108
|
+
}
|
|
7109
|
+
};
|
|
7110
|
+
|
|
7111
|
+
const VirtualVm = {
|
|
7112
|
+
createContext(sandbox) { return sandbox && typeof sandbox === 'object' ? sandbox : {}; },
|
|
7113
|
+
isContext() { return false; },
|
|
7114
|
+
createScript() { throw new Error('vm code compilation is not supported in the virtual runtime.'); },
|
|
7115
|
+
runInContext() { throw new Error('vm.runInContext is not supported in the virtual runtime.'); },
|
|
7116
|
+
runInNewContext() { throw new Error('vm.runInNewContext is not supported in the virtual runtime.'); },
|
|
7117
|
+
runInThisContext() { throw new Error('vm.runInThisContext is not supported in the virtual runtime.'); },
|
|
7118
|
+
compileFunction() { throw new Error('vm.compileFunction is not supported in the virtual runtime.'); },
|
|
7119
|
+
Script: class Script {
|
|
7120
|
+
runInThisContext() { throw new Error('vm.Script is not supported in the virtual runtime.'); }
|
|
7121
|
+
runInContext() { throw new Error('vm.Script is not supported in the virtual runtime.'); }
|
|
7122
|
+
runInNewContext() { throw new Error('vm.Script is not supported in the virtual runtime.'); }
|
|
7123
|
+
}
|
|
7124
|
+
};
|
|
7125
|
+
|
|
7126
|
+
const VirtualDomain = {
|
|
7127
|
+
create() {
|
|
7128
|
+
const d = new EventEmitter();
|
|
7129
|
+
d.members = [];
|
|
7130
|
+
d.add = () => d;
|
|
7131
|
+
d.remove = () => d;
|
|
7132
|
+
d.bind = (fn) => fn;
|
|
7133
|
+
d.intercept = (fn) => fn;
|
|
7134
|
+
d.run = (fn, ...args) => fn(...args);
|
|
7135
|
+
d.dispose = () => d;
|
|
7136
|
+
return d;
|
|
7137
|
+
},
|
|
7138
|
+
createDomain() { return VirtualDomain.create(); }
|
|
7139
|
+
};
|
|
7140
|
+
|
|
7141
|
+
const VirtualDiagnosticsChannel = {
|
|
7142
|
+
_channels: new Map(),
|
|
7143
|
+
channel(name) {
|
|
7144
|
+
const key = String(name);
|
|
7145
|
+
if (!VirtualDiagnosticsChannel._channels.has(key)) {
|
|
7146
|
+
const ch = new EventEmitter();
|
|
7147
|
+
ch.name = key;
|
|
7148
|
+
ch.hasSubscribers = false;
|
|
7149
|
+
ch.subscribe = () => { ch.hasSubscribers = true; };
|
|
7150
|
+
ch.unsubscribe = () => { ch.hasSubscribers = false; };
|
|
7151
|
+
VirtualDiagnosticsChannel._channels.set(key, ch);
|
|
7152
|
+
}
|
|
7153
|
+
return VirtualDiagnosticsChannel._channels.get(key);
|
|
7154
|
+
},
|
|
7155
|
+
subscribe(name, cb) {
|
|
7156
|
+
const ch = VirtualDiagnosticsChannel.channel(name);
|
|
7157
|
+
ch.subscribe();
|
|
7158
|
+
if (typeof cb === 'function') ch.on('message', cb);
|
|
7159
|
+
},
|
|
7160
|
+
unsubscribe(name) { VirtualDiagnosticsChannel.channel(name).unsubscribe(); },
|
|
7161
|
+
Channel: class Channel extends EventEmitter {}
|
|
7162
|
+
};
|
|
7163
|
+
|
|
7164
|
+
const notSupported = (what) => () => { throw new Error(what + ' is not supported in the virtual runtime.'); };
|
|
7165
|
+
const VirtualTls = {
|
|
7166
|
+
DEFAULT_MIN_VERSION: 'TLSv1.2',
|
|
7167
|
+
DEFAULT_MAX_VERSION: 'TLSv1.3',
|
|
7168
|
+
rootCertificates: [],
|
|
7169
|
+
createSecureContext() { return { context: {} }; },
|
|
7170
|
+
SecureContext: class SecureContext {},
|
|
7171
|
+
TLSSocket: class TLSSocket extends EventEmitter {},
|
|
7172
|
+
Server: class TLSServer extends EventEmitter {},
|
|
7173
|
+
checkServerIdentity() { return undefined; },
|
|
7174
|
+
connect: notSupported('tls.connect'),
|
|
7175
|
+
createServer: notSupported('tls.createServer')
|
|
7176
|
+
};
|
|
7177
|
+
const VirtualDgram = {
|
|
7178
|
+
createSocket(type) {
|
|
7179
|
+
const sock = new EventEmitter();
|
|
7180
|
+
sock.type = type || 'udp4';
|
|
7181
|
+
sock.bind = (...args) => { const cb = args[args.length - 1]; if (typeof cb === 'function') queueMicrotask(cb); return sock; };
|
|
7182
|
+
sock.close = (cb) => { queueMicrotask(() => { sock.emit('close'); if (typeof cb === 'function') cb(); }); return sock; };
|
|
7183
|
+
sock.send = notSupported('dgram.send');
|
|
7184
|
+
sock.address = () => ({ address: '0.0.0.0', family: 'IPv4', port: 0 });
|
|
7185
|
+
sock.setBroadcast = () => sock;
|
|
7186
|
+
sock.setTTL = () => sock;
|
|
7187
|
+
sock.addMembership = () => {};
|
|
7188
|
+
sock.dropMembership = () => {};
|
|
7189
|
+
return sock;
|
|
7190
|
+
},
|
|
7191
|
+
Socket: class Socket extends EventEmitter {}
|
|
7192
|
+
};
|
|
7193
|
+
const VirtualHttp2 = {
|
|
7194
|
+
constants: { NGHTTP2_REFUSED_STREAM: 7, NGHTTP2_CANCEL: 8 },
|
|
7195
|
+
connect: notSupported('http2.connect'),
|
|
7196
|
+
createServer: notSupported('http2.createServer'),
|
|
7197
|
+
createSecureServer: notSupported('http2.createSecureServer')
|
|
7198
|
+
};
|
|
7199
|
+
const VirtualCluster = {
|
|
7200
|
+
isPrimary: true,
|
|
7201
|
+
isMaster: true,
|
|
7202
|
+
isWorker: false,
|
|
7203
|
+
workers: {},
|
|
7204
|
+
fork: notSupported('cluster.fork'),
|
|
7205
|
+
setupPrimary: notSupported('cluster.setupPrimary'),
|
|
7206
|
+
setupMaster: notSupported('cluster.setupMaster'),
|
|
7207
|
+
disconnect: () => {}
|
|
7208
|
+
};
|
|
7209
|
+
const VirtualRepl = { start: notSupported('repl.start') };
|
|
7210
|
+
const VirtualInspector = {
|
|
7211
|
+
open: () => null,
|
|
7212
|
+
close: () => {},
|
|
7213
|
+
url: () => '',
|
|
7214
|
+
Session: class Session { connect() {} disconnect() {} post() {} }
|
|
7215
|
+
};
|
|
7216
|
+
const VirtualTraceEvents = {
|
|
7217
|
+
createTracing: () => ({ enable() {}, disable() {} }),
|
|
7218
|
+
getEnabledCategories: () => ''
|
|
7219
|
+
};
|
|
7220
|
+
const VirtualWasi = {
|
|
7221
|
+
WASI: class WASI { constructor() { throw new Error('wasi is not supported in the virtual runtime.'); } }
|
|
7222
|
+
};
|
|
7223
|
+
|
|
7224
|
+
const VirtualStreamWeb = {
|
|
7225
|
+
ReadableStream: typeof ReadableStream !== 'undefined' ? ReadableStream : undefined,
|
|
7226
|
+
WritableStream: typeof WritableStream !== 'undefined' ? WritableStream : undefined,
|
|
7227
|
+
TransformStream: typeof TransformStream !== 'undefined' ? TransformStream : undefined
|
|
7228
|
+
};
|
|
7229
|
+
async function consumeStream(kind, stream) {
|
|
7230
|
+
const chunks = [];
|
|
7231
|
+
if (stream && typeof stream[Symbol.asyncIterator] === 'function') {
|
|
7232
|
+
for await (const chunk of stream) chunks.push(chunk);
|
|
7233
|
+
} else if (stream && typeof stream.on === 'function') {
|
|
7234
|
+
await new Promise((resolve, reject) => {
|
|
7235
|
+
stream.on('data', (c) => chunks.push(c));
|
|
7236
|
+
stream.on('end', resolve);
|
|
7237
|
+
stream.on('error', reject);
|
|
7238
|
+
});
|
|
7239
|
+
}
|
|
7240
|
+
const bufs = chunks.map((c) => (typeof c === 'string' ? VirtualBuffer.from(c) : VirtualBuffer.from(c)));
|
|
7241
|
+
const buf = VirtualBuffer.concat(bufs);
|
|
7242
|
+
if (kind === 'buffer') return buf;
|
|
7243
|
+
if (kind === 'arrayBuffer') return buf.buffer ? buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength) : new ArrayBuffer(0);
|
|
7244
|
+
if (kind === 'text') return buf.toString('utf8');
|
|
7245
|
+
if (kind === 'json') return JSON.parse(buf.toString('utf8'));
|
|
7246
|
+
return buf;
|
|
7247
|
+
}
|
|
7248
|
+
const VirtualStreamConsumers = {
|
|
7249
|
+
text: (s) => consumeStream('text', s),
|
|
7250
|
+
json: (s) => consumeStream('json', s),
|
|
7251
|
+
buffer: (s) => consumeStream('buffer', s),
|
|
7252
|
+
arrayBuffer: (s) => consumeStream('arrayBuffer', s)
|
|
7253
|
+
};
|
|
7254
|
+
|
|
6897
7255
|
const builtinModules = {
|
|
6898
7256
|
fs: vfs,
|
|
6899
7257
|
'node:fs': vfs,
|
|
@@ -6954,8 +7312,58 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6954
7312
|
bun: BunObj,
|
|
6955
7313
|
'node:bun': BunObj,
|
|
6956
7314
|
'bun:test': bunTestModule,
|
|
6957
|
-
'bun:sqlite': { Database: SqliteDatabase }
|
|
7315
|
+
'bun:sqlite': { Database: SqliteDatabase },
|
|
7316
|
+
tty: VirtualTty,
|
|
7317
|
+
tls: VirtualTls,
|
|
7318
|
+
dgram: VirtualDgram,
|
|
7319
|
+
readline: VirtualReadline,
|
|
7320
|
+
'readline/promises': VirtualReadlinePromises,
|
|
7321
|
+
async_hooks: VirtualAsyncHooks,
|
|
7322
|
+
worker_threads: VirtualWorkerThreads,
|
|
7323
|
+
v8: VirtualV8,
|
|
7324
|
+
vm: VirtualVm,
|
|
7325
|
+
domain: VirtualDomain,
|
|
7326
|
+
diagnostics_channel: VirtualDiagnosticsChannel,
|
|
7327
|
+
http2: VirtualHttp2,
|
|
7328
|
+
cluster: VirtualCluster,
|
|
7329
|
+
repl: VirtualRepl,
|
|
7330
|
+
inspector: VirtualInspector,
|
|
7331
|
+
trace_events: VirtualTraceEvents,
|
|
7332
|
+
wasi: VirtualWasi,
|
|
7333
|
+
constants: vfs.constants,
|
|
7334
|
+
'util/types': VirtualUtil.types,
|
|
7335
|
+
'stream/web': VirtualStreamWeb,
|
|
7336
|
+
'stream/consumers': VirtualStreamConsumers
|
|
7337
|
+
};
|
|
7338
|
+
|
|
7339
|
+
// Auto-alias every builtin under the `node:` prefix (node:tty, node:readline…)
|
|
7340
|
+
// so both spellings resolve identically without hand-maintaining two lists.
|
|
7341
|
+
for (const __builtinName of Object.keys(builtinModules)) {
|
|
7342
|
+
if (!__builtinName.startsWith('node:') && !__builtinName.startsWith('bun:')) {
|
|
7343
|
+
builtinModules['node:' + __builtinName] = builtinModules[__builtinName];
|
|
7344
|
+
}
|
|
7345
|
+
}
|
|
7346
|
+
|
|
7347
|
+
// `module` must reference the now-complete builtin table, so it is attached
|
|
7348
|
+
// after the object literal above.
|
|
7349
|
+
const VirtualModule = {
|
|
7350
|
+
builtinModules: Object.keys(builtinModules),
|
|
7351
|
+
Module: class Module {},
|
|
7352
|
+
isBuiltin(name) { return Object.prototype.hasOwnProperty.call(builtinModules, String(name)); },
|
|
7353
|
+
createRequire(from) {
|
|
7354
|
+
const base = typeof from === 'string' ? from : '/workspace';
|
|
7355
|
+
const dir = /\.(?:js|mjs|cjs|ts|json)$/.test(base) ? VirtualPath.dirname(base) : base;
|
|
7356
|
+
const req = (id) => {
|
|
7357
|
+
if (Object.prototype.hasOwnProperty.call(builtinModules, id)) return builtinModules[id];
|
|
7358
|
+
return loadModule(resolveModulePath(id, dir), false);
|
|
7359
|
+
};
|
|
7360
|
+
req.resolve = (id) => resolveModulePath(id, dir);
|
|
7361
|
+
req.cache = {};
|
|
7362
|
+
return req;
|
|
7363
|
+
}
|
|
6958
7364
|
};
|
|
7365
|
+
builtinModules.module = VirtualModule;
|
|
7366
|
+
builtinModules['node:module'] = VirtualModule;
|
|
6959
7367
|
|
|
6960
7368
|
const moduleCache = new Map();
|
|
6961
7369
|
let mainModule = null;
|