Skip to content

[wrangler] Support source phase imports#12996

Merged
petebacondarwin merged 3 commits intomainfrom
fix/wrangler-source-phase-imports-12995
Mar 25, 2026
Merged

[wrangler] Support source phase imports#12996
petebacondarwin merged 3 commits intomainfrom
fix/wrangler-source-phase-imports-12995

Conversation

@guybedford
Copy link
Copy Markdown
Contributor

@guybedford guybedford commented Mar 21, 2026

Fixes #12995.

Wrangler's shared esbuild config targeted es2024 without enabling source phase import syntax, which caused import source Wasm imports to fail before Wrangler could preserve them in deploy output.

This enables esbuild's import-source syntax support in Wrangler's shared build options so source phase Wasm imports work in both bundled and --no-bundle deploy paths. It also adds regression coverage for worker format detection, wrangler deploy --no-bundle --dry-run, and bundled deploy output written via --outdir and --outfile.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this fixes Wrangler's handling of an existing Wasm import syntax without changing the documented API.

A small sea otter successfully carrying a very important pebble.

@guybedford guybedford requested a review from a team as a code owner March 21, 2026 00:44
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 21, 2026

🦋 Changeset detected

Latest commit: ef02bad

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 21, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 21, 2026

✅ All changesets look good

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 21, 2026

The review is complete. Let me analyze the changes:

  1. COMMON_ESBUILD_OPTIONS at bundle.ts:49 adds supported: { "import-source": true } — this tells esbuild to recognize source phase import syntax.

  2. guess-worker-format.ts:27 already spreads ...COMMON_ESBUILD_OPTIONS, so it automatically picks up the new supported field. This fixes the format detection path.

  3. bundle.ts:388 explicitly passes supported: COMMON_ESBUILD_OPTIONS.supported in the bundleWorker build options. This fixes the --no-bundle deploy path.

  4. Tests cover both the format detection path and the --no-bundle --dry-run deploy path.

The fix is correct and minimal:

  • guess-worker-format.ts uses spread so it inherits supported automatically — no change needed.
  • bundleWorker doesn't spread COMMON_ESBUILD_OPTIONS; it picks fields individually. The PR correctly adds the supported field alongside the existing target and loader references.
  • The changeset is properly scoped as a patch to wrangler.
  • Tests are well-targeted regression tests.

LGTM

github run

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 21, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12996

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12996

miniflare

npm i https://pkg.pr.new/miniflare@12996

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12996

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12996

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12996

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12996

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12996

wrangler

npm i https://pkg.pr.new/wrangler@12996

commit: ef02bad

@guybedford guybedford changed the title [wrangler] Fix no-bundle source phase imports [wrangler] Support source phase imports Mar 21, 2026
@guybedford guybedford force-pushed the fix/wrangler-source-phase-imports-12995 branch from cbfae6c to ef02bad Compare March 23, 2026 18:32
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 25, 2026
@petebacondarwin petebacondarwin merged commit f6cdab2 into main Mar 25, 2026
60 of 62 checks passed
@petebacondarwin petebacondarwin deleted the fix/wrangler-source-phase-imports-12995 branch March 25, 2026 17:50
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 25, 2026
guybedford added a commit that referenced this pull request Apr 2, 2026
Fixes module parsing to support the TC39 source phase imports proposal
(`import source wasm from './module.wasm'`), which is required for
WebAssembly ESM integration.

Follow-up to #12996 which added wrangler support. Part of #12995.

Changes:
- Add acorn-import-phases dependency to parse import source syntax
- Extend acorn Parser with the import phases plugin in modules.ts
- Add test for source phase imports parsing
guybedford added a commit that referenced this pull request Apr 2, 2026
Fixes module parsing to support the TC39 source phase imports proposal
(`import source wasm from './module.wasm'`), which is required for
WebAssembly ESM integration.

Follow-up to #12996 which added wrangler support. Part of #12995.

Changes:
- Add acorn-import-phases dependency to parse import source syntax
- Extend acorn Parser with the import phases plugin in modules.ts
- Add test for source phase imports parsing
guybedford added a commit that referenced this pull request Apr 2, 2026
Fixes module parsing to support the TC39 source phase imports proposal
(`import source wasm from './module.wasm'`), which is required for
WebAssembly ESM integration.

Follow-up to #12996 which added wrangler support. Part of #12995.

Changes:
- Add acorn-import-phases dependency to parse import source syntax
- Extend acorn Parser with the import phases plugin in modules.ts
- Add test for source phase imports parsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Source Phase Imports support

3 participants