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

feat(wasm): support output esm imports #1565

Merged
merged 6 commits into from
Aug 11, 2023
Merged

feat(wasm): support output esm imports #1565

merged 6 commits into from
Aug 11, 2023

Conversation

antfu
Copy link
Member

@antfu antfu commented Aug 11, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

src/rollup/config.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Merging #1565 (fb61060) into main (75ddbf4) will decrease coverage by 0.47%.
Report is 2 commits behind head on main.
The diff coverage is 42.42%.

@@            Coverage Diff             @@
##             main    #1565      +/-   ##
==========================================
- Coverage   76.49%   76.02%   -0.47%     
==========================================
  Files          73       74       +1     
  Lines        7582     7672      +90     
  Branches      752      753       +1     
==========================================
+ Hits         5800     5833      +33     
- Misses       1781     1837      +56     
- Partials        1        2       +1     
Files Changed Coverage Ξ”
src/rollup/plugins/wasm.ts 18.84% <18.84%> (ΓΈ)
src/rollup/config.ts 90.37% <85.71%> (-0.23%) ⬇️
src/presets/cloudflare.ts 100.00% <100.00%> (ΓΈ)
src/types/nitro.ts 100.00% <100.00%> (ΓΈ)

src/rollup/config.ts Outdated Show resolved Hide resolved
src/presets/cloudflare.ts Outdated Show resolved Hide resolved
src/presets/cloudflare.ts Outdated Show resolved Hide resolved
@pi0 pi0 changed the title fix: support wasm for Cloudflare feat(wasm): support output esm imports Aug 11, 2023
@antfu antfu marked this pull request as draft August 11, 2023 15:03
@antfu antfu marked this pull request as ready for review August 11, 2023 15:36
@antfu
Copy link
Member Author

antfu commented Aug 11, 2023

The bundling works, tho the nitro dev doesn't. And it seems to be a rather complex thing to do right, maybe we better keep the experimental state?

@pi0
Copy link
Member

pi0 commented Aug 11, 2023

Working example with wasm bundled mode (Node dev/prod):

export default defineLazyEventHandler(async () => {
  const { sum } = await import("./sum.wasm")
    .then((wasm) => wasm.default({}))
    .then((r) => r.instance.exports);

  return eventHandler((event) => {
    return sum(1, 2);
  });
});

Working example with new esmImport (only prod build with cloudflare pages):

export default defineLazyEventHandler(async () => {
  const { sum } = await import("./sum.wasm")
    .then((mod) => WebAssembly.instantiate(mod.default, {}))
    .then((instance) => instance.exports);

  return eventHandler((event) => {
    return sum(1, 2);
  });
});

I wish we could find a way to keep API consistant

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM. Let's keep it under the experimental flag until we can unify usage across.

@pi0 pi0 merged commit d52ef62 into main Aug 11, 2023
8 of 9 checks passed
@pi0 pi0 deleted the feat/cf-wasm branch August 11, 2023 18:06
@pi0 pi0 mentioned this pull request Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants