Skip to content

Commit 82e7e90

Browse files
Fix arguments passed to wrangler deploy not being forwarded to opennextjs-cloudflare deploy (#11710)
1 parent a018bd4 commit 82e7e90

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed

.changeset/loud-seas-shave.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix arguments passed to `wrangler deploy` not being forwarded to `opennextjs-cloudflare deploy`
6+
7+
`wrangler deploy` run in an open-next project delegates to `opennextjs-cloudflare deploy`, as part of this all the arguments passed to `wrangler deploy` need be forwarded to `opennextjs-cloudflare deploy`, before the arguments would be lost, now they will be successfully forwarded (for example `wrangler deploy --keep-vars` will call `opennextjs-cloudflare deploy --keep-vars`)

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16004,6 +16004,11 @@ export default{
1600416004
}
1600516005

1600616006
it("should delegate to open-next when run in an open-next project and set OPEN_NEXT_DEPLOY", async () => {
16007+
vi.spyOn(process, "argv", "get").mockReturnValue([
16008+
"npx",
16009+
"wrangler",
16010+
"deploy",
16011+
]);
1600716012
const runCommandSpy = (await import("../autoconfig/c3-vendor/command"))
1600816013
.runCommand;
1600916014

@@ -16037,6 +16042,53 @@ export default{
1603716042
`);
1603816043
});
1603916044

16045+
it("should delegate to open-next when run in an open-next project and set OPEN_NEXT_DEPLOY and pass the various CLI arguments", async () => {
16046+
vi.spyOn(process, "argv", "get").mockReturnValue([
16047+
"npx",
16048+
"wrangler",
16049+
"deploy",
16050+
"--keep-vars",
16051+
]);
16052+
const runCommandSpy = (await import("../autoconfig/c3-vendor/command"))
16053+
.runCommand;
16054+
16055+
await mockOpenNextLikeProject();
16056+
16057+
await runWrangler("deploy");
16058+
16059+
expect(runCommandSpy).toHaveBeenCalledOnce();
16060+
const call = (runCommandSpy as unknown as MockInstance).mock.calls[0];
16061+
const [command, options] = call;
16062+
expect(command).toEqual([
16063+
"npx",
16064+
"opennextjs-cloudflare",
16065+
"deploy",
16066+
// `opennextjs-cloudflare deploy` accepts all the same arguments `wrangler deploy` does (since it then forwards them
16067+
// to wrangler), so we do want to make sure that arguments are indeed forwarded to `opennextjs-cloudflare deploy`
16068+
"--keep-vars",
16069+
]);
16070+
expect(options).toMatchObject({
16071+
env: {
16072+
// Note: we want to ensure that OPEN_NEXT_DEPLOY has been set, this is not strictly necessary but it helps us
16073+
// ensure that we can't end up in an infinite wrangler<>open-next invokation loop
16074+
OPEN_NEXT_DEPLOY: "true",
16075+
},
16076+
});
16077+
16078+
expect(std).toMatchInlineSnapshot(`
16079+
Object {
16080+
"debug": "",
16081+
"err": "",
16082+
"info": "",
16083+
"out": "
16084+
⛅️ wrangler x.x.x
16085+
──────────────────
16086+
OpenNext project detected, calling \`opennextjs-cloudflare deploy\`",
16087+
"warn": "",
16088+
}
16089+
`);
16090+
});
16091+
1604016092
it("should not delegate to open-next deploy when run in an open-next project and OPEN_NEXT_DEPLOY is set", async () => {
1604116093
vi.stubEnv("OPEN_NEXT_DEPLOY", "1");
1604216094

packages/wrangler/src/deploy/open-next.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from "node:assert";
12
import { readdir } from "node:fs/promises";
23
import { getOpenNextDeployFromEnv } from "@cloudflare/workers-utils";
34
import { runCommand } from "../autoconfig/c3-vendor/command";
@@ -22,14 +23,21 @@ export async function maybeDelegateToOpenNextDeployCommand(
2223
"OpenNext project detected, calling `opennextjs-cloudflare deploy`"
2324
);
2425

26+
const deployArgIdx = process.argv.findIndex((arg) => arg === "deploy");
27+
assert(deployArgIdx !== -1, "Could not find `deploy` argument");
28+
const deployArguments = process.argv.slice(deployArgIdx + 1);
29+
2530
const { npx } = await getPackageManager();
2631

27-
await runCommand([npx, "opennextjs-cloudflare", "deploy"], {
28-
env: {
29-
// We set `OPEN_NEXT_DEPLOY` here so that it's passed through to the `wrangler deploy` command that OpenNext delegates to in order to prevent an infinite loop
30-
OPEN_NEXT_DEPLOY: "true",
31-
},
32-
});
32+
await runCommand(
33+
[npx, "opennextjs-cloudflare", "deploy", ...deployArguments],
34+
{
35+
env: {
36+
// We set `OPEN_NEXT_DEPLOY` here so that it's passed through to the `wrangler deploy` command that OpenNext delegates to in order to prevent an infinite loop
37+
OPEN_NEXT_DEPLOY: "true",
38+
},
39+
}
40+
);
3341

3442
return true;
3543
}

0 commit comments

Comments
 (0)