@componentor/quickjs-emscripten-core 0.31.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 ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ quickjs-emscripten copyright (c) 2019-2024 Jake Teton-Landis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,341 @@
1
+ <!-- DO NOT EDIT THIS FILE. Edit README.template.md instead. -->
2
+
3
+ # quickjs-emscripten-core
4
+
5
+ This package is part of [quickjs-emscripten](https://github.com/justjakel/quickjs-emscripten), a Javascript interface for QuickJS compiled to WebAssembly via Emscripten.
6
+
7
+ This package (`quickjs-emscripten-core`) contains only Javascript code - no WebAssembly. To use this package, you'll need to install one or more _variants_ of the QuickJS WebAssembly build, see [available variants](#Available-variants) below.
8
+
9
+ ```typescript
10
+ // 1. Import a QuickJS module constructor function from quickjs-emscripten-core
11
+ import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
12
+
13
+ // 2. Import a variant suitable for your use case. For example, if you only care to
14
+ // target with the fastest execution speed, import the release build variant
15
+ import releaseVariant from "@componentor/quickjs-singlefile-cjs-release-sync"
16
+
17
+ // 3. Create the "QuickJS" module that presents the quickjs-emscripten API.
18
+ // Export and use in other files, or consume directly.
19
+ const QuickJS = await newQuickJSWASMModuleFromVariant(releaseVariant)
20
+ ```
21
+
22
+ ## What's a variant?
23
+
24
+ A variant describes how to load a QuickJS WebAssembly build and how to call the low-level C API functions used by the higher-level abstractions in `quickjs-emscripten-core`. A variant is an object with the following properties:
25
+
26
+ ```typescript
27
+ const variant = {
28
+ // This should be `async` if the variant is built with ASYNCIFY
29
+ // so that the WebAssembly module execution can be suspended.
30
+ //
31
+ // Otherwise, this should be `sync`.
32
+ type: "sync",
33
+ // This should be a function that resolves to a QuickJSFFI class.
34
+ importFFI: () => import("something/ffi.ts").then((mod) => mod.QuickJSFFI),
35
+ // This should be a function that resolves to a Emscripten-shaped WASM module factory.
36
+ importModuleLoader: () => import("something/emscripten-module.ts"),
37
+ }
38
+ ```
39
+
40
+ You can provide your own variant to control exactly how the large WebAssembly object is loaded. `quickjs-emscripten-core` will call your variant's importXYZ methods during `newQuickJSWASMModuleFromVariant` or `newQuickJSAsyncWASMModuleFromVariant`.
41
+
42
+ ## Environment-specific variants
43
+
44
+ You can use [subpath imports in package.json](https://nodejs.org/api/packages.html#subpath-imports) to select the appropriate variant for a runtime. This is how the main `quickjs-emscripten` package picks between browser, Node ESM and Node CommonJS variants.
45
+
46
+ ```json
47
+ // in your package.json
48
+ {
49
+ "imports": {
50
+ "#my-quickjs-variant": {
51
+ "types": "@componentor/quickjs-wasmfile-release-sync",
52
+ // In the browser, use the singlefile variant that doesn't need an external file
53
+ "browser": "@componentor/quickjs-singlefile-browser-release-sync",
54
+ // Otherwise, use the wasmfile variant, compatible with all environments
55
+ "default": "@componentor/quickjs-wasmfile-release-sync"
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ ```typescript
62
+ // In your code
63
+ import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
64
+ import variant from "#my-quickjs-variant"
65
+ const QuickJS = await newQuickJSWASMModuleFromVariant(variant)
66
+ ```
67
+
68
+ ## Available variants
69
+
70
+ ### @componentor/quickjs-wasmfile-debug-sync
71
+
72
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-wasmfile-debug-sync/README.md) |
73
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
74
+
75
+ | Variable | Setting | Description |
76
+ | ------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
77
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
78
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
79
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
80
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
81
+ | exports | require import browser workerd | Has these package.json export conditions |
82
+
83
+ ### @componentor/quickjs-wasmfile-debug-asyncify
84
+
85
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-wasmfile-debug-asyncify/README.md) |
86
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
87
+
88
+ | Variable | Setting | Description |
89
+ | ------------------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
90
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
91
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
92
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
93
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
94
+ | exports | require import browser workerd | Has these package.json export conditions |
95
+
96
+ ### @componentor/quickjs-wasmfile-release-sync
97
+
98
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-wasmfile-release-sync/README.md) |
99
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
100
+
101
+ | Variable | Setting | Description |
102
+ | ------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
104
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
105
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
106
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
107
+ | exports | require import browser workerd | Has these package.json export conditions |
108
+
109
+ ### @componentor/quickjs-wasmfile-release-asyncify
110
+
111
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-wasmfile-release-asyncify/README.md) |
112
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
113
+
114
+ | Variable | Setting | Description |
115
+ | ------------------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
116
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
117
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
118
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
119
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
120
+ | exports | require import browser workerd | Has these package.json export conditions |
121
+
122
+ ### @componentor/quickjs-ng-wasmfile-debug-sync
123
+
124
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-ng-wasmfile-debug-sync/README.md) |
125
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
126
+
127
+ | Variable | Setting | Description |
128
+ | ------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
129
+ | library | quickjs-ng | [quickjs-ng](https://github.com/quickjs-ng/quickjs) is a fork of quickjs that tends to add features more quickly. Version [git+7ded62c5](https://github.com/quickjs-ng/quickjs/commit/7ded62c536fca860b8106c39fb75f2df8fe27180) vendored to quickjs-emscripten on 2024-02-12. |
130
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
131
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
132
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
133
+ | exports | require import browser workerd | Has these package.json export conditions |
134
+
135
+ ### @componentor/quickjs-ng-wasmfile-debug-asyncify
136
+
137
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-ng-wasmfile-debug-asyncify/README.md) |
138
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
139
+
140
+ | Variable | Setting | Description |
141
+ | ------------------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
142
+ | library | quickjs-ng | [quickjs-ng](https://github.com/quickjs-ng/quickjs) is a fork of quickjs that tends to add features more quickly. Version [git+7ded62c5](https://github.com/quickjs-ng/quickjs/commit/7ded62c536fca860b8106c39fb75f2df8fe27180) vendored to quickjs-emscripten on 2024-02-12. |
143
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
144
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
145
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
146
+ | exports | require import browser workerd | Has these package.json export conditions |
147
+
148
+ ### @componentor/quickjs-ng-wasmfile-release-sync
149
+
150
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-ng-wasmfile-release-sync/README.md) |
151
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
152
+
153
+ | Variable | Setting | Description |
154
+ | ------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155
+ | library | quickjs-ng | [quickjs-ng](https://github.com/quickjs-ng/quickjs) is a fork of quickjs that tends to add features more quickly. Version [git+7ded62c5](https://github.com/quickjs-ng/quickjs/commit/7ded62c536fca860b8106c39fb75f2df8fe27180) vendored to quickjs-emscripten on 2024-02-12. |
156
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
157
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
158
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
159
+ | exports | require import browser workerd | Has these package.json export conditions |
160
+
161
+ ### @componentor/quickjs-ng-wasmfile-release-asyncify
162
+
163
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-ng-wasmfile-release-asyncify/README.md) |
164
+ Variant with separate .WASM file. Supports browser ESM, NodeJS ESM, and NodeJS CommonJS.
165
+
166
+ | Variable | Setting | Description |
167
+ | ------------------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
168
+ | library | quickjs-ng | [quickjs-ng](https://github.com/quickjs-ng/quickjs) is a fork of quickjs that tends to add features more quickly. Version [git+7ded62c5](https://github.com/quickjs-ng/quickjs/commit/7ded62c536fca860b8106c39fb75f2df8fe27180) vendored to quickjs-emscripten on 2024-02-12. |
169
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
170
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
171
+ | emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
172
+ | exports | require import browser workerd | Has these package.json export conditions |
173
+
174
+ ### @componentor/quickjs-singlefile-cjs-debug-sync
175
+
176
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-cjs-debug-sync/README.md) |
177
+ Variant with the WASM data embedded into a universal (Node and Browser compatible) CommonJS module.
178
+
179
+ | Variable | Setting | Description |
180
+ | ------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
181
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
182
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
183
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
184
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
185
+ | exports | require | Has these package.json export conditions |
186
+
187
+ ### @componentor/quickjs-singlefile-cjs-debug-asyncify
188
+
189
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-cjs-debug-asyncify/README.md) |
190
+ Variant with the WASM data embedded into a universal (Node and Browser compatible) CommonJS module.
191
+
192
+ | Variable | Setting | Description |
193
+ | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
194
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
195
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
196
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
197
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
198
+ | exports | require | Has these package.json export conditions |
199
+
200
+ ### @componentor/quickjs-singlefile-cjs-release-sync
201
+
202
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-cjs-release-sync/README.md) |
203
+ Variant with the WASM data embedded into a universal (Node and Browser compatible) CommonJS module.
204
+
205
+ | Variable | Setting | Description |
206
+ | ------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
207
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
208
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
209
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
210
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
211
+ | exports | require | Has these package.json export conditions |
212
+
213
+ ### @componentor/quickjs-singlefile-cjs-release-asyncify
214
+
215
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-cjs-release-asyncify/README.md) |
216
+ Variant with the WASM data embedded into a universal (Node and Browser compatible) CommonJS module.
217
+
218
+ | Variable | Setting | Description |
219
+ | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
220
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
221
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
222
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
223
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
224
+ | exports | require | Has these package.json export conditions |
225
+
226
+ ### @componentor/quickjs-singlefile-mjs-debug-sync
227
+
228
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-mjs-debug-sync/README.md) |
229
+ Variant with the WASM data embedded into a NodeJS ESModule.
230
+
231
+ | Variable | Setting | Description |
232
+ | ------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
233
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
234
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
235
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
236
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
237
+ | exports | import | Has these package.json export conditions |
238
+
239
+ ### @componentor/quickjs-singlefile-mjs-debug-asyncify
240
+
241
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-mjs-debug-asyncify/README.md) |
242
+ Variant with the WASM data embedded into a NodeJS ESModule.
243
+
244
+ | Variable | Setting | Description |
245
+ | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
246
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
247
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
248
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
249
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
250
+ | exports | import | Has these package.json export conditions |
251
+
252
+ ### @componentor/quickjs-singlefile-mjs-release-sync
253
+
254
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-mjs-release-sync/README.md) |
255
+ Variant with the WASM data embedded into a NodeJS ESModule.
256
+
257
+ | Variable | Setting | Description |
258
+ | ------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
259
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
260
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
261
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
262
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
263
+ | exports | import | Has these package.json export conditions |
264
+
265
+ ### @componentor/quickjs-singlefile-mjs-release-asyncify
266
+
267
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-mjs-release-asyncify/README.md) |
268
+ Variant with the WASM data embedded into a NodeJS ESModule.
269
+
270
+ | Variable | Setting | Description |
271
+ | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
272
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
273
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
274
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
275
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
276
+ | exports | import | Has these package.json export conditions |
277
+
278
+ ### @componentor/quickjs-singlefile-browser-debug-sync
279
+
280
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-browser-debug-sync/README.md) |
281
+ Variant with the WASM data embedded into a browser ESModule.
282
+
283
+ | Variable | Setting | Description |
284
+ | ------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
285
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
286
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
287
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
288
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
289
+ | exports | browser | Has these package.json export conditions |
290
+
291
+ ### @componentor/quickjs-singlefile-browser-debug-asyncify
292
+
293
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-browser-debug-asyncify/README.md) |
294
+ Variant with the WASM data embedded into a browser ESModule.
295
+
296
+ | Variable | Setting | Description |
297
+ | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
298
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
299
+ | releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
300
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
301
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
302
+ | exports | browser | Has these package.json export conditions |
303
+
304
+ ### @componentor/quickjs-singlefile-browser-release-sync
305
+
306
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-browser-release-sync/README.md) |
307
+ Variant with the WASM data embedded into a browser ESModule.
308
+
309
+ | Variable | Setting | Description |
310
+ | ------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
311
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
312
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
313
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
314
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
315
+ | exports | browser | Has these package.json export conditions |
316
+
317
+ ### @componentor/quickjs-singlefile-browser-release-asyncify
318
+
319
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-singlefile-browser-release-asyncify/README.md) |
320
+ Variant with the WASM data embedded into a browser ESModule.
321
+
322
+ | Variable | Setting | Description |
323
+ | ------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
324
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
325
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
326
+ | syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. This imposes substantial size (2x the size of sync) and speed penalties (40% the speed of sync). In return, allows synchronous calls from the QuickJS WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! The [QuickJSAsyncRuntime](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncRuntime.md) and [QuickJSAsyncContext](https://github.com/componentor/quickjs-emscripten/blob/main/doc/quickjs-emscripten/classes/QuickJSAsyncContext.md) classes expose the ASYNCIFY-specific APIs. |
327
+ | emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
328
+ | exports | browser | Has these package.json export conditions |
329
+
330
+ ### @componentor/quickjs-asmjs-mjs-release-sync
331
+
332
+ [Docs](https://github.com/componentor/quickjs-emscripten/blob/main/doc/@componentor/quickjs-asmjs-mjs-release-sync/README.md) |
333
+ Compiled to pure Javascript, no WebAssembly required.
334
+
335
+ | Variable | Setting | Description |
336
+ | ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
337
+ | library | quickjs | The original [bellard/quickjs](https://github.com/bellard/quickjs) library. Version [2024-02-14+36911f0d](https://github.com/bellard/quickjs/commit/36911f0d3ab1a4c190a4d5cbe7c2db225a455389) vendored to quickjs-emscripten on 2024-06-15. |
338
+ | releaseMode | release | Optimized for performance; use when building/deploying your application. |
339
+ | syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
340
+ | emscriptenInclusion | asmjs | The C library code is compiled to Javascript, no WebAssembly used. Sometimes called "asmjs". This is the slowest possible option, and is intended for constrained environments that do not support WebAssembly, like quickjs-for-quickjs. |
341
+ | exports | import | Has these package.json export conditions |
@@ -0,0 +1,70 @@
1
+ <!-- __EDIT_THIS_FILE_NOT_README_MD__ -->
2
+
3
+ # quickjs-emscripten-core
4
+
5
+ This package is part of [quickjs-emscripten](https://github.com/justjakel/quickjs-emscripten), a Javascript interface for QuickJS compiled to WebAssembly via Emscripten.
6
+
7
+ This package (`quickjs-emscripten-core`) contains only Javascript code - no WebAssembly. To use this package, you'll need to install one or more _variants_ of the QuickJS WebAssembly build, see [available variants](#Available-variants) below.
8
+
9
+ ```typescript
10
+ // 1. Import a QuickJS module constructor function from quickjs-emscripten-core
11
+ import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
12
+
13
+ // 2. Import a variant suitable for your use case. For example, if you only care to
14
+ // target with the fastest execution speed, import the release build variant
15
+ import releaseVariant from "@componentor/quickjs-singlefile-cjs-release-sync"
16
+
17
+ // 3. Create the "QuickJS" module that presents the quickjs-emscripten API.
18
+ // Export and use in other files, or consume directly.
19
+ const QuickJS = await newQuickJSWASMModuleFromVariant(releaseVariant)
20
+ ```
21
+
22
+ ## What's a variant?
23
+
24
+ A variant describes how to load a QuickJS WebAssembly build and how to call the low-level C API functions used by the higher-level abstractions in `quickjs-emscripten-core`. A variant is an object with the following properties:
25
+
26
+ ```typescript
27
+ const variant = {
28
+ // This should be `async` if the variant is built with ASYNCIFY
29
+ // so that the WebAssembly module execution can be suspended.
30
+ //
31
+ // Otherwise, this should be `sync`.
32
+ type: "sync",
33
+ // This should be a function that resolves to a QuickJSFFI class.
34
+ importFFI: () => import("something/ffi.ts").then((mod) => mod.QuickJSFFI),
35
+ // This should be a function that resolves to a Emscripten-shaped WASM module factory.
36
+ importModuleLoader: () => import("something/emscripten-module.ts"),
37
+ }
38
+ ```
39
+
40
+ You can provide your own variant to control exactly how the large WebAssembly object is loaded. `quickjs-emscripten-core` will call your variant's importXYZ methods during `newQuickJSWASMModuleFromVariant` or `newQuickJSAsyncWASMModuleFromVariant`.
41
+
42
+ ## Environment-specific variants
43
+
44
+ You can use [subpath imports in package.json](https://nodejs.org/api/packages.html#subpath-imports) to select the appropriate variant for a runtime. This is how the main `quickjs-emscripten` package picks between browser, Node ESM and Node CommonJS variants.
45
+
46
+ ```json
47
+ // in your package.json
48
+ {
49
+ "imports": {
50
+ "#my-quickjs-variant": {
51
+ "types": "@componentor/quickjs-wasmfile-release-sync",
52
+ // In the browser, use the singlefile variant that doesn't need an external file
53
+ "browser": "@componentor/quickjs-singlefile-browser-release-sync",
54
+ // Otherwise, use the wasmfile variant, compatible with all environments
55
+ "default": "@componentor/quickjs-wasmfile-release-sync"
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ ```typescript
62
+ // In your code
63
+ import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
64
+ import variant from "#my-quickjs-variant"
65
+ const QuickJS = await newQuickJSWASMModuleFromVariant(variant)
66
+ ```
67
+
68
+ ## Available variants
69
+
70
+ <!-- __VARIANTS__ -->