fix(cloudflare): wasm support with dynamic chunks #1957
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π Linked issue
#1952
β Type of 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 usingnew 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 (!) butwrangler 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