You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: allow for use of both manual & fetchEvent based HTTP (#247)
* fix: allow for use of both manual & fetchEvent based HTTP
This commit updates the componentize-js code to support both
fetchEvent and manual based HTTP.
To make this possible we needed to re-introduce a few things:
- A feature that represents fetch-event
- Allow controlling removal of the the built-in fetch event
- Allow skipping checks for manual wasi:http/incoming-handler impls
- Add oxc-parser to detect manual impls and toggle fetch-event feature
The docs are also updated to note the changes to API/usage.
* test: add test case for fetch-event integration
* fix: tests, arg order for splice bindings
* refactor: use sets for features & detected exports
* refactor: remove comment
* chore: fix clippy
* refactor: simplify feature creation
Copy file name to clipboardExpand all lines: README.md
+16-3Lines changed: 16 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -184,16 +184,29 @@ The default set of features includes:
184
184
*`'random'`: Support for cryptographic random, depends on `wasi:random`. **When disabled, random numbers will still be generated but will not be random and instead fully deterministic.**
185
185
*`'clocks'`: Support for clocks and duration polls, depends on `wasi:clocks` and `wasi:io`. **When disabled, using any timer functions like setTimeout or setInterval will panic.**
186
186
*`'http'`: Support for outbound HTTP via the `fetch` global in JS.
187
+
*`'fetch-event'`: Support for `fetch` based incoming request handling (i.e. `addEventListener('fetch', ...)`)
187
188
188
-
Setting `disableFeatures: ['random', 'stdio', 'clocks', 'http']` will disable all features creating a minimal "pure component", that does not depend on any WASI APIs at all and just the target world.
189
+
Setting `disableFeatures: ['random', 'stdio', 'clocks', 'http', 'fetch-event']` will disable all features creating a minimal "pure component", that does not depend on any WASI APIs at all and just the target world.
189
190
190
191
Note that pure components **will not report errors and will instead trap**, so that this should only be enabled after very careful testing.
191
192
192
193
Note that features explicitly imported by the target world cannot be disabled - if you target a component to a world that imports `wasi:clocks`, then `disableFeatures: ['clocks']` will not be supported.
193
194
195
+
Note that depending on your component implementation, some features may be automatically disabled. For example, if using
196
+
`wasi:http/incoming-handler` manually, the `fetch-event` cannot be used.
197
+
194
198
## Using StarlingMonkey's `fetch-event`
195
199
196
-
The StarlingMonkey engine provides the ability to use `fetchEvent` to handle calls to `wasi:http/[email protected]#handle`. When targeting worlds that export `wasi:http/[email protected]` the fetch event will automatically be attached. Alternatively, to override the fetch event with a custom handler, export an explicit `incomingHandler` or `'wasi:http/[email protected]'` object. Using the `fetchEvent` requires enabling the `http` feature.
200
+
The StarlingMonkey engine provides the ability to use `fetchEvent` to handle calls to `wasi:http/[email protected]#handle`.
201
+
202
+
When targeting worlds that export `wasi:http/[email protected]` the fetch event will automatically be attached. Alternatively,
203
+
to override the fetch event with a custom handler, export an explicit `incomingHandler` or `'wasi:http/[email protected]'`
204
+
object. Using the `fetchEvent` requires enabling the `http` feature.
205
+
206
+
> [!WARNING]
207
+
> If using `fetch-event`, ensure that you *do not* manually import (i.e. exporting `incomingHandler` from your ES module).
208
+
>
209
+
> Modules that export `incomingHandler` and have the `http` feature enabled are assumed to be using `wasi:http` manually.
197
210
198
211
## API
199
212
@@ -206,7 +219,7 @@ export function componentize(opts: {
0 commit comments