@scelar/nodepod 1.0.3 → 1.0.5

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.
Files changed (55) hide show
  1. package/dist/__sw__.js +642 -642
  2. package/dist/{child_process-hmVqFcF7.cjs → child_process-B9qsOKHs.cjs} +7434 -7434
  3. package/dist/child_process-B9qsOKHs.cjs.map +1 -0
  4. package/dist/{child_process-D6oDN2MX.js → child_process-PY34i_6n.js} +8233 -8233
  5. package/dist/child_process-PY34i_6n.js.map +1 -0
  6. package/dist/{index-BO1i013L.cjs → index-CyhVjVJU.cjs} +38383 -37240
  7. package/dist/index-CyhVjVJU.cjs.map +1 -0
  8. package/dist/index-D8Hn2kWU.js +36455 -0
  9. package/dist/index-D8Hn2kWU.js.map +1 -0
  10. package/dist/index.cjs +67 -65
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +88 -86
  13. package/dist/index.mjs +61 -59
  14. package/dist/memory-handler.d.ts +57 -0
  15. package/dist/memory-volume.d.ts +157 -147
  16. package/dist/packages/installer.d.ts +44 -41
  17. package/dist/persistence/idb-cache.d.ts +7 -0
  18. package/dist/polyfills/wasi.d.ts +45 -4
  19. package/dist/script-engine.d.ts +84 -81
  20. package/dist/sdk/nodepod-process.d.ts +29 -28
  21. package/dist/sdk/nodepod.d.ts +59 -39
  22. package/dist/sdk/types.d.ts +64 -53
  23. package/dist/threading/process-manager.d.ts +1 -1
  24. package/dist/threading/worker-protocol.d.ts +1 -1
  25. package/package.json +1 -1
  26. package/src/index.ts +194 -192
  27. package/src/memory-handler.ts +168 -0
  28. package/src/memory-volume.ts +78 -8
  29. package/src/packages/installer.ts +49 -1
  30. package/src/packages/version-resolver.ts +421 -411
  31. package/src/persistence/idb-cache.ts +107 -0
  32. package/src/polyfills/child_process.ts +2288 -2288
  33. package/src/polyfills/events.ts +6 -2
  34. package/src/polyfills/fs.ts +2888 -2888
  35. package/src/polyfills/http.ts +1450 -1449
  36. package/src/polyfills/process.ts +27 -1
  37. package/src/polyfills/stream.ts +1621 -1620
  38. package/src/polyfills/wasi.ts +1306 -44
  39. package/src/polyfills/zlib.ts +881 -881
  40. package/src/request-proxy.ts +716 -716
  41. package/src/script-engine.ts +444 -118
  42. package/src/sdk/nodepod-process.ts +94 -86
  43. package/src/sdk/nodepod.ts +571 -509
  44. package/src/sdk/types.ts +82 -70
  45. package/src/syntax-transforms.ts +2 -2
  46. package/src/threading/offload-worker.ts +383 -383
  47. package/src/threading/offload.ts +271 -271
  48. package/src/threading/process-manager.ts +967 -956
  49. package/src/threading/process-worker-entry.ts +858 -854
  50. package/src/threading/worker-protocol.ts +358 -358
  51. package/dist/child_process-D6oDN2MX.js.map +0 -1
  52. package/dist/child_process-hmVqFcF7.cjs.map +0 -1
  53. package/dist/index-Ale2oba_.js +0 -35412
  54. package/dist/index-Ale2oba_.js.map +0 -1
  55. package/dist/index-BO1i013L.cjs.map +0 -1
