Skip to content

Commit 2510723

Browse files
dario-piotrowiczpetebacondarwinvicb
authored
Restrict the wrangler deploy delegation to opennextjs-cloudflare deploy only when the --x-autoconfig flag is used (#11796)
* Restrict the `wrangler deploy` delegation to `opennextjs-cloudflare deploy` only when the `--x-autoconfig` flag is used * Update .changeset/common-readers-draw.md Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com> * Update .changeset/common-readers-draw.md Co-authored-by: Victor Berchet <victor@suumit.com> * remove the `canDelegateToOpenNext` variable * add PRs to code comment --------- Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com> Co-authored-by: Victor Berchet <victor@suumit.com>
1 parent 7cf365e commit 2510723

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

.changeset/common-readers-draw.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+
`wrangler deploy` delegates to `opennextjs-cloudflare deploy` only when the `--x-autoconfig` flag is used
6+
7+
The `wrangler deploy` command has been updated to delegate to the `opennextjs-cloudflare deploy` command when run in an open-next project. Once this behavior had been introduced it caused a few issues. So it's been decided to enable it for the time being only when the `--x-autoconfig` flag is set (since this behavior, although generally valid, is only strictly necessary for the `wrangler deploy`'s autoconfig flow).

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16008,18 +16008,24 @@ export default{
1600816008
"npx",
1600916009
"wrangler",
1601016010
"deploy",
16011+
"--x-autoconfig",
1601116012
]);
1601216013
const runCommandSpy = (await import("../autoconfig/c3-vendor/command"))
1601316014
.runCommand;
1601416015

1601516016
await mockOpenNextLikeProject();
1601616017

16017-
await runWrangler("deploy");
16018+
await runWrangler("deploy --x-autoconfig");
1601816019

1601916020
expect(runCommandSpy).toHaveBeenCalledOnce();
1602016021
const call = (runCommandSpy as unknown as MockInstance).mock.calls[0];
1602116022
const [command, options] = call;
16022-
expect(command).toEqual(["npx", "opennextjs-cloudflare", "deploy"]);
16023+
expect(command).toEqual([
16024+
"npx",
16025+
"opennextjs-cloudflare",
16026+
"deploy",
16027+
"--x-autoconfig",
16028+
]);
1602316029
expect(options).toMatchObject({
1602416030
env: {
1602516031
// Note: we want to ensure that OPEN_NEXT_DEPLOY has been set, this is not strictly necessary but it helps us
@@ -16048,13 +16054,14 @@ export default{
1604816054
"wrangler",
1604916055
"deploy",
1605016056
"--keep-vars",
16057+
"--x-autoconfig",
1605116058
]);
1605216059
const runCommandSpy = (await import("../autoconfig/c3-vendor/command"))
1605316060
.runCommand;
1605416061

1605516062
await mockOpenNextLikeProject();
1605616063

16057-
await runWrangler("deploy");
16064+
await runWrangler("deploy --x-autoconfig");
1605816065

1605916066
expect(runCommandSpy).toHaveBeenCalledOnce();
1606016067
const call = (runCommandSpy as unknown as MockInstance).mock.calls[0];
@@ -16066,6 +16073,7 @@ export default{
1606616073
// `opennextjs-cloudflare deploy` accepts all the same arguments `wrangler deploy` does (since it then forwards them
1606716074
// to wrangler), so we do want to make sure that arguments are indeed forwarded to `opennextjs-cloudflare deploy`
1606816075
"--keep-vars",
16076+
"--x-autoconfig",
1606916077
]);
1607016078
expect(options).toMatchObject({
1607116079
env: {
@@ -16097,6 +16105,35 @@ export default{
1609716105

1609816106
await mockOpenNextLikeProject();
1609916107

16108+
await runWrangler("deploy --x-autoconfig");
16109+
16110+
expect(runCommandSpy).not.toHaveBeenCalledOnce();
16111+
16112+
expect(std.out).toMatchInlineSnapshot(`
16113+
"
16114+
⛅️ wrangler x.x.x
16115+
──────────────────
16116+
Total Upload: xx KiB / gzip: xx KiB
16117+
Worker Startup Time: 100 ms
16118+
Your Worker has access to the following bindings:
16119+
Binding Resource
16120+
env.ASSETS Assets
16121+
16122+
Uploaded test-name (TIMINGS)
16123+
Deployed test-name triggers (TIMINGS)
16124+
https://test-name.test-sub-domain.workers.dev
16125+
Current Version ID: Galaxy-Class"
16126+
`);
16127+
expect(std.err).toMatchInlineSnapshot(`""`);
16128+
expect(std.warn).toMatchInlineSnapshot(`""`);
16129+
});
16130+
16131+
it("should not delegate to open-next deploy when the --x-autoconfig flag is not provided", async () => {
16132+
const runCommandSpy = (await import("../autoconfig/c3-vendor/command"))
16133+
.runCommand;
16134+
16135+
await mockOpenNextLikeProject();
16136+
1610016137
await runWrangler("deploy");
1610116138

1610216139
expect(runCommandSpy).not.toHaveBeenCalledOnce();
@@ -16129,7 +16166,7 @@ export default{
1612916166
// Let's delete the next.config.js file
1613016167
fs.rmSync("./next.config.js");
1613116168

16132-
await runWrangler("deploy");
16169+
await runWrangler("deploy --x-autoconfig");
1613316170

1613416171
expect(runCommandSpy).not.toHaveBeenCalledOnce();
1613516172

@@ -16161,7 +16198,7 @@ export default{
1616116198
// Let's delete the open-next.config.ts file
1616216199
fs.rmSync("./open-next.config.ts");
1616316200

16164-
await runWrangler("deploy");
16201+
await runWrangler("deploy --x-autoconfig");
1616516202

1616616203
expect(runCommandSpy).not.toHaveBeenCalledOnce();
1616716204

packages/wrangler/src/deploy/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ export const deployCommand = createCommand({
302302
// make sure that the deployment of brand newly auto-configured Next.js apps is correctly
303303
// delegated here
304304
const deploymentDelegatedToOpenNext =
305+
// Currently the delegation to open-next is gated behind the autoconfig experimental flag, this is because
306+
// this behavior is currently only necessary in the autoconfig flow and having it un-gated/stable in wrangler
307+
// releases caused different issues. All the issues should have been fixed (by
308+
// https://github.com/cloudflare/workers-sdk/pull/11694 and https://github.com/cloudflare/workers-sdk/pull/11710)
309+
// but as a precaution we're gating the feature under the autoconfig flag for the time being
310+
args.experimentalAutoconfig &&
305311
!args.dryRun &&
306312
(await maybeDelegateToOpenNextDeployCommand(process.cwd()));
307313

0 commit comments

Comments
 (0)