@ricsam/quickjs-runtime 0.2.3 → 0.2.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.
- package/README.md +25 -3
- package/dist/cjs/index.cjs +19 -1
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/index.mjs +23 -1
- package/dist/mjs/index.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/index.d.ts +21 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -6,18 +6,40 @@ Umbrella package that combines all APIs.
|
|
|
6
6
|
import { setupRuntime } from "@ricsam/quickjs-runtime";
|
|
7
7
|
|
|
8
8
|
const handle = setupRuntime(context, {
|
|
9
|
+
// Fetch API - pass true for defaults or options object
|
|
9
10
|
fetch: {
|
|
10
11
|
onFetch: async (req) => fetch(req),
|
|
11
12
|
},
|
|
13
|
+
// File System API
|
|
12
14
|
fs: {
|
|
13
15
|
getDirectory: async (path) => createNodeDirectoryHandle(`./sandbox${path}`),
|
|
14
16
|
},
|
|
17
|
+
// Console API - pass true for defaults or options with handlers
|
|
18
|
+
console: {
|
|
19
|
+
handlers: {
|
|
20
|
+
onLog: (level, args) => console.log(`[${level}]`, ...args),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
// Encoding API (atob/btoa) - pass true to enable
|
|
24
|
+
encoding: true,
|
|
15
25
|
});
|
|
16
26
|
|
|
17
27
|
// Access individual handles
|
|
18
|
-
handle.core;
|
|
19
|
-
handle.fetch;
|
|
20
|
-
handle.fs;
|
|
28
|
+
handle.core; // CoreHandle (always present)
|
|
29
|
+
handle.fetch; // FetchHandle (if enabled)
|
|
30
|
+
handle.fs; // FsHandle (if enabled)
|
|
31
|
+
handle.console; // ConsoleHandle (if enabled)
|
|
32
|
+
handle.encoding; // EncodingHandle (if enabled)
|
|
21
33
|
|
|
22
34
|
handle.dispose(); // Cleanup all
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Quick enable with defaults:**
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const handle = setupRuntime(context, {
|
|
41
|
+
fetch: true, // Enable fetch with default options
|
|
42
|
+
console: true, // Enable console with no handlers (silent)
|
|
43
|
+
encoding: true, // Enable atob/btoa
|
|
44
|
+
});
|
|
23
45
|
```
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -51,16 +51,22 @@ __export(exports_src, {
|
|
|
51
51
|
});
|
|
52
52
|
module.exports = __toCommonJS(exports_src);
|
|
53
53
|
__reExport(exports_src, require("@ricsam/quickjs-core"), module.exports);
|
|
54
|
+
__reExport(exports_src, require("@ricsam/quickjs-console"), module.exports);
|
|
55
|
+
__reExport(exports_src, require("@ricsam/quickjs-encoding"), module.exports);
|
|
54
56
|
__reExport(exports_src, require("@ricsam/quickjs-fetch"), module.exports);
|
|
55
57
|
__reExport(exports_src, require("@ricsam/quickjs-fs"), module.exports);
|
|
56
58
|
var import_quickjs_core = require("@ricsam/quickjs-core");
|
|
57
59
|
var import_quickjs_fetch = require("@ricsam/quickjs-fetch");
|
|
58
60
|
var import_quickjs_fs = require("@ricsam/quickjs-fs");
|
|
61
|
+
var import_quickjs_console = require("@ricsam/quickjs-console");
|
|
62
|
+
var import_quickjs_encoding = require("@ricsam/quickjs-encoding");
|
|
59
63
|
function setupRuntime(context, options = {}) {
|
|
60
64
|
const stateMap = import_quickjs_core.createStateMap();
|
|
61
65
|
const core = import_quickjs_core.setupCore(context, { stateMap });
|
|
62
66
|
let fetch;
|
|
63
67
|
let fs;
|
|
68
|
+
let consoleHandle;
|
|
69
|
+
let encoding;
|
|
64
70
|
if (options.fetch) {
|
|
65
71
|
const fetchOptions = options.fetch === true ? { stateMap, coreHandle: core } : { ...options.fetch, stateMap, coreHandle: core };
|
|
66
72
|
fetch = import_quickjs_fetch.setupFetch(context, fetchOptions);
|
|
@@ -72,12 +78,24 @@ function setupRuntime(context, options = {}) {
|
|
|
72
78
|
coreHandle: core
|
|
73
79
|
});
|
|
74
80
|
}
|
|
81
|
+
if (options.console) {
|
|
82
|
+
const consoleOptions = options.console === true ? { stateMap, coreHandle: core } : { ...options.console, stateMap, coreHandle: core };
|
|
83
|
+
consoleHandle = import_quickjs_console.setupConsole(context, consoleOptions);
|
|
84
|
+
}
|
|
85
|
+
if (options.encoding) {
|
|
86
|
+
const encodingOptions = options.encoding === true ? { stateMap, coreHandle: core } : { ...options.encoding, stateMap, coreHandle: core };
|
|
87
|
+
encoding = import_quickjs_encoding.setupEncoding(context, encodingOptions);
|
|
88
|
+
}
|
|
75
89
|
return {
|
|
76
90
|
core,
|
|
77
91
|
fetch,
|
|
78
92
|
fs,
|
|
93
|
+
console: consoleHandle,
|
|
94
|
+
encoding,
|
|
79
95
|
stateMap,
|
|
80
96
|
dispose() {
|
|
97
|
+
encoding?.dispose();
|
|
98
|
+
consoleHandle?.dispose();
|
|
81
99
|
fs?.dispose();
|
|
82
100
|
fetch?.dispose();
|
|
83
101
|
core.dispose();
|
|
@@ -86,4 +104,4 @@ function setupRuntime(context, options = {}) {
|
|
|
86
104
|
}
|
|
87
105
|
})
|
|
88
106
|
|
|
89
|
-
//# debugId=
|
|
107
|
+
//# debugId=338B0AA07E15C13A64756E2164756E21
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// Re-export everything from sub-packages\nexport * from \"@ricsam/quickjs-core\";\nexport * from \"@ricsam/quickjs-fetch\";\nexport * from \"@ricsam/quickjs-fs\";\n\nimport type { QuickJSContext } from \"quickjs-emscripten\";\nimport {\n setupCore,\n createStateMap,\n type StateMap,\n type CoreHandle,\n} from \"@ricsam/quickjs-core\";\nimport {\n setupFetch,\n type SetupFetchOptions,\n type FetchHandle,\n} from \"@ricsam/quickjs-fetch\";\nimport {\n setupFs,\n type SetupFsOptions,\n type FsHandle,\n} from \"@ricsam/quickjs-fs\";\n\n/**\n * Options for setting up the runtime\n */\nexport interface SetupRuntimeOptions {\n /**\n * Fetch API options\n * Pass `true` to enable with defaults\n * Pass `false` or omit to disable\n */\n fetch?: SetupFetchOptions | boolean;\n\n /**\n * File system options\n * Pass options object to enable\n * Pass `false` or omit to disable\n */\n fs?: SetupFsOptions | false;\n}\n\n/**\n * Handle returned from setupRuntime\n */\nexport interface RuntimeHandle {\n /** Core handle (always present) */\n core: CoreHandle;\n\n /** Fetch handle (if enabled) */\n fetch?: FetchHandle;\n\n /** File system handle (if enabled) */\n fs?: FsHandle;\n\n /** Shared state map */\n readonly stateMap: StateMap;\n\n /** Dispose all handles and cleanup */\n dispose(): void;\n}\n\n/**\n * Setup multiple APIs in a QuickJS context\n *\n * @example\n * const handle = setupRuntime(context, {\n * fetch: {\n * onFetch: async (req) => fetch(req),\n * },\n * fs: {\n * getDirectory: async (path) => createNodeDirectoryHandle(`/sandbox${path}`),\n * },\n * });\n *\n * // Use the context...\n *\n * handle.dispose();\n */\nexport function setupRuntime(\n context: QuickJSContext,\n options: SetupRuntimeOptions = {}\n): RuntimeHandle {\n const stateMap = createStateMap();\n\n // Always setup core\n const core = setupCore(context, { stateMap });\n\n let fetch: FetchHandle | undefined;\n let fs: FsHandle | undefined;\n\n // Setup fetch if enabled\n if (options.fetch) {\n const fetchOptions: SetupFetchOptions =\n options.fetch === true\n ? { stateMap, coreHandle: core }\n : { ...options.fetch, stateMap, coreHandle: core };\n\n fetch = setupFetch(context, fetchOptions);\n }\n\n // Setup fs if provided\n if (options.fs) {\n fs = setupFs(context, {\n ...options.fs,\n stateMap,\n coreHandle: core,\n });\n }\n\n return {\n core,\n fetch,\n fs,\n stateMap,\n dispose() {\n fs?.dispose();\n fetch?.dispose();\n core.dispose();\n },\n };\n}\n"
|
|
5
|
+
"// Re-export everything from sub-packages\nexport * from \"@ricsam/quickjs-core\";\nexport * from \"@ricsam/quickjs-console\";\nexport * from \"@ricsam/quickjs-encoding\";\nexport * from \"@ricsam/quickjs-fetch\";\nexport * from \"@ricsam/quickjs-fs\";\n\nimport type { QuickJSContext } from \"quickjs-emscripten\";\nimport {\n setupCore,\n createStateMap,\n type StateMap,\n type CoreHandle,\n} from \"@ricsam/quickjs-core\";\nimport {\n setupFetch,\n type SetupFetchOptions,\n type FetchHandle,\n} from \"@ricsam/quickjs-fetch\";\nimport {\n setupFs,\n type SetupFsOptions,\n type FsHandle,\n} from \"@ricsam/quickjs-fs\";\nimport {\n setupConsole,\n type SetupConsoleOptions,\n type ConsoleHandle,\n} from \"@ricsam/quickjs-console\";\nimport {\n setupEncoding,\n type SetupEncodingOptions,\n type EncodingHandle,\n} from \"@ricsam/quickjs-encoding\";\n\n/**\n * Options for setting up the runtime\n */\nexport interface SetupRuntimeOptions {\n /**\n * Fetch API options\n * Pass `true` to enable with defaults\n * Pass `false` or omit to disable\n */\n fetch?: SetupFetchOptions | boolean;\n\n /**\n * File system options\n * Pass options object to enable\n * Pass `false` or omit to disable\n */\n fs?: SetupFsOptions | false;\n\n /**\n * Console options\n * Pass `true` to enable with defaults\n * Pass handlers object to customize\n * Pass `false` or omit to disable\n */\n console?: SetupConsoleOptions | boolean;\n\n /**\n * Encoding options (atob/btoa)\n * Pass `true` to enable with defaults\n * Pass `false` or omit to disable\n */\n encoding?: SetupEncodingOptions | boolean;\n}\n\n/**\n * Handle returned from setupRuntime\n */\nexport interface RuntimeHandle {\n /** Core handle (always present) */\n core: CoreHandle;\n\n /** Fetch handle (if enabled) */\n fetch?: FetchHandle;\n\n /** File system handle (if enabled) */\n fs?: FsHandle;\n\n /** Console handle (if enabled) */\n console?: ConsoleHandle;\n\n /** Encoding handle (if enabled) */\n encoding?: EncodingHandle;\n\n /** Shared state map */\n readonly stateMap: StateMap;\n\n /** Dispose all handles and cleanup */\n dispose(): void;\n}\n\n/**\n * Setup multiple APIs in a QuickJS context\n *\n * @example\n * const handle = setupRuntime(context, {\n * fetch: {\n * onFetch: async (req) => fetch(req),\n * },\n * fs: {\n * getDirectory: async (path) => createNodeDirectoryHandle(`/sandbox${path}`),\n * },\n * });\n *\n * // Use the context...\n *\n * handle.dispose();\n */\nexport function setupRuntime(\n context: QuickJSContext,\n options: SetupRuntimeOptions = {}\n): RuntimeHandle {\n const stateMap = createStateMap();\n\n // Always setup core\n const core = setupCore(context, { stateMap });\n\n let fetch: FetchHandle | undefined;\n let fs: FsHandle | undefined;\n let consoleHandle: ConsoleHandle | undefined;\n let encoding: EncodingHandle | undefined;\n\n // Setup fetch if enabled\n if (options.fetch) {\n const fetchOptions: SetupFetchOptions =\n options.fetch === true\n ? { stateMap, coreHandle: core }\n : { ...options.fetch, stateMap, coreHandle: core };\n\n fetch = setupFetch(context, fetchOptions);\n }\n\n // Setup fs if provided\n if (options.fs) {\n fs = setupFs(context, {\n ...options.fs,\n stateMap,\n coreHandle: core,\n });\n }\n\n // Setup console if enabled\n if (options.console) {\n const consoleOptions: SetupConsoleOptions =\n options.console === true\n ? { stateMap, coreHandle: core }\n : { ...options.console, stateMap, coreHandle: core };\n\n consoleHandle = setupConsole(context, consoleOptions);\n }\n\n // Setup encoding if enabled\n if (options.encoding) {\n const encodingOptions: SetupEncodingOptions =\n options.encoding === true\n ? { stateMap, coreHandle: core }\n : { ...options.encoding, stateMap, coreHandle: core };\n\n encoding = setupEncoding(context, encodingOptions);\n }\n\n return {\n core,\n fetch,\n fs,\n console: consoleHandle,\n encoding,\n stateMap,\n dispose() {\n // Dispose in reverse order of setup\n encoding?.dispose();\n consoleHandle?.dispose();\n fs?.dispose();\n fetch?.dispose();\n core.dispose();\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AACA;AACA;AAQO,IALP;AAUO,IAJP;AASO,IAJP;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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O,QAAQ;AAAA,MACf,KAAK,QAAQ;AAAA;AAAA,EAEjB;AAAA;",
|
|
8
|
+
"debugId": "338B0AA07E15C13A64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/cjs/package.json
CHANGED
package/dist/mjs/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/runtime/src/index.ts
|
|
3
3
|
export * from "@ricsam/quickjs-core";
|
|
4
|
+
export * from "@ricsam/quickjs-console";
|
|
5
|
+
export * from "@ricsam/quickjs-encoding";
|
|
4
6
|
export * from "@ricsam/quickjs-fetch";
|
|
5
7
|
export * from "@ricsam/quickjs-fs";
|
|
6
8
|
import {
|
|
@@ -13,11 +15,19 @@ import {
|
|
|
13
15
|
import {
|
|
14
16
|
setupFs
|
|
15
17
|
} from "@ricsam/quickjs-fs";
|
|
18
|
+
import {
|
|
19
|
+
setupConsole
|
|
20
|
+
} from "@ricsam/quickjs-console";
|
|
21
|
+
import {
|
|
22
|
+
setupEncoding
|
|
23
|
+
} from "@ricsam/quickjs-encoding";
|
|
16
24
|
function setupRuntime(context, options = {}) {
|
|
17
25
|
const stateMap = createStateMap();
|
|
18
26
|
const core = setupCore(context, { stateMap });
|
|
19
27
|
let fetch;
|
|
20
28
|
let fs;
|
|
29
|
+
let consoleHandle;
|
|
30
|
+
let encoding;
|
|
21
31
|
if (options.fetch) {
|
|
22
32
|
const fetchOptions = options.fetch === true ? { stateMap, coreHandle: core } : { ...options.fetch, stateMap, coreHandle: core };
|
|
23
33
|
fetch = setupFetch(context, fetchOptions);
|
|
@@ -29,12 +39,24 @@ function setupRuntime(context, options = {}) {
|
|
|
29
39
|
coreHandle: core
|
|
30
40
|
});
|
|
31
41
|
}
|
|
42
|
+
if (options.console) {
|
|
43
|
+
const consoleOptions = options.console === true ? { stateMap, coreHandle: core } : { ...options.console, stateMap, coreHandle: core };
|
|
44
|
+
consoleHandle = setupConsole(context, consoleOptions);
|
|
45
|
+
}
|
|
46
|
+
if (options.encoding) {
|
|
47
|
+
const encodingOptions = options.encoding === true ? { stateMap, coreHandle: core } : { ...options.encoding, stateMap, coreHandle: core };
|
|
48
|
+
encoding = setupEncoding(context, encodingOptions);
|
|
49
|
+
}
|
|
32
50
|
return {
|
|
33
51
|
core,
|
|
34
52
|
fetch,
|
|
35
53
|
fs,
|
|
54
|
+
console: consoleHandle,
|
|
55
|
+
encoding,
|
|
36
56
|
stateMap,
|
|
37
57
|
dispose() {
|
|
58
|
+
encoding?.dispose();
|
|
59
|
+
consoleHandle?.dispose();
|
|
38
60
|
fs?.dispose();
|
|
39
61
|
fetch?.dispose();
|
|
40
62
|
core.dispose();
|
|
@@ -45,4 +67,4 @@ export {
|
|
|
45
67
|
setupRuntime
|
|
46
68
|
};
|
|
47
69
|
|
|
48
|
-
//# debugId=
|
|
70
|
+
//# debugId=4A2F7A5BFA9F294A64756E2164756E21
|
package/dist/mjs/index.mjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// Re-export everything from sub-packages\nexport * from \"@ricsam/quickjs-core\";\nexport * from \"@ricsam/quickjs-fetch\";\nexport * from \"@ricsam/quickjs-fs\";\n\nimport type { QuickJSContext } from \"quickjs-emscripten\";\nimport {\n setupCore,\n createStateMap,\n type StateMap,\n type CoreHandle,\n} from \"@ricsam/quickjs-core\";\nimport {\n setupFetch,\n type SetupFetchOptions,\n type FetchHandle,\n} from \"@ricsam/quickjs-fetch\";\nimport {\n setupFs,\n type SetupFsOptions,\n type FsHandle,\n} from \"@ricsam/quickjs-fs\";\n\n/**\n * Options for setting up the runtime\n */\nexport interface SetupRuntimeOptions {\n /**\n * Fetch API options\n * Pass `true` to enable with defaults\n * Pass `false` or omit to disable\n */\n fetch?: SetupFetchOptions | boolean;\n\n /**\n * File system options\n * Pass options object to enable\n * Pass `false` or omit to disable\n */\n fs?: SetupFsOptions | false;\n}\n\n/**\n * Handle returned from setupRuntime\n */\nexport interface RuntimeHandle {\n /** Core handle (always present) */\n core: CoreHandle;\n\n /** Fetch handle (if enabled) */\n fetch?: FetchHandle;\n\n /** File system handle (if enabled) */\n fs?: FsHandle;\n\n /** Shared state map */\n readonly stateMap: StateMap;\n\n /** Dispose all handles and cleanup */\n dispose(): void;\n}\n\n/**\n * Setup multiple APIs in a QuickJS context\n *\n * @example\n * const handle = setupRuntime(context, {\n * fetch: {\n * onFetch: async (req) => fetch(req),\n * },\n * fs: {\n * getDirectory: async (path) => createNodeDirectoryHandle(`/sandbox${path}`),\n * },\n * });\n *\n * // Use the context...\n *\n * handle.dispose();\n */\nexport function setupRuntime(\n context: QuickJSContext,\n options: SetupRuntimeOptions = {}\n): RuntimeHandle {\n const stateMap = createStateMap();\n\n // Always setup core\n const core = setupCore(context, { stateMap });\n\n let fetch: FetchHandle | undefined;\n let fs: FsHandle | undefined;\n\n // Setup fetch if enabled\n if (options.fetch) {\n const fetchOptions: SetupFetchOptions =\n options.fetch === true\n ? { stateMap, coreHandle: core }\n : { ...options.fetch, stateMap, coreHandle: core };\n\n fetch = setupFetch(context, fetchOptions);\n }\n\n // Setup fs if provided\n if (options.fs) {\n fs = setupFs(context, {\n ...options.fs,\n stateMap,\n coreHandle: core,\n });\n }\n\n return {\n core,\n fetch,\n fs,\n stateMap,\n dispose() {\n fs?.dispose();\n fetch?.dispose();\n core.dispose();\n },\n };\n}\n"
|
|
5
|
+
"// Re-export everything from sub-packages\nexport * from \"@ricsam/quickjs-core\";\nexport * from \"@ricsam/quickjs-console\";\nexport * from \"@ricsam/quickjs-encoding\";\nexport * from \"@ricsam/quickjs-fetch\";\nexport * from \"@ricsam/quickjs-fs\";\n\nimport type { QuickJSContext } from \"quickjs-emscripten\";\nimport {\n setupCore,\n createStateMap,\n type StateMap,\n type CoreHandle,\n} from \"@ricsam/quickjs-core\";\nimport {\n setupFetch,\n type SetupFetchOptions,\n type FetchHandle,\n} from \"@ricsam/quickjs-fetch\";\nimport {\n setupFs,\n type SetupFsOptions,\n type FsHandle,\n} from \"@ricsam/quickjs-fs\";\nimport {\n setupConsole,\n type SetupConsoleOptions,\n type ConsoleHandle,\n} from \"@ricsam/quickjs-console\";\nimport {\n setupEncoding,\n type SetupEncodingOptions,\n type EncodingHandle,\n} from \"@ricsam/quickjs-encoding\";\n\n/**\n * Options for setting up the runtime\n */\nexport interface SetupRuntimeOptions {\n /**\n * Fetch API options\n * Pass `true` to enable with defaults\n * Pass `false` or omit to disable\n */\n fetch?: SetupFetchOptions | boolean;\n\n /**\n * File system options\n * Pass options object to enable\n * Pass `false` or omit to disable\n */\n fs?: SetupFsOptions | false;\n\n /**\n * Console options\n * Pass `true` to enable with defaults\n * Pass handlers object to customize\n * Pass `false` or omit to disable\n */\n console?: SetupConsoleOptions | boolean;\n\n /**\n * Encoding options (atob/btoa)\n * Pass `true` to enable with defaults\n * Pass `false` or omit to disable\n */\n encoding?: SetupEncodingOptions | boolean;\n}\n\n/**\n * Handle returned from setupRuntime\n */\nexport interface RuntimeHandle {\n /** Core handle (always present) */\n core: CoreHandle;\n\n /** Fetch handle (if enabled) */\n fetch?: FetchHandle;\n\n /** File system handle (if enabled) */\n fs?: FsHandle;\n\n /** Console handle (if enabled) */\n console?: ConsoleHandle;\n\n /** Encoding handle (if enabled) */\n encoding?: EncodingHandle;\n\n /** Shared state map */\n readonly stateMap: StateMap;\n\n /** Dispose all handles and cleanup */\n dispose(): void;\n}\n\n/**\n * Setup multiple APIs in a QuickJS context\n *\n * @example\n * const handle = setupRuntime(context, {\n * fetch: {\n * onFetch: async (req) => fetch(req),\n * },\n * fs: {\n * getDirectory: async (path) => createNodeDirectoryHandle(`/sandbox${path}`),\n * },\n * });\n *\n * // Use the context...\n *\n * handle.dispose();\n */\nexport function setupRuntime(\n context: QuickJSContext,\n options: SetupRuntimeOptions = {}\n): RuntimeHandle {\n const stateMap = createStateMap();\n\n // Always setup core\n const core = setupCore(context, { stateMap });\n\n let fetch: FetchHandle | undefined;\n let fs: FsHandle | undefined;\n let consoleHandle: ConsoleHandle | undefined;\n let encoding: EncodingHandle | undefined;\n\n // Setup fetch if enabled\n if (options.fetch) {\n const fetchOptions: SetupFetchOptions =\n options.fetch === true\n ? { stateMap, coreHandle: core }\n : { ...options.fetch, stateMap, coreHandle: core };\n\n fetch = setupFetch(context, fetchOptions);\n }\n\n // Setup fs if provided\n if (options.fs) {\n fs = setupFs(context, {\n ...options.fs,\n stateMap,\n coreHandle: core,\n });\n }\n\n // Setup console if enabled\n if (options.console) {\n const consoleOptions: SetupConsoleOptions =\n options.console === true\n ? { stateMap, coreHandle: core }\n : { ...options.console, stateMap, coreHandle: core };\n\n consoleHandle = setupConsole(context, consoleOptions);\n }\n\n // Setup encoding if enabled\n if (options.encoding) {\n const encodingOptions: SetupEncodingOptions =\n options.encoding === true\n ? { stateMap, coreHandle: core }\n : { ...options.encoding, stateMap, coreHandle: core };\n\n encoding = setupEncoding(context, encodingOptions);\n }\n\n return {\n core,\n fetch,\n fs,\n console: consoleHandle,\n encoding,\n stateMap,\n dispose() {\n // Dispose in reverse order of setup\n encoding?.dispose();\n consoleHandle?.dispose();\n fs?.dispose();\n fetch?.dispose();\n core.dispose();\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;AACA;AACA;AACA;AAGA;AAAA;AAAA;AAAA;AAMA;AAAA;AAAA;AAKA;AAAA;AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;AACA;AACA;AACA;AACA;AACA;AAGA;AAAA;AAAA;AAAA;AAMA;AAAA;AAAA;AAKA;AAAA;AAAA;AAKA;AAAA;AAAA;AAKA;AAAA;AAAA;AAmFO,SAAS,YAAY,CAC1B,SACA,UAA+B,CAAC,GACjB;AAAA,EACf,MAAM,WAAW,eAAe;AAAA,EAGhC,MAAM,OAAO,UAAU,SAAS,EAAE,SAAS,CAAC;AAAA,EAE5C,IAAI;A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+
export * from "@ricsam/quickjs-console";
|
|
3
|
+
export * from "@ricsam/quickjs-encoding";
|
|
2
4
|
export * from "@ricsam/quickjs-fetch";
|
|
3
5
|
export * from "@ricsam/quickjs-fs";
|
|
4
6
|
import type { QuickJSContext } from "quickjs-emscripten";
|
|
5
7
|
import { type StateMap, type CoreHandle } from "@ricsam/quickjs-core";
|
|
6
8
|
import { type SetupFetchOptions, type FetchHandle } from "@ricsam/quickjs-fetch";
|
|
7
9
|
import { type SetupFsOptions, type FsHandle } from "@ricsam/quickjs-fs";
|
|
10
|
+
import { type SetupConsoleOptions, type ConsoleHandle } from "@ricsam/quickjs-console";
|
|
11
|
+
import { type SetupEncodingOptions, type EncodingHandle } from "@ricsam/quickjs-encoding";
|
|
8
12
|
/**
|
|
9
13
|
* Options for setting up the runtime
|
|
10
14
|
*/
|
|
@@ -21,6 +25,19 @@ export interface SetupRuntimeOptions {
|
|
|
21
25
|
* Pass `false` or omit to disable
|
|
22
26
|
*/
|
|
23
27
|
fs?: SetupFsOptions | false;
|
|
28
|
+
/**
|
|
29
|
+
* Console options
|
|
30
|
+
* Pass `true` to enable with defaults
|
|
31
|
+
* Pass handlers object to customize
|
|
32
|
+
* Pass `false` or omit to disable
|
|
33
|
+
*/
|
|
34
|
+
console?: SetupConsoleOptions | boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Encoding options (atob/btoa)
|
|
37
|
+
* Pass `true` to enable with defaults
|
|
38
|
+
* Pass `false` or omit to disable
|
|
39
|
+
*/
|
|
40
|
+
encoding?: SetupEncodingOptions | boolean;
|
|
24
41
|
}
|
|
25
42
|
/**
|
|
26
43
|
* Handle returned from setupRuntime
|
|
@@ -32,6 +49,10 @@ export interface RuntimeHandle {
|
|
|
32
49
|
fetch?: FetchHandle;
|
|
33
50
|
/** File system handle (if enabled) */
|
|
34
51
|
fs?: FsHandle;
|
|
52
|
+
/** Console handle (if enabled) */
|
|
53
|
+
console?: ConsoleHandle;
|
|
54
|
+
/** Encoding handle (if enabled) */
|
|
55
|
+
encoding?: EncodingHandle;
|
|
35
56
|
/** Shared state map */
|
|
36
57
|
readonly stateMap: StateMap;
|
|
37
58
|
/** Dispose all handles and cleanup */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/quickjs-runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"main": "./dist/cjs/index.cjs",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
"typecheck": "tsc --noEmit"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ricsam/quickjs-core": "^0.2.
|
|
20
|
-
"@ricsam/quickjs-
|
|
21
|
-
"@ricsam/quickjs-
|
|
19
|
+
"@ricsam/quickjs-core": "^0.2.5",
|
|
20
|
+
"@ricsam/quickjs-console": "^0.2.5",
|
|
21
|
+
"@ricsam/quickjs-encoding": "^0.2.5",
|
|
22
|
+
"@ricsam/quickjs-fetch": "^0.2.5",
|
|
23
|
+
"@ricsam/quickjs-fs": "^0.2.5",
|
|
22
24
|
"quickjs-emscripten": "^0.31.0"
|
|
23
25
|
},
|
|
24
26
|
"peerDependencies": {
|