Skip to content

Vendor JS files in python workers SDK as esm modules#13311

Merged
petebacondarwin merged 8 commits intomainfrom
gyeongjae/python-module-js-files
Apr 15, 2026
Merged

Vendor JS files in python workers SDK as esm modules#13311
petebacondarwin merged 8 commits intomainfrom
gyeongjae/python-module-js-files

Conversation

@ryanking13
Copy link
Copy Markdown
Contributor

This updates the vendoring logic of Python workers so that we can include some JavaScript files in our Python SDK package.

Currently, all the files in the python_modules directory (packages installed for Python workers) are uploaded as buffer types. But we would like to make some JavaScript files in our SKD package to be uploaded as ESM types so that they can be imported in the runtime.


  • 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 is an internal change for python workers

@ryanking13 ryanking13 requested review from dom96, hoodmane and joesepi April 6, 2026 09:24
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 6, 2026

🦋 Changeset detected

Latest commit: 2c0f85f

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

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 6, 2026

There's a minor edge case: for a file like workers/noext (no extension), lastIndexOf(".") returns -1, and name.slice(-1) returns the last character. However, it won't match any entry in VENDORED_JS_EXTENSIONS, so it just falls through to fallback. Not a bug in practice.

The logic is sound. The test coverage is good. The code is well-scoped and doesn't introduce any backward compatibility risks (it only changes behavior for Python workers with files specifically under python_modules/workers/ with .js or .mjs extensions).

LGTM

github run

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 6, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 2c0f85f

@ryanking13 ryanking13 changed the title DRAFT Vendor JS files in python workers SDK as esm modules Vendor JS files in python workers SDK as esm modules Apr 13, 2026
@ryanking13 ryanking13 force-pushed the gyeongjae/python-module-js-files branch from 7a1c97f to 436a01f Compare April 13, 2026 13:33
@ryanking13 ryanking13 marked this pull request as ready for review April 13, 2026 13:33
@workers-devprod workers-devprod requested review from a team and petebacondarwin and removed request for a team April 13, 2026 13:33
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 13, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

⚠️ Issues found

.changeset/poor-feet-like.md

  1. Grammar issue: "JS files ... is now handled" should be "JS files ... are now handled" (subject-verb agreement).

  2. Experimental feature not called out: This change appears to relate to the "Python workers runtime SDK" which is likely an experimental/beta feature. Per the guidelines, changesets for experimental features should explicitly call this out and note how users can opt in.

  3. Limited context: The description could benefit from:

    • What was the previous behavior? (JS files were presumably handled as CommonJS?)
    • Why is this change being made?
    • Any potential impact on users?

Suggested revision:

---
"wrangler": minor
---

JS files under the Python Workers runtime SDK are now handled as ESM modules

This is a change to the experimental Python Workers runtime. Previously, JS files were handled as CommonJS modules; they are now treated as ESM modules for better interoperability.

To opt in to the Python Workers runtime, add `python_workers = true` to your `wrangler.toml` or enable it in your Cloudflare dashboard.

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 3 additional findings.

Open in Devin Review

Comment thread packages/wrangler/src/deployment-bundle/find-additional-modules.ts Outdated
Comment thread packages/wrangler/src/deployment-bundle/find-additional-modules.ts
Comment thread .changeset/poor-feet-like.md Outdated
@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Apr 14, 2026
Copy link
Copy Markdown
Contributor

@workers-devprod workers-devprod left a comment

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

@github-project-automation github-project-automation bot moved this from In Review to Approved in workers-sdk Apr 15, 2026
@petebacondarwin petebacondarwin merged commit 6cbcdeb into main Apr 15, 2026
69 of 72 checks passed
@petebacondarwin petebacondarwin deleted the gyeongjae/python-module-js-files branch April 15, 2026 07:01
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Apr 15, 2026
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.

4 participants