@scelar/nodepod 1.0.0
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/LICENSE +43 -0
- package/README.md +240 -0
- package/dist/child_process-BJOMsZje.js +8233 -0
- package/dist/child_process-BJOMsZje.js.map +1 -0
- package/dist/child_process-Cj8vOcuc.cjs +7434 -0
- package/dist/child_process-Cj8vOcuc.cjs.map +1 -0
- package/dist/index-Cb1Cgdnd.js +35308 -0
- package/dist/index-Cb1Cgdnd.js.map +1 -0
- package/dist/index-DsMGS-xc.cjs +37195 -0
- package/dist/index-DsMGS-xc.cjs.map +1 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +59 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +95 -0
- package/src/__tests__/smoke.test.ts +11 -0
- package/src/constants/cdn-urls.ts +18 -0
- package/src/constants/config.ts +236 -0
- package/src/cross-origin.ts +26 -0
- package/src/engine-factory.ts +176 -0
- package/src/engine-types.ts +56 -0
- package/src/helpers/byte-encoding.ts +39 -0
- package/src/helpers/digest.ts +9 -0
- package/src/helpers/event-loop.ts +96 -0
- package/src/helpers/wasm-cache.ts +133 -0
- package/src/iframe-sandbox.ts +141 -0
- package/src/index.ts +192 -0
- package/src/isolation-helpers.ts +148 -0
- package/src/memory-volume.ts +941 -0
- package/src/module-transformer.ts +368 -0
- package/src/packages/archive-extractor.ts +248 -0
- package/src/packages/browser-bundler.ts +284 -0
- package/src/packages/installer.ts +396 -0
- package/src/packages/registry-client.ts +131 -0
- package/src/packages/version-resolver.ts +411 -0
- package/src/polyfills/assert.ts +384 -0
- package/src/polyfills/async_hooks.ts +144 -0
- package/src/polyfills/buffer.ts +628 -0
- package/src/polyfills/child_process.ts +2288 -0
- package/src/polyfills/chokidar.ts +336 -0
- package/src/polyfills/cluster.ts +106 -0
- package/src/polyfills/console.ts +136 -0
- package/src/polyfills/constants.ts +123 -0
- package/src/polyfills/crypto.ts +885 -0
- package/src/polyfills/dgram.ts +87 -0
- package/src/polyfills/diagnostics_channel.ts +76 -0
- package/src/polyfills/dns.ts +134 -0
- package/src/polyfills/domain.ts +68 -0
- package/src/polyfills/esbuild.ts +854 -0
- package/src/polyfills/events.ts +276 -0
- package/src/polyfills/fs.ts +2888 -0
- package/src/polyfills/fsevents.ts +79 -0
- package/src/polyfills/http.ts +1449 -0
- package/src/polyfills/http2.ts +199 -0
- package/src/polyfills/https.ts +76 -0
- package/src/polyfills/inspector.ts +62 -0
- package/src/polyfills/lightningcss.ts +105 -0
- package/src/polyfills/module.ts +191 -0
- package/src/polyfills/net.ts +353 -0
- package/src/polyfills/os.ts +238 -0
- package/src/polyfills/path.ts +206 -0
- package/src/polyfills/perf_hooks.ts +102 -0
- package/src/polyfills/process.ts +690 -0
- package/src/polyfills/punycode.ts +159 -0
- package/src/polyfills/querystring.ts +93 -0
- package/src/polyfills/quic.ts +118 -0
- package/src/polyfills/readdirp.ts +229 -0
- package/src/polyfills/readline.ts +692 -0
- package/src/polyfills/repl.ts +134 -0
- package/src/polyfills/rollup.ts +119 -0
- package/src/polyfills/sea.ts +33 -0
- package/src/polyfills/sqlite.ts +78 -0
- package/src/polyfills/stream.ts +1620 -0
- package/src/polyfills/string_decoder.ts +25 -0
- package/src/polyfills/tailwindcss-oxide.ts +309 -0
- package/src/polyfills/test.ts +197 -0
- package/src/polyfills/timers.ts +32 -0
- package/src/polyfills/tls.ts +105 -0
- package/src/polyfills/trace_events.ts +50 -0
- package/src/polyfills/tty.ts +71 -0
- package/src/polyfills/url.ts +174 -0
- package/src/polyfills/util.ts +559 -0
- package/src/polyfills/v8.ts +126 -0
- package/src/polyfills/vm.ts +132 -0
- package/src/polyfills/volume-registry.ts +15 -0
- package/src/polyfills/wasi.ts +44 -0
- package/src/polyfills/worker_threads.ts +326 -0
- package/src/polyfills/ws.ts +595 -0
- package/src/polyfills/zlib.ts +881 -0
- package/src/request-proxy.ts +716 -0
- package/src/script-engine.ts +3375 -0
- package/src/sdk/nodepod-fs.ts +93 -0
- package/src/sdk/nodepod-process.ts +86 -0
- package/src/sdk/nodepod-terminal.ts +350 -0
- package/src/sdk/nodepod.ts +509 -0
- package/src/sdk/types.ts +70 -0
- package/src/shell/commands/bun.ts +121 -0
- package/src/shell/commands/directory.ts +297 -0
- package/src/shell/commands/file-ops.ts +525 -0
- package/src/shell/commands/git.ts +2142 -0
- package/src/shell/commands/node.ts +80 -0
- package/src/shell/commands/npm.ts +198 -0
- package/src/shell/commands/pm-types.ts +45 -0
- package/src/shell/commands/pnpm.ts +82 -0
- package/src/shell/commands/search.ts +264 -0
- package/src/shell/commands/shell-env.ts +352 -0
- package/src/shell/commands/text-processing.ts +1152 -0
- package/src/shell/commands/yarn.ts +84 -0
- package/src/shell/shell-builtins.ts +19 -0
- package/src/shell/shell-helpers.ts +250 -0
- package/src/shell/shell-interpreter.ts +514 -0
- package/src/shell/shell-parser.ts +429 -0
- package/src/shell/shell-types.ts +85 -0
- package/src/syntax-transforms.ts +561 -0
- package/src/threading/engine-worker.ts +64 -0
- package/src/threading/inline-worker.ts +372 -0
- package/src/threading/offload-types.ts +112 -0
- package/src/threading/offload-worker.ts +383 -0
- package/src/threading/offload.ts +271 -0
- package/src/threading/process-context.ts +92 -0
- package/src/threading/process-handle.ts +275 -0
- package/src/threading/process-manager.ts +956 -0
- package/src/threading/process-worker-entry.ts +854 -0
- package/src/threading/shared-vfs.ts +352 -0
- package/src/threading/sync-channel.ts +135 -0
- package/src/threading/task-queue.ts +177 -0
- package/src/threading/vfs-bridge.ts +231 -0
- package/src/threading/worker-pool.ts +233 -0
- package/src/threading/worker-protocol.ts +358 -0
- package/src/threading/worker-vfs.ts +218 -0
- package/src/types/externals.d.ts +38 -0
- package/src/types/fs-streams.ts +142 -0
- package/src/types/manifest.ts +17 -0
- package/src/worker-sandbox.ts +90 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// EventEmitter polyfill -- uses a function constructor (not a class) so that
|
|
2
|
+
// EventEmitter.call(this) and Object.create(EventEmitter.prototype) work.
|
|
3
|
+
// ES6 classes forbid calling without `new`, which breaks tons of npm packages.
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
export type EventHandler = (...args: any[]) => void;
|
|
7
|
+
|
|
8
|
+
const DEFAULT_CEILING = 10;
|
|
9
|
+
|
|
10
|
+
// VFS->chokidar HMR bridge: chokidar's async fs.watch() setup chain doesn't
|
|
11
|
+
// complete in browser, so we detect FSWatchers by _watched Map and bridge
|
|
12
|
+
// VFS file changes directly to the watcher.
|
|
13
|
+
const _vfsBridged = new WeakSet<object>();
|
|
14
|
+
let _vfsBridgeCleanups: (() => void)[] = [];
|
|
15
|
+
|
|
16
|
+
function _bridgeVfsToWatcher(watcher: EventEmitter): void {
|
|
17
|
+
const vol = (globalThis as any).__nodepodVolume;
|
|
18
|
+
if (!vol || typeof vol.onGlobalChange !== 'function') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// debounce per-path to avoid cascading reloads from multiple VFS writes
|
|
23
|
+
const pending = new Map<string, { event: string; timer: ReturnType<typeof setTimeout> }>();
|
|
24
|
+
const DEBOUNCE_MS = 50;
|
|
25
|
+
|
|
26
|
+
const cleanup = vol.onGlobalChange((path: string, event: string) => {
|
|
27
|
+
if (path.includes('/node_modules/') || path.includes('/.cache/')) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const existing = pending.get(path);
|
|
32
|
+
if (existing) clearTimeout(existing.timer);
|
|
33
|
+
|
|
34
|
+
pending.set(path, {
|
|
35
|
+
event,
|
|
36
|
+
timer: setTimeout(() => {
|
|
37
|
+
pending.delete(path);
|
|
38
|
+
if (event === 'change') {
|
|
39
|
+
watcher.emit('change', path);
|
|
40
|
+
} else if (event === 'add') {
|
|
41
|
+
watcher.emit('add', path);
|
|
42
|
+
} else if (event === 'unlink') {
|
|
43
|
+
watcher.emit('unlink', path);
|
|
44
|
+
}
|
|
45
|
+
}, DEBOUNCE_MS),
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
_vfsBridgeCleanups.push(cleanup);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// lazily init the listener map (handles Object.create() bypassing constructor)
|
|
52
|
+
function _reg(self: any): Map<string, EventHandler[]> {
|
|
53
|
+
if (!self._registry) self._registry = new Map<string, EventHandler[]>();
|
|
54
|
+
return self._registry;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function _ensureSlot(self: any, name: string): EventHandler[] {
|
|
58
|
+
const reg = _reg(self);
|
|
59
|
+
let slot = reg.get(name);
|
|
60
|
+
if (!slot) {
|
|
61
|
+
slot = [];
|
|
62
|
+
reg.set(name, slot);
|
|
63
|
+
}
|
|
64
|
+
return slot;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface EventEmitter {
|
|
68
|
+
_registry: Map<string, EventHandler[]>;
|
|
69
|
+
_ceiling: number;
|
|
70
|
+
addListener(name: string, handler: EventHandler): this;
|
|
71
|
+
on(name: string, handler: EventHandler): this;
|
|
72
|
+
once(name: string, handler: EventHandler): this;
|
|
73
|
+
removeListener(name: string, handler: EventHandler): this;
|
|
74
|
+
off(name: string, handler: EventHandler): this;
|
|
75
|
+
removeAllListeners(name?: string): this;
|
|
76
|
+
emit(name: string, ...payload: unknown[]): boolean;
|
|
77
|
+
listeners(name: string): EventHandler[];
|
|
78
|
+
rawListeners(name: string): EventHandler[];
|
|
79
|
+
listenerCount(name: string): number;
|
|
80
|
+
eventNames(): string[];
|
|
81
|
+
setMaxListeners(limit: number): this;
|
|
82
|
+
getMaxListeners(): number;
|
|
83
|
+
prependListener(name: string, handler: EventHandler): this;
|
|
84
|
+
prependOnceListener(name: string, handler: EventHandler): this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface EventEmitterConstructor {
|
|
88
|
+
new(): EventEmitter;
|
|
89
|
+
(): void;
|
|
90
|
+
prototype: EventEmitter;
|
|
91
|
+
EventEmitter: EventEmitterConstructor;
|
|
92
|
+
listenerCount(target: EventEmitter, name: string): number;
|
|
93
|
+
once(target: EventEmitter, name: string): Promise<unknown[]>;
|
|
94
|
+
on(target: EventEmitter, name: string): AsyncIterable<unknown[]>;
|
|
95
|
+
getEventListeners(target: EventEmitter, name: string): EventHandler[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const EventEmitter = function EventEmitter(this: any) {
|
|
99
|
+
// guard against double-init (e.g. super() + EventEmitter.call(this))
|
|
100
|
+
if (this && !this._registry) {
|
|
101
|
+
this._registry = new Map<string, EventHandler[]>();
|
|
102
|
+
}
|
|
103
|
+
if (this && this._ceiling === undefined) {
|
|
104
|
+
this._ceiling = DEFAULT_CEILING;
|
|
105
|
+
}
|
|
106
|
+
} as unknown as EventEmitterConstructor;
|
|
107
|
+
|
|
108
|
+
EventEmitter.prototype.addListener = function addListener(name: string, handler: EventHandler): any {
|
|
109
|
+
const slot = _ensureSlot(this, name);
|
|
110
|
+
slot.push(handler);
|
|
111
|
+
|
|
112
|
+
// VFS->chokidar HMR bridge: detect FSWatcher by _watched Map
|
|
113
|
+
if (name === 'change' && !_vfsBridged.has(this) && (this as any)._watched instanceof Map) {
|
|
114
|
+
_vfsBridged.add(this);
|
|
115
|
+
_bridgeVfsToWatcher(this as any);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return this;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// on and addListener must be the SAME function reference -- if one calls the other,
|
|
122
|
+
// subclass overrides cause infinite recursion
|
|
123
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
124
|
+
|
|
125
|
+
EventEmitter.prototype.once = function once(name: string, handler: EventHandler): any {
|
|
126
|
+
const self = this;
|
|
127
|
+
const wrapper: EventHandler = function (this: any, ...payload: unknown[]) {
|
|
128
|
+
self.removeListener(name, wrapper);
|
|
129
|
+
handler.apply(self, payload);
|
|
130
|
+
};
|
|
131
|
+
// use _ensureSlot directly, not addListener, to avoid recursion
|
|
132
|
+
const slot = _ensureSlot(this, name);
|
|
133
|
+
slot.push(wrapper);
|
|
134
|
+
return this;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
EventEmitter.prototype.removeListener = function removeListener(name: string, handler: EventHandler): any {
|
|
138
|
+
const slot = _reg(this).get(name);
|
|
139
|
+
if (slot) {
|
|
140
|
+
const pos = slot.indexOf(handler);
|
|
141
|
+
if (pos !== -1) {
|
|
142
|
+
slot.splice(pos, 1);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return this;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
149
|
+
|
|
150
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(name?: string): any {
|
|
151
|
+
if (name !== undefined) {
|
|
152
|
+
_reg(this).delete(name);
|
|
153
|
+
} else {
|
|
154
|
+
_reg(this).clear();
|
|
155
|
+
}
|
|
156
|
+
return this;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
EventEmitter.prototype.emit = function emit(name: string, ...payload: unknown[]): boolean {
|
|
160
|
+
const slot = _reg(this).get(name);
|
|
161
|
+
if (!slot || slot.length === 0) {
|
|
162
|
+
if (name === "error") {
|
|
163
|
+
const problem = payload[0];
|
|
164
|
+
if (problem instanceof Error) throw problem;
|
|
165
|
+
throw new Error("Unhandled error event");
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const snapshot = slot.slice();
|
|
171
|
+
for (const handler of snapshot) {
|
|
172
|
+
try {
|
|
173
|
+
handler.apply(this, payload);
|
|
174
|
+
} catch (fault) {
|
|
175
|
+
/* swallow handler errors */
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
EventEmitter.prototype.listeners = function listeners(name: string): EventHandler[] {
|
|
182
|
+
const slot = _reg(this).get(name);
|
|
183
|
+
return slot ? slot.slice() : [];
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
EventEmitter.prototype.rawListeners = function rawListeners(name: string): EventHandler[] {
|
|
187
|
+
return this.listeners(name);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
EventEmitter.prototype.listenerCount = function listenerCount(name: string): number {
|
|
191
|
+
const slot = _reg(this).get(name);
|
|
192
|
+
return slot ? slot.length : 0;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
EventEmitter.prototype.eventNames = function eventNames(): string[] {
|
|
196
|
+
return Array.from(_reg(this).keys());
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(limit: number): any {
|
|
200
|
+
this._ceiling = limit;
|
|
201
|
+
return this;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners(): number {
|
|
205
|
+
return this._ceiling ?? DEFAULT_CEILING;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
EventEmitter.prototype.prependListener = function prependListener(name: string, handler: EventHandler): any {
|
|
209
|
+
const slot = _ensureSlot(this, name);
|
|
210
|
+
slot.unshift(handler);
|
|
211
|
+
return this;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
EventEmitter.prototype.prependOnceListener = function prependOnceListener(name: string, handler: EventHandler): any {
|
|
215
|
+
const self = this;
|
|
216
|
+
const wrapper: EventHandler = function (this: any, ...payload: unknown[]) {
|
|
217
|
+
self.removeListener(name, wrapper);
|
|
218
|
+
handler.apply(self, payload);
|
|
219
|
+
};
|
|
220
|
+
return this.prependListener(name, wrapper);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
EventEmitter.listenerCount = function (target: EventEmitter, name: string): number {
|
|
224
|
+
return target.listenerCount(name);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// supports both `import EventEmitter from 'events'` and `import { EventEmitter }`
|
|
228
|
+
const moduleFacade = EventEmitter as EventEmitterConstructor & {
|
|
229
|
+
EventEmitter: EventEmitterConstructor;
|
|
230
|
+
once: (target: EventEmitter, name: string) => Promise<unknown[]>;
|
|
231
|
+
on: (target: EventEmitter, name: string) => AsyncIterable<unknown[]>;
|
|
232
|
+
getEventListeners: (target: EventEmitter, name: string) => EventHandler[];
|
|
233
|
+
listenerCount: (target: EventEmitter, name: string) => number;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
moduleFacade.EventEmitter = EventEmitter;
|
|
237
|
+
|
|
238
|
+
moduleFacade.once = async (
|
|
239
|
+
target: EventEmitter,
|
|
240
|
+
name: string,
|
|
241
|
+
): Promise<unknown[]> => {
|
|
242
|
+
return new Promise((fulfill, reject) => {
|
|
243
|
+
const onSuccess: EventHandler = (...args: unknown[]) => {
|
|
244
|
+
target.removeListener("error", onFailure);
|
|
245
|
+
fulfill(args);
|
|
246
|
+
};
|
|
247
|
+
const onFailure: EventHandler = (...args: unknown[]) => {
|
|
248
|
+
target.removeListener(name, onSuccess);
|
|
249
|
+
reject(args[0] as Error);
|
|
250
|
+
};
|
|
251
|
+
target.once(name, onSuccess);
|
|
252
|
+
target.once("error", onFailure);
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
moduleFacade.on = (target: EventEmitter, name: string) => {
|
|
257
|
+
const asyncIter = {
|
|
258
|
+
async next() {
|
|
259
|
+
return new Promise<{ value: unknown[]; done: boolean }>((fulfill) => {
|
|
260
|
+
target.once(name, (...args) => fulfill({ value: args, done: false }));
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
[Symbol.asyncIterator]() {
|
|
264
|
+
return this;
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
return asyncIter as AsyncIterable<unknown[]>;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
moduleFacade.getEventListeners = (target: EventEmitter, name: string) =>
|
|
271
|
+
target.listeners(name);
|
|
272
|
+
|
|
273
|
+
moduleFacade.listenerCount = (target: EventEmitter, name: string) =>
|
|
274
|
+
target.listenerCount(name);
|
|
275
|
+
|
|
276
|
+
export default moduleFacade;
|