Support packages and virtual modules in the main field of the Worker config#10212
Support packages and virtual modules in the main field of the Worker config#10212jamesopstad merged 8 commits intomainfrom
main field of the Worker config#10212Conversation
🦋 Changeset detectedLatest commit: 8a0fc4b The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
1431592 to
b7992c1
Compare
c241913 to
e7dde15
Compare
6fb4782 to
aa165db
Compare
main field of the Worker configmain field of the Worker config
| if (!ENTRY_MODULE_EXTENSIONS.some((extension) => main.endsWith(extension))) { | ||
| return main; | ||
| } |
There was a problem hiding this comment.
You can technically include an extension in a package entrypoint, though that seems pretty uncommon. Would it be safer to default to treating it as a path, and only consider it a module if it does not exist on the file system?
There was a problem hiding this comment.
The issue then is that it would be a change to the existing behaviour where we error if the file does not exist. There's also a slight risk that the file at the absolute path doesn't exist so we pass it through but then it resolves to a different (and unintended) file that does exist. Part of the problem is that we resolve the main field relative to the Worker config file and we treat paths as relative, even if they don't have leading ./.
Not allowing package.json exports that include a file extension seems like an OK tradeoff but open to other ideas here.
aa165db to
be0d1c4
Compare
|
Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the Depending on your changes, running Notes:
|
be0d1c4 to
5aef76a
Compare
main field of the Worker configmain field of the Worker config
5aef76a to
8afe079
Compare
8afe079 to
8a0fc4b
Compare
Fixes #000.
Adds support for package exports and virtual modules in the
mainfield of the Worker config. The primary use case is to enable users to directly provide a file exported by a framework as the Worker entry module.The changes made as part of this PR also prepare for better Rolldown support. By using virtual modules as entry files, it will be easier to adopt Rolldown's hook filter feature. Avoiding calling
this.resolveinloadortransformhooks also prevents errors when using modules that may pass through@rollup/common-js, such as package exports.The entry file name in the build output is now hardcoded to
index.js. This was necessary because of using a virtual module but is also more reliable than inferring from the first entry chunk as users/frameworks may add additional entry chunks.