DEVX-2073: Draft of external plugin model#10119
Conversation
🦋 Changeset detectedLatest commit: bc0dcdb The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
petebacondarwin
left a comment
There was a problem hiding this comment.
Looking good. The general approach looks sound.
Regarding tests, I think we should be able to create a new fixture that can have its own local mock of an unsafe binding installed.
Then you can treat this like a playground during development, and also add tests that will run in CI.
packages/wrangler/src/api/startDevWorker/LocalRuntimeController.ts
Outdated
Show resolved
Hide resolved
d7c1a47 to
5cafd4c
Compare
695865c to
20bcc31
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
Just a few comments on the fixture...
1e81bd1 to
c45b1e8
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
Cool - Samuel and I have lots of questions about the API and configuration approach.
But if this is passing tests in CI then perhaps we land this and iterate?
There was a problem hiding this comment.
Is this needed for the Worker?
There was a problem hiding this comment.
would there be additional "production" config here that should be merged with the dev config above?
c45b1e8 to
ed855f1
Compare
bb412ca to
a71ccf8
Compare
5c2b039 to
f4cc133
Compare
…fe.bindings Wrangler config
…ld plugins between plugin implementations
* Update ESBuild for Miniflare to build a single fixtures folder * Update tsconfigs to allow single Miniflare test fixture folder to be considered via TS
aaee766 to
c5b0cb5
Compare
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: |
This implements an 'external plugin' model for extending Miniflare with Workers + Services outside of the Workers-SDK repo.
With this change, a user could specify the following configuration in an unsafe binding and have it emulated locally in a Worker simulator as existing plugins do.
{ // The name of the binding made available to this Worker "name": "MY_INTERNAL_BINDING", "service": "some-unsafe-service-binding", // We expect the '@cloudflare/example-external-plugin' package // to expose a plugin with name 'name-of-plugin-exposed-by-plugin' // that will provide the service binding for 'account-services-staging' "dev": { "package": "@cloudflare/example-external-plugin", "plugin": "name-of-plugin-exposed-by-plugin" }, "type": "service", }This package would need to expose a module with the following function export:
Notably, this can now happen outside of the Workers-SDK repo, which is important for plugins that may have non-public or implementation details that are confidential or restricted for internal Cloudflare usage.
Context:
Internally at Cloudflare, there is a desire to have a more functional local development environment when using "unsafe" bindings that aren't available for public consumption. Examples of internal bindings may include "unsafe" service bindings between internal Worker services or accessing a Quicksilver binding that will never be publicly exposed to customers but is still highly relevant to internal developers.
This MR tries to allow internal developers at Cloudflare to write and publish Miniflare plugins outside of the workers-sdk repo. These plugins can then be published internally and dynamically imported and merged into Miniflare's existing plugin model.
This MR is in rough draft state and definitely needs comments from the Workers ANT team members to help point out inconsistencies or areas for improvement. Particularly, I'd love reviews and help with:
Tests. I am slightly lost on how to best specify and mock these options in the existing Miniflare test structure.✅Opinions on the approach for specifying unsafe bindings via a✅devsection in wrangler.jsonc.Improving the documentation for the anatomy of a plugin. It has taken me a while to understand what each individual plugin method should be returning, even after reading CONTRIBUTING.md. For users who struggle with the intracacies of Miniflare and how it interacts with Wrangler, better comments could go a long way in helping folks contribute plugins.✅