Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker-build): prevent script will never generate a response #256

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

samdenty
Copy link

@samdenty samdenty commented Dec 31, 2022

This fixes #255

There's no clean way to convert the index_bg.js which contains ESM exports, into a function which is called on each fetch().

So in this PR, I basically split the two parts of the bundle up and move the initialization inside the fetch function, by replacing the INSERT_INIT() token

This is kinda hacky, but it works. It fixes the script will never generate a response errors that can occur when sharing the wasm state across requests.

export * from "./index_bg.js";
export default {
fetch: async (...args) => {
INSERT_INIT();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is replaced in the script below

@@ -130,14 +131,50 @@ fn bundle(esbuild_path: &Path) -> Result<()> {
"--outfile=shim.mjs",
]);

if !no_minify {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't run minify, as we need the non-minified source to run transforms

fs::write(path.join("./shim.mjs"), result)?;

// re-bundle the shim with minification flag
if !no_minify {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we re-run esbuild to minify it

@samdenty
Copy link
Author

samdenty commented Jan 7, 2023

ping @zebp i wonder if you know who to hit up to get this in, this is blocking me from using worker-rs

@zebp
Copy link
Collaborator

zebp commented Jan 7, 2023

ping @zebp i wonder if you know who to hit up to get this in, this is blocking me from using worker-rs

left a reply in the issue

@Smephite
Copy link

Smephite commented Mar 2, 2023

Is there any update on this?


return imports.fetch(...args);
},
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is missing the scheduled entrypoint

@@ -1,7 +1,12 @@
import * as imports from "./index_bg.js";
export * from "./index_bg.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents Durable Objects from being exported no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants