Skip to content

Commit 1c4d850

Browse files
fix: skip auto-config and OpenNext delegation when --config is explicitly provided (#13711)
1 parent fc2d883 commit 1c4d850

4 files changed

Lines changed: 87 additions & 4 deletions

File tree

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: skip auto-config and OpenNext delegation when `--config` is explicitly provided
6+
7+
When `--config` is passed to `wrangler deploy`, the user is explicitly targeting a specific Worker configuration. Previously, wrangler would ignore `--config` and delegate to `opennextjs-cloudflare deploy` if it detected an OpenNext project in the working directory, silently deploying the wrong Worker. Now, both auto-config detection and OpenNext delegation are skipped when `--config` is provided, matching the existing behavior for `--script` and `--assets`.

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,39 @@ describe("deploy", () => {
651651
"Using fallback value in non-interactive context: yes"
652652
);
653653
});
654+
655+
it("should not run autoconfig when --config is explicitly provided", async ({
656+
expect,
657+
}) => {
658+
const getDetailsForAutoConfigSpy = vi.spyOn(
659+
await import("../../autoconfig/details"),
660+
"getDetailsForAutoConfig"
661+
);
662+
663+
writeWorkerSource();
664+
writeWranglerConfig({ main: "../index.js" }, "./config/wrangler.jsonc");
665+
mockSubDomainRequest();
666+
mockUploadWorkerRequest();
667+
668+
await runWrangler("deploy --config config/wrangler.jsonc");
669+
670+
expect(getDetailsForAutoConfigSpy).not.toHaveBeenCalled();
671+
672+
expect(std.out).toMatchInlineSnapshot(`
673+
"
674+
⛅️ wrangler x.x.x
675+
──────────────────
676+
Total Upload: xx KiB / gzip: xx KiB
677+
Worker Startup Time: 100 ms
678+
Uploaded test-name (TIMINGS)
679+
Deployed test-name triggers (TIMINGS)
680+
https://test-name.test-sub-domain.workers.dev
681+
Current Version ID: Galaxy-Class"
682+
`);
683+
expect(std.err).toMatchInlineSnapshot(`""`);
684+
expect(std.warn).toMatchInlineSnapshot(`""`);
685+
});
686+
654687
describe("output additional script information", () => {
655688
it("for first party workers, it should print worker information at log level", async ({
656689
expect,

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { writeWranglerConfig } from "@cloudflare/workers-utils/test-helpers";
33
import { http, HttpResponse } from "msw";
44
import dedent from "ts-dedent";
55
import { afterEach, beforeEach, describe, it, vi } from "vitest";
6+
import { getDetailsForAutoConfig } from "../../autoconfig/details";
67
import { getInstalledPackageVersion } from "../../autoconfig/frameworks/utils/packages";
78
import { clearOutputFilePath } from "../../output";
89
import { fetchSecrets } from "../../utils/fetch-secrets";
@@ -57,6 +58,7 @@ vi.mock("../../package-manager", async (importOriginal) => ({
5758
},
5859
}));
5960

61+
vi.mock("../../autoconfig/details");
6062
vi.mock("../../autoconfig/run");
6163
vi.mock("../../autoconfig/frameworks/utils/packages");
6264
vi.mock("@cloudflare/cli-shared-helpers/command");
@@ -88,6 +90,12 @@ describe("deploy", () => {
8890
);
8991
vi.mocked(fetchSecrets).mockResolvedValue([]);
9092
vi.mocked(getInstalledPackageVersion).mockReturnValue(undefined);
93+
vi.mocked(getDetailsForAutoConfig).mockResolvedValue({
94+
configured: true,
95+
workerName: "test-name",
96+
projectPath: process.cwd(),
97+
packageManager: { type: "npm" as const, npx: "npx" },
98+
} as Awaited<ReturnType<typeof getDetailsForAutoConfig>>);
9199
});
92100

93101
afterEach(() => {
@@ -390,5 +398,37 @@ describe("deploy", () => {
390398
expect(std.err).toMatchInlineSnapshot(`""`);
391399
expect(std.warn).toMatchInlineSnapshot(`""`);
392400
});
401+
402+
it("should not delegate to open-next deploy when --config is explicitly provided", async ({
403+
expect,
404+
}) => {
405+
const runCommandSpy = (
406+
await import("@cloudflare/cli-shared-helpers/command")
407+
).runCommand;
408+
409+
await mockOpenNextLikeProject();
410+
411+
await runWrangler("deploy --config wrangler.jsonc");
412+
413+
expect(runCommandSpy).not.toHaveBeenCalledOnce();
414+
415+
expect(std.out).toMatchInlineSnapshot(`
416+
"
417+
⛅️ wrangler x.x.x
418+
──────────────────
419+
Total Upload: xx KiB / gzip: xx KiB
420+
Worker Startup Time: 100 ms
421+
Your Worker has access to the following bindings:
422+
Binding Resource
423+
env.ASSETS Assets
424+
425+
Uploaded test-name (TIMINGS)
426+
Deployed test-name triggers (TIMINGS)
427+
https://test-name.test-sub-domain.workers.dev
428+
Current Version ID: Galaxy-Class"
429+
`);
430+
expect(std.err).toMatchInlineSnapshot(`""`);
431+
expect(std.warn).toMatchInlineSnapshot(`""`);
432+
});
393433
});
394434
});

packages/wrangler/src/deploy/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ export const deployCommand = createCommand({
286286
async handler(args, { config }) {
287287
const shouldRunAutoConfig =
288288
args.experimentalAutoconfig &&
289-
// If there is a positional parameter or an assets directory specified via --assets then
290-
// we don't want to run autoconfig since we assume that the user knows what they are doing
291-
// and that they are specifying what needs to be deployed
289+
// If there is a positional parameter, an assets directory specified via --assets, or an
290+
// explicit --config path then we don't want to run autoconfig since we assume that the
291+
// user knows what they are doing and that they are specifying what needs to be deployed
292292
!args.script &&
293-
!args.assets;
293+
!args.assets &&
294+
!args.config;
294295

295296
if (
296297
config.pages_build_output_dir &&
@@ -380,6 +381,8 @@ export const deployCommand = createCommand({
380381
// https://github.com/cloudflare/workers-sdk/pull/11694 and https://github.com/cloudflare/workers-sdk/pull/11710)
381382
// but as a precaution we're gating the feature under the autoconfig flag for the time being
382383
args.experimentalAutoconfig &&
384+
// If the user explicitly provided a --config path, they are targeting a specific Worker config and we should not delegate to open-next
385+
!args.config &&
383386
!args.dryRun &&
384387
(await maybeDelegateToOpenNextDeployCommand(process.cwd()));
385388

0 commit comments

Comments
 (0)