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(cloudflare): wasm support with dynamic chunks #1957

Merged
merged 11 commits into from
Nov 28, 2023
Merged

fix(cloudflare): wasm support with dynamic chunks #1957

merged 11 commits into from
Nov 28, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Nov 28, 2023

πŸ”— Linked issue

#1952

❓ 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

This is almost a rewrite of #1565 in order to support WASM (via native ESM imports) for Cloudflare modules and page environments.

As of #1905, we have enabled dynamic chunks by default for Cloudflare modules and pages. As a result, the wasm imports need to be resolved relative to the chunk paths like ../wasm/* rather than ./wasm/*. This required significant changes.

The rollup preferred way is using File URLs i tried this method but import.meta.ROLLUP_FILE_URL_* if conflicting with nitro plugin today + not sure if using new URL for imports is supported for wrangler static analyzer for .wasm entries. As alternative way, i used an AST parser to post normalize nitro specific ids (\0nitro:wasm\) to real wasm path.

Another note: Since tests enabled, i had pushed two more hooks to the plugin that somehow allows wasm for IIFE preset cloudflare. It shouldn't work (!) but wrangler dev (both local and remote) allows this!

A new importWasm utility is also added to test fixture subject to extract as reusable auto imported util in next iterations.

This PR also fixes windows compatibility issue detected via tests / disabled in e73b849

Tests for workers are still disabled due to the limitations of current setup so i used local tests.

πŸ“ Checklist

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

@pi0 pi0 merged commit 84c5418 into main Nov 28, 2023
5 checks passed
@pi0 pi0 deleted the fix/wasm-chunks branch November 28, 2023 02:13
@pi0 pi0 mentioned this pull request Nov 28, 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.

1 participant