-
Notifications
You must be signed in to change notification settings - Fork 67
Add support for passing multiple configs to wrangler #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for passing multiple configs to wrangler #896
Conversation
🦋 Changeset detectedLatest commit: f7187b9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for passing multiple Wrangler configuration files to the opennextjs-cloudflare CLI, enabling developers to bind multiple workers to a single dev session for local development with Durable Objects and RPC communication.
- Updates the CLI to accept multiple
--config
flags as an array of configuration paths - Introduces
nextjsWranglerConfigPath
to maintain compatibility with existing OpenNext functionality - Adds informational logging when multiple configs are detected
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/cloudflare/src/cli/commands/utils.ts | Core implementation adding array support for config option and new type definitions |
packages/cloudflare/src/cli/commands/upload.ts | Updated to use nextjsWranglerConfigPath for OpenNext-specific operations |
packages/cloudflare/src/cli/commands/preview.ts | Updated to use nextjsWranglerConfigPath for OpenNext-specific operations |
packages/cloudflare/src/cli/commands/populate-cache.ts | Updated to use nextjsWranglerConfigPath for OpenNext-specific operations |
packages/cloudflare/src/cli/commands/deploy.ts | Updated to use nextjsWranglerConfigPath for OpenNext-specific operations |
.changeset/weak-crews-tickle.md | Changelog entry documenting the new multiple config support feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
...args, | ||
wranglerConfigPath: args.config ?? args.configPath, | ||
wranglerConfigPath, | ||
nextjsWranglerConfigPath: wranglerConfigPath?.[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly this will only work when the next app config is first which is not ideal.
Can't you run opennextjs-cloudflare ...
(for the next app) and wrangler dev ...
for other workers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this isn't ideal but I couldn't think of another solution.
You can run them in separate dev sessions but you'll hit them limitation outline in the documentation;
If you are not using RPC with your Durable Object, you can run a separate Wrangler dev session alongside your framework development server.
Otherwise, you can build your application and run both Workers in the same Wrangler dev session.
I found this when trying to port the agents starter to opennext-cloudflare which is working when I link this change.
I'm trying to run them locally in separate dev sessions now but its having an issue upgrading to web-sockets I've not debugged yet.
I'm open to other ways of solving this or I can just open an issue so it can be fixed upstream in wrangler somehow
Sounds like inter process communication is coming soon. |
This PR updates the opennextjs-cloudflare CLI to correctly pass through multiple configuration files to Wrangler, allowing multiple workers to be bound to a single dev session. This is helpful when using Durable Objects, which aren't bound to the worker when using Miniflare locally, as per the CLI warning.
This reduces the need to run two dev sessions locally and ensures you can use RPC with DO locally, as per the supported binding docs.
Developers can enable this by updating preview to:
You can do this today; however, you'll encounter an error when an array is passed through to unstable_readConfig unexpectedly, as yargs will return an array of strings for config without error, misaligned with its typing.
As the CLI has to read the config file used for OpenNext to support some features, I've made the choice to assume the first config passed is the one used to define the worker for Next.js. This might not be the best choice but felt more aligned with Wrangler than adding additional config flags.
Given this usage is probably an edge case and most users don't pass config, it seemed like a reasonable trade-off.
One item that could use more work but would require more code changes is ensuring the info message I added is below the header. I'm happy to make this change if people would consider merging this.