-
Notifications
You must be signed in to change notification settings - Fork 69
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@opennextjs/cloudflare": minor | ||
--- | ||
|
||
Support multiple Wrangler configuration files via `--config` flag | ||
|
||
Enable passing multiple configuration files to the OpenNext.js Cloudflare CLI | ||
using the `--config` flag, matching Wrangler's native capability. This allows | ||
running multiple workers in a single dev session, which is essential for RPC | ||
communication with Durable Objects during local development as documented in the | ||
[Wrangler API bindings guide](https://developers.cloudflare.com/workers/wrangler/api/#supported-bindings) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ import { createOpenNextConfigIfNotExistent, ensureCloudflareConfig } from "../bu | |
export type WithWranglerArgs<T = unknown> = T & { | ||
// Array of arguments that can be given to wrangler commands, including the `--config` and `--env` args. | ||
wranglerArgs: string[]; | ||
wranglerConfigPath: string | undefined; | ||
wranglerConfigPath: string[] | undefined; | ||
// The first wrangler config path passed into the CLI, if any. Assumed to be the one used for OpenNext. | ||
nextjsWranglerConfigPath: string | undefined; | ||
env: string | undefined; | ||
}; | ||
|
||
|
@@ -101,7 +103,7 @@ export function getNormalizedOptions(config: OpenNextConfig, buildDir = nextAppD | |
* @returns Wrangler config. | ||
*/ | ||
export function readWranglerConfig(args: WithWranglerArgs) { | ||
return unstable_readConfig({ env: args.env, config: args.wranglerConfigPath }); | ||
return unstable_readConfig({ env: args.env, config: args.nextjsWranglerConfigPath }); | ||
} | ||
|
||
/** | ||
|
@@ -111,6 +113,7 @@ export function withWranglerOptions<T extends yargs.Argv>(args: T) { | |
return args | ||
.option("config", { | ||
type: "string", | ||
array: true, | ||
alias: "c", | ||
desc: "Path to Wrangler configuration file", | ||
}) | ||
|
@@ -128,7 +131,7 @@ export function withWranglerOptions<T extends yargs.Argv>(args: T) { | |
|
||
type WranglerInputArgs = { | ||
configPath: string | undefined; | ||
config: string | undefined; | ||
config: string[] | undefined; | ||
env: string | undefined; | ||
}; | ||
|
||
|
@@ -143,15 +146,15 @@ function getWranglerArgs(args: WranglerInputArgs & { _: (string | number)[] }): | |
|
||
if (args.config) { | ||
logger.error( | ||
"Multiple config flags found. Please use the `--config` flag for your Wrangler config path." | ||
"Duplicate config flags found. Unable to pass both `--config` and `--configPath`. Please use the `--config` flag for your Wrangler config path." | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
return [ | ||
...(args.configPath ? ["--config", args.configPath] : []), | ||
...(args.config ? ["--config", args.config] : []), | ||
...(args.config ? args.config.flatMap((c) => ["--config", c]) : []), | ||
...(args.env ? ["--env", args.env] : []), | ||
// Note: the first args in `_` will be the commands. | ||
...args._.slice(args._[0] === "populateCache" ? 2 : 1).map((a) => `${a}`), | ||
|
@@ -166,9 +169,15 @@ function getWranglerArgs(args: WranglerInputArgs & { _: (string | number)[] }): | |
export function withWranglerPassthroughArgs<T extends yargs.ArgumentsCamelCase<WranglerInputArgs>>( | ||
args: T | ||
): WithWranglerArgs<T> { | ||
const wranglerConfigPath = args.config ?? (args.configPath ? [args.configPath] : undefined); | ||
if (wranglerConfigPath && wranglerConfigPath?.length > 1) { | ||
logger.info("Multiple Wrangler config paths found, first config assumed as opennext config."); | ||
} | ||
|
||
return { | ||
...args, | ||
wranglerConfigPath: args.config ?? args.configPath, | ||
wranglerConfigPath, | ||
nextjsWranglerConfigPath: wranglerConfigPath?.[0], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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;
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 |
||
wranglerArgs: getWranglerArgs(args), | ||
}; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.