diff --git a/.changeset/mighty-heads-shine.md b/.changeset/mighty-heads-shine.md new file mode 100644 index 00000000..dbf88865 --- /dev/null +++ b/.changeset/mighty-heads-shine.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +When running `wrangler deploy` add a `OPEN_NEXT_DEPLOY` environment variable to let wrangler know that it is being run by open-next diff --git a/packages/cloudflare/src/cli/commands/deploy.ts b/packages/cloudflare/src/cli/commands/deploy.ts index beb70bef..b81ad8b4 100644 --- a/packages/cloudflare/src/cli/commands/deploy.ts +++ b/packages/cloudflare/src/cli/commands/deploy.ts @@ -56,6 +56,13 @@ export async function deployCommand(args: WithWranglerArgs<{ cacheChunkSize?: nu ], { logging: "all", + env: { + // If we are running the deploy command we set this OPEN_NEXT_DEPLOY environment variable + // to let `wrangler deploy` know that it is being run from open-next. We do this because + // otherwise `wrangler deploy` run in an open-next project would call + // `opennextjs-cloudflare deploy` (thus causing an unwanted recursion). + OPEN_NEXT_DEPLOY: "true", + }, } ); } diff --git a/packages/cloudflare/src/cli/utils/run-wrangler.ts b/packages/cloudflare/src/cli/utils/run-wrangler.ts index 226ea50b..f6c07cdb 100644 --- a/packages/cloudflare/src/cli/utils/run-wrangler.ts +++ b/packages/cloudflare/src/cli/utils/run-wrangler.ts @@ -13,6 +13,7 @@ type WranglerOptions = { environment?: string; configPath?: string; logging?: "all" | "error"; + env?: Record; }; /** @@ -79,6 +80,7 @@ export function runWrangler(options: BuildOptions, args: string[], wranglerOpts: stdio: shouldPipeLogs ? ["ignore", "pipe", "pipe"] : "inherit", env: { ...process.env, + ...wranglerOpts.env, // `.env` files are handled by the adapter. // Wrangler would load `.env.` while we should load `.env.` // See https://opennext.js.org/cloudflare/howtos/env-vars