@@ -1,147 +1,157 @@
1
- import type { VolumeSnapshot } from './engine-types';
2
- export interface VolumeNode {
3
- kind: 'file' | 'directory' | 'symlink';
4
- content?: Uint8Array;
5
- children?: Map<string, VolumeNode>;
6
- target?: string;
7
- modified: number;
8
- }
9
- type FileChangeHandler = (filePath: string, content: string) => void;
10
- type FileDeleteHandler = (filePath: string) => void;
11
- export interface FileStat {
12
- isFile(): boolean;
13
- isDirectory(): boolean;
14
- isSymbolicLink(): boolean;
15
- isBlockDevice(): boolean;
16
- isCharacterDevice(): boolean;
17
- isFIFO(): boolean;
18
- isSocket(): boolean;
19
- size: number;
20
- mode: number;
21
- mtime: Date;
22
- atime: Date;
23
- ctime: Date;
24
- birthtime: Date;
25
- mtimeMs: number;
26
- atimeMs: number;
27
- ctimeMs: number;
28
- birthtimeMs: number;
29
- nlink: number;
30
- uid: number;
31
- gid: number;
32
- dev: number;
33
- ino: number;
34
- rdev: number;
35
- blksize: number;
36
- blocks: number;
37
- atimeNs: bigint;
38
- mtimeNs: bigint;
39
- ctimeNs: bigint;
40
- birthtimeNs: bigint;
41
- }
42
- export type WatchEventKind = 'change' | 'rename';
43
- export type WatchCallback = (event: WatchEventKind, name: string | null) => void;
44
- export interface FileWatchHandle {
45
- close(): void;
46
- ref(): this;
47
- unref(): this;
48
- on(event: string, listener: (...args: unknown[]) => void): this;
49
- once(event: string, listener: (...args: unknown[]) => void): this;
50
- removeListener(event: string, listener: (...args: unknown[]) => void): this;
51
- off(event: string, listener: (...args: unknown[]) => void): this;
52
- addListener(event: string, listener: (...args: unknown[]) => void): this;
53
- removeAllListeners(event?: string): this;
54
- emit(event: string, ...args: unknown[]): boolean;
55
- }
56
- export interface SystemError extends Error {
57
- code: string;
58
- errno: number;
59
- syscall: string;
60
- path?: string;
61
- }
62
- export declare function makeSystemError(code: 'ENOENT' | 'ENOTDIR' | 'EISDIR' | 'EEXIST' | 'ENOTEMPTY', syscall: string, targetPath: string, detail?: string): SystemError;
63
- export declare class MemoryVolume {
64
- private tree;
65
- private textEncoder;
66
- private textDecoder;
67
- private activeWatchers;
68
- private subscribers;
69
- constructor();
70
- on(event: 'change', handler: FileChangeHandler): this;
71
- on(event: 'delete', handler: FileDeleteHandler): this;
72
- off(event: 'change', handler: FileChangeHandler): this;
73
- off(event: 'delete', handler: FileDeleteHandler): this;
74
- private broadcast;
75
- toSnapshot(): VolumeSnapshot;
76
- private collectEntries;
77
- static fromBinarySnapshot(snapshot: {
78
- manifest: Array<{
79
- path: string;
80
- offset: number;
81
- length: number;
82
- isDirectory: boolean;
83
- }>;
84
- data: ArrayBuffer;
85
- }): MemoryVolume;
86
- static fromSnapshot(snapshot: VolumeSnapshot): MemoryVolume;
87
- private normalize;
88
- private segments;
89
- private parentOf;
90
- private nameOf;
91
- private locateRaw;
92
- private locate;
93
- private ensureDir;
94
- private writeInternal;
95
- existsSync(p: string): boolean;
96
- statSync(p: string): FileStat;
97
- lstatSync(p: string): FileStat;
98
- readFileSync(p: string): Uint8Array;
99
- readFileSync(p: string, encoding: 'utf8' | 'utf-8'): string;
100
- writeFileSync(p: string, data: string | Uint8Array): void;
101
- mkdirSync(p: string, options?: {
102
- recursive?: boolean;
103
- }): void;
104
- readdirSync(p: string): string[];
105
- unlinkSync(p: string): void;
106
- rmdirSync(p: string): void;
107
- renameSync(from: string, to: string): void;
108
- accessSync(p: string, _mode?: number): void;
109
- copyFileSync(src: string, dest: string): void;
110
- realpathSync(p: string): string;
111
- symlinkSync(target: string, linkPath: string, _type?: string): void;
112
- readlinkSync(p: string): string;
113
- linkSync(existingPath: string, newPath: string): void;
114
- chmodSync(_p: string, _mode: number): void;
115
- chownSync(_p: string, _uid: number, _gid: number): void;
116
- appendFileSync(p: string, data: string | Uint8Array): void;
117
- truncateSync(p: string, len?: number): void;
118
- readFile(p: string, optionsOrCb?: {
119
- encoding?: string;
120
- } | ((err: Error | null, data?: Uint8Array | string) => void), cb?: (err: Error | null, data?: Uint8Array | string) => void): void;
121
- stat(p: string, cb?: (err: Error | null, stats?: FileStat) => void): void;
122
- lstat(p: string, cb?: (err: Error | null, stats?: FileStat) => void): void;
123
- readdir(p: string, optionsOrCb?: {
124
- withFileTypes?: boolean;
125
- } | ((err: Error | null, files?: string[]) => void), cb?: (err: Error | null, files?: string[]) => void): void;
126
- realpath(p: string, cb?: (err: Error | null, resolved?: string) => void): void;
127
- access(p: string, modeOrCb?: number | ((err: Error | null) => void), cb?: (err: Error | null) => void): void;
128
- watch(target: string, optionsOrCb?: {
129
- persistent?: boolean;
130
- recursive?: boolean;
131
- encoding?: string;
132
- } | WatchCallback, cb?: WatchCallback): FileWatchHandle;
133
- private triggerWatchers;
134
- private globalChangeListeners;
135
- onGlobalChange(cb: (path: string, event: string) => void): () => void;
136
- private notifyGlobalListeners;
137
- createReadStream(p: string): {
138
- on: (event: string, cb: (...args: unknown[]) => void) => void;
139
- pipe: (dest: unknown) => unknown;
140
- };
141
- createWriteStream(p: string): {
142
- write: (data: string | Uint8Array) => boolean;
143
- end: (data?: string | Uint8Array) => void;
144
- on: (event: string, cb: (...args: unknown[]) => void) => void;
145
- };
146
- }
147
- export {};
1
+ import type { VolumeSnapshot } from './engine-types';
2
+ import type { MemoryHandler } from './memory-handler';
3
+ export interface VolumeNode {
4
+ kind: 'file' | 'directory' | 'symlink';
5
+ content?: Uint8Array;
6
+ children?: Map<string, VolumeNode>;
7
+ target?: string;
8
+ modified: number;
9
+ }
10
+ type FileChangeHandler = (filePath: string, content: string) => void;
11
+ type FileDeleteHandler = (filePath: string) => void;
12
+ export interface FileStat {
13
+ isFile(): boolean;
14
+ isDirectory(): boolean;
15
+ isSymbolicLink(): boolean;
16
+ isBlockDevice(): boolean;
17
+ isCharacterDevice(): boolean;
18
+ isFIFO(): boolean;
19
+ isSocket(): boolean;
20
+ size: number;
21
+ mode: number;
22
+ mtime: Date;
23
+ atime: Date;
24
+ ctime: Date;
25
+ birthtime: Date;
26
+ mtimeMs: number;
27
+ atimeMs: number;
28
+ ctimeMs: number;
29
+ birthtimeMs: number;
30
+ nlink: number;
31
+ uid: number;
32
+ gid: number;
33
+ dev: number;
34
+ ino: number;
35
+ rdev: number;
36
+ blksize: number;
37
+ blocks: number;
38
+ atimeNs: bigint;
39
+ mtimeNs: bigint;
40
+ ctimeNs: bigint;
41
+ birthtimeNs: bigint;
42
+ }
43
+ export type WatchEventKind = 'change' | 'rename';
44
+ export type WatchCallback = (event: WatchEventKind, name: string | null) => void;
45
+ export interface FileWatchHandle {
46
+ close(): void;
47
+ ref(): this;
48
+ unref(): this;
49
+ on(event: string, listener: (...args: unknown[]) => void): this;
50
+ once(event: string, listener: (...args: unknown[]) => void): this;
51
+ removeListener(event: string, listener: (...args: unknown[]) => void): this;
52
+ off(event: string, listener: (...args: unknown[]) => void): this;
53
+ addListener(event: string, listener: (...args: unknown[]) => void): this;
54
+ removeAllListeners(event?: string): this;
55
+ emit(event: string, ...args: unknown[]): boolean;
56
+ }
57
+ export interface SystemError extends Error {
58
+ code: string;
59
+ errno: number;
60
+ syscall: string;
61
+ path?: string;
62
+ }
63
+ export declare function makeSystemError(code: 'ENOENT' | 'ENOTDIR' | 'EISDIR' | 'EEXIST' | 'ENOTEMPTY', syscall: string, targetPath: string, detail?: string): SystemError;
64
+ export declare class MemoryVolume {
65
+ private tree;
66
+ private textEncoder;
67
+ private textDecoder;
68
+ private activeWatchers;
69
+ private subscribers;
70
+ private _handler;
71
+ constructor(handler?: MemoryHandler | null);
72
+ on(event: 'change', handler: FileChangeHandler): this;
73
+ on(event: 'delete', handler: FileDeleteHandler): this;
74
+ off(event: 'change', handler: FileChangeHandler): this;
75
+ off(event: 'delete', handler: FileDeleteHandler): this;
76
+ private broadcast;
77
+ getStats(): {
78
+ fileCount: number;
79
+ totalBytes: number;
80
+ dirCount: number;
81
+ watcherCount: number;
82
+ };
83
+ /** Clean up all watchers, subscribers, and global listeners. */
84
+ dispose(): void;
85
+ toSnapshot(excludePrefixes?: string[], excludeDirNames?: Set<string>): VolumeSnapshot;
86
+ private collectEntries;
87
+ static fromBinarySnapshot(snapshot: {
88
+ manifest: Array<{
89
+ path: string;
90
+ offset: number;
91
+ length: number;
92
+ isDirectory: boolean;
93
+ }>;
94
+ data: ArrayBuffer;
95
+ }): MemoryVolume;
96
+ static fromSnapshot(snapshot: VolumeSnapshot): MemoryVolume;
97
+ private normalize;
98
+ private segments;
99
+ private parentOf;
100
+ private nameOf;
101
+ private locateRaw;
102
+ private locate;
103
+ private ensureDir;
104
+ private writeInternal;
105
+ existsSync(p: string): boolean;
106
+ statSync(p: string): FileStat;
107
+ lstatSync(p: string): FileStat;
108
+ readFileSync(p: string): Uint8Array;
109
+ readFileSync(p: string, encoding: 'utf8' | 'utf-8'): string;
110
+ writeFileSync(p: string, data: string | Uint8Array): void;
111
+ mkdirSync(p: string, options?: {
112
+ recursive?: boolean;
113
+ }): void;
114
+ readdirSync(p: string): string[];
115
+ unlinkSync(p: string): void;
116
+ rmdirSync(p: string): void;
117
+ renameSync(from: string, to: string): void;
118
+ accessSync(p: string, _mode?: number): void;
119
+ copyFileSync(src: string, dest: string): void;
120
+ realpathSync(p: string): string;
121
+ symlinkSync(target: string, linkPath: string, _type?: string): void;
122
+ readlinkSync(p: string): string;
123
+ linkSync(existingPath: string, newPath: string): void;
124
+ chmodSync(_p: string, _mode: number): void;
125
+ chownSync(_p: string, _uid: number, _gid: number): void;
126
+ appendFileSync(p: string, data: string | Uint8Array): void;
127
+ truncateSync(p: string, len?: number): void;
128
+ readFile(p: string, optionsOrCb?: {
129
+ encoding?: string;
130
+ } | ((err: Error | null, data?: Uint8Array | string) => void), cb?: (err: Error | null, data?: Uint8Array | string) => void): void;
131
+ stat(p: string, cb?: (err: Error | null, stats?: FileStat) => void): void;
132
+ lstat(p: string, cb?: (err: Error | null, stats?: FileStat) => void): void;
133
+ readdir(p: string, optionsOrCb?: {
134
+ withFileTypes?: boolean;
135
+ } | ((err: Error | null, files?: string[]) => void), cb?: (err: Error | null, files?: string[]) => void): void;
136
+ realpath(p: string, cb?: (err: Error | null, resolved?: string) => void): void;
137
+ access(p: string, modeOrCb?: number | ((err: Error | null) => void), cb?: (err: Error | null) => void): void;
138
+ watch(target: string, optionsOrCb?: {
139
+ persistent?: boolean;
140
+ recursive?: boolean;
141
+ encoding?: string;
142
+ } | WatchCallback, cb?: WatchCallback): FileWatchHandle;
143
+ private triggerWatchers;
144
+ private globalChangeListeners;
145
+ onGlobalChange(cb: (path: string, event: string) => void): () => void;
146
+ private notifyGlobalListeners;
147
+ createReadStream(p: string): {
148
+ on: (event: string, cb: (...args: unknown[]) => void) => void;
149
+ pipe: (dest: unknown) => unknown;
150
+ };
151
+ createWriteStream(p: string): {
152
+ write: (data: string | Uint8Array) => boolean;
153
+ end: (data?: string | Uint8Array) => void;
154
+ on: (event: string, cb: (...args: unknown[]) => void) => void;
155
+ };
156
+ }
157
+ export {};
@@ -1,41 +1,44 @@
1
- import { MemoryVolume } from "../memory-volume";
2
- import { RegistryConfig } from "./registry-client";
3
- import { ResolvedDependency } from "./version-resolver";
4
- export interface InstallFlags {
5
- registry?: string;
6
- persist?: boolean;
7
- persistDev?: boolean;
8
- withDevDeps?: boolean;
9
- withOptionalDeps?: boolean;
10
- onProgress?: (message: string) => void;
11
- transformModules?: boolean;
12
- }
13
- export interface InstallOutcome {
14
- resolved: Map<string, ResolvedDependency>;
15
- newPackages: string[];
16
- }
17
- declare function splitSpecifier(spec: string): {
18
- name: string;
19
- version?: string;
20
- };
21
- export declare class DependencyInstaller {
22
- private vol;
23
- private registryClient;
24
- private workingDir;
25
- constructor(vol: MemoryVolume, opts?: {
26
- cwd?: string;
27
- } & RegistryConfig);
28
- install(packageName: string, version?: string, flags?: InstallFlags): Promise<InstallOutcome>;
29
- installFromManifest(manifestPath?: string, flags?: InstallFlags): Promise<InstallOutcome>;
30
- listInstalled(): Record<string, string>;
31
- private materializePackages;
32
- private createBinStubs;
33
- private writeLockFile;
34
- private patchManifest;
35
- }
36
- export declare function install(specifier: string, vol: MemoryVolume, flags?: InstallFlags): Promise<InstallOutcome>;
37
- export { RegistryClient } from "./registry-client";
38
- export type { RegistryConfig, VersionDetail, PackageMetadata, } from "./registry-client";
39
- export type { ResolvedDependency, ResolutionConfig } from "./version-resolver";
40
- export type { ExtractionOptions } from "./archive-extractor";
41
- export { splitSpecifier };
1
+ import { MemoryVolume } from "../memory-volume";
2
+ import { RegistryConfig } from "./registry-client";
3
+ import { ResolvedDependency } from "./version-resolver";
4
+ import type { IDBSnapshotCache } from "../persistence/idb-cache";
5
+ export interface InstallFlags {
6
+ registry?: string;
7
+ persist?: boolean;
8
+ persistDev?: boolean;
9
+ withDevDeps?: boolean;
10
+ withOptionalDeps?: boolean;
11
+ onProgress?: (message: string) => void;
12
+ transformModules?: boolean;
13
+ }
14
+ export interface InstallOutcome {
15
+ resolved: Map<string, ResolvedDependency>;
16
+ newPackages: string[];
17
+ }
18
+ declare function splitSpecifier(spec: string): {
19
+ name: string;
20
+ version?: string;
21
+ };
22
+ export declare class DependencyInstaller {
23
+ private vol;
24
+ private registryClient;
25
+ private workingDir;
26
+ private _snapshotCache;
27
+ constructor(vol: MemoryVolume, opts?: {
28
+ cwd?: string;
29
+ snapshotCache?: IDBSnapshotCache | null;
30
+ } & RegistryConfig);
31
+ install(packageName: string, version?: string, flags?: InstallFlags): Promise<InstallOutcome>;
32
+ installFromManifest(manifestPath?: string, flags?: InstallFlags): Promise<InstallOutcome>;
33
+ listInstalled(): Record<string, string>;
34
+ private materializePackages;
35
+ private createBinStubs;
36
+ private writeLockFile;
37
+ private patchManifest;
38
+ }
39
+ export declare function install(specifier: string, vol: MemoryVolume, flags?: InstallFlags): Promise<InstallOutcome>;
40
+ export { RegistryClient } from "./registry-client";
41
+ export type { RegistryConfig, VersionDetail, PackageMetadata, } from "./registry-client";
42
+ export type { ResolvedDependency, ResolutionConfig } from "./version-resolver";
43
+ export type { ExtractionOptions } from "./archive-extractor";
44
+ export { splitSpecifier };
@@ -0,0 +1,7 @@
1
+ import type { VolumeSnapshot } from '../engine-types';
2
+ export interface IDBSnapshotCache {
3
+ get(packageJsonHash: string): Promise<VolumeSnapshot | null>;
4
+ set(packageJsonHash: string, snapshot: VolumeSnapshot): Promise<void>;
5
+ close(): void;
6
+ }
7
+ export declare function openSnapshotCache(): Promise<IDBSnapshotCache | null>;
@@ -1,12 +1,53 @@
1
+ interface WasiFileStat {
2
+ isFile(): boolean;
3
+ isDirectory(): boolean;
4
+ isSymbolicLink(): boolean;
5
+ size: number;
6
+ mtimeMs: number;
7
+ atimeMs: number;
8
+ ctimeMs: number;
9
+ ino?: number;
10
+ nlink?: number;
11
+ }
12
+ interface WasiFS {
13
+ readFileSync(p: string): Uint8Array;
14
+ writeFileSync(p: string, data: string | Uint8Array): void;
15
+ mkdirSync(p: string, options?: {
16
+ recursive?: boolean;
17
+ }): void;
18
+ statSync(p: string): WasiFileStat;
19
+ readdirSync(p: string): string[];
20
+ unlinkSync(p: string): void;
21
+ rmdirSync(p: string): void;
22
+ renameSync(from: string, to: string): void;
23
+ existsSync(p: string): boolean;
24
+ symlinkSync?(target: string, linkPath: string): void;
25
+ readlinkSync?(p: string): string;
26
+ }
27
+ export declare class ExitStatus extends Error {
28
+ readonly code: number;
29
+ constructor(code: number);
30
+ }
31
+ export interface WASIOptions {
32
+ version?: "preview1" | "unstable";
33
+ args?: string[];
34
+ env?: Record<string, string>;
35
+ preopens?: Record<string, string>;
36
+ returnOnExit?: boolean;
37
+ stdin?: number;
38
+ stdout?: number;
39
+ stderr?: number;
40
+ fs?: WasiFS;
41
+ }
1
42
  export interface WASI {
2
43
  readonly wasiImport: Record<string, Function>;
3
- start(_instance: object): number;
4
- initialize(_instance: object): void;
44
+ start(instance: object): number;
45
+ initialize(instance: object): void;
5
46
  getImportObject(): Record<string, Record<string, Function>>;
6
47
  }
7
48
  interface WASIConstructor {
8
- new (_options?: object): WASI;
9
- (this: any, _options?: object): void;
49
+ new (options?: WASIOptions): WASI;
50
+ (this: any, options?: WASIOptions): void;
10
51
  prototype: any;
11
52
  }
12
53
  export declare const WASI: WASIConstructor;
@@ -1,81 +1,84 @@
1
- import { MemoryVolume } from "./memory-volume";
2
- import type { ExecutionOutcome } from "./engine-types";
3
- import { ProcessObject } from "./polyfills/process";
4
- export declare function setChildProcessPolyfill(mod: any): void;
5
- export interface ModuleRecord {
6
- id: string;
7
- filename: string;
8
- exports: unknown;
9
- loaded: boolean;
10
- children: ModuleRecord[];
11
- paths: string[];
12
- parent: ModuleRecord | null;
13
- }
14
- export interface EngineOptions {
15
- cwd?: string;
16
- env?: Record<string, string>;
17
- onConsole?: (method: string, args: unknown[]) => void;
18
- onStdout?: (data: string) => void;
19
- onStderr?: (data: string) => void;
20
- workerThreadsOverride?: {
21
- isMainThread: boolean;
22
- parentPort: unknown;
23
- workerData: unknown;
24
- threadId: number;
25
- };
26
- }
27
- export interface ResolverFn {
28
- (id: string): unknown;
29
- resolve: (id: string, options?: {
30
- paths?: string[];
31
- }) => string;
32
- cache: Record<string, ModuleRecord>;
33
- extensions: Record<string, unknown>;
34
- main: ModuleRecord | null;
35
- _ownerRecord?: ModuleRecord;
36
- }
37
- export declare class ScriptEngine {
38
- private vol;
39
- private fsBridge;
40
- private proc;
41
- private moduleRegistry;
42
- private opts;
43
- private transformCache;
44
- constructor(vol: MemoryVolume, opts?: EngineOptions);
45
- private patchTextDecoder;
46
- private patchStackTraceApi;
47
- execute(code: string, filename?: string): {
48
- exports: unknown;
49
- module: ModuleRecord;
50
- };
51
- executeSync: (code: string, filename?: string) => {
52
- exports: unknown;
53
- module: ModuleRecord;
54
- };
55
- executeAsync(code: string, filename?: string): Promise<ExecutionOutcome>;
56
- runFile(filename: string): {
57
- exports: unknown;
58
- module: ModuleRecord;
59
- };
60
- runFileSync: (filename: string) => {
61
- exports: unknown;
62
- module: ModuleRecord;
63
- };
64
- runFileTLA(filename: string): Promise<{
65
- exports: unknown;
66
- module: ModuleRecord;
67
- }>;
68
- runFileAsync(filename: string): Promise<ExecutionOutcome>;
69
- clearCache(): void;
70
- getVolume(): MemoryVolume;
71
- getProcess(): ProcessObject;
72
- createREPL(): {
73
- eval: (code: string) => unknown;
74
- };
75
- }
76
- export declare function executeCode(code: string, vol: MemoryVolume, opts?: EngineOptions): {
77
- exports: unknown;
78
- module: ModuleRecord;
79
- };
80
- export type { IScriptEngine, ExecutionOutcome, EngineConfig, } from "./engine-types";
81
- export default ScriptEngine;
1
+ import { MemoryVolume } from "./memory-volume";
2
+ import type { ExecutionOutcome } from "./engine-types";
3
+ import { ProcessObject } from "./polyfills/process";
4
+ export declare function setChildProcessPolyfill(mod: any): void;
5
+ export interface ModuleRecord {
6
+ id: string;
7
+ filename: string;
8
+ exports: unknown;
9
+ loaded: boolean;
10
+ children: ModuleRecord[];
11
+ paths: string[];
12
+ parent: ModuleRecord | null;
13
+ }
14
+ export interface EngineOptions {
15
+ cwd?: string;
16
+ env?: Record<string, string>;
17
+ onConsole?: (method: string, args: unknown[]) => void;
18
+ onStdout?: (data: string) => void;
19
+ onStderr?: (data: string) => void;
20
+ workerThreadsOverride?: {
21
+ isMainThread: boolean;
22
+ parentPort: unknown;
23
+ workerData: unknown;
24
+ threadId: number;
25
+ };
26
+ handler?: import('./memory-handler').MemoryHandler;
27
+ }
28
+ export interface ResolverFn {
29
+ (id: string): unknown;
30
+ resolve: (id: string, options?: {
31
+ paths?: string[];
32
+ }) => string;
33
+ cache: Record<string, ModuleRecord>;
34
+ extensions: Record<string, unknown>;
35
+ main: ModuleRecord | null;
36
+ _ownerRecord?: ModuleRecord;
37
+ }
38
+ export declare class ScriptEngine {
39
+ private vol;
40
+ private fsBridge;
41
+ private proc;
42
+ private moduleRegistry;
43
+ private opts;
44
+ private transformCache;
45
+ constructor(vol: MemoryVolume, opts?: EngineOptions);
46
+ private patchTextDecoder;
47
+ private patchStackTraceApi;
48
+ execute(code: string, filename?: string): {
49
+ exports: unknown;
50
+ module: ModuleRecord;
51
+ };
52
+ executeSync: (code: string, filename?: string) => {
53
+ exports: unknown;
54
+ module: ModuleRecord;
55
+ };
56
+ executeAsync(code: string, filename?: string): Promise<ExecutionOutcome>;
57
+ runFile(filename: string): {
58
+ exports: unknown;
59
+ module: ModuleRecord;
60
+ };
61
+ runFileSync: (filename: string) => {
62
+ exports: unknown;
63
+ module: ModuleRecord;
64
+ };
65
+ runFileTLA(filename: string): Promise<{
66
+ exports: unknown;
67
+ module: ModuleRecord;
68
+ }>;
69
+ runFileAsync(filename: string): Promise<ExecutionOutcome>;
70
+ clearCache(): void;
71
+ /** Evict one node_modules entry when module cache exceeds soft limit. */
72
+ private _trimModuleCache;
73
+ getVolume(): MemoryVolume;
74
+ getProcess(): ProcessObject;
75
+ createREPL(): {
76
+ eval: (code: string) => unknown;
77
+ };
78
+ }
79
+ export declare function executeCode(code: string, vol: MemoryVolume, opts?: EngineOptions): {
80
+ exports: unknown;
81
+ module: ModuleRecord;
82
+ };
83
+ export type { IScriptEngine, ExecutionOutcome, EngineConfig, } from "./engine-types";
84
+ export default ScriptEngine;