Skip to content

Commit af54c63

Browse files
Add new autoconfig_summary field to the deploy output entry (#11500)
* Add new `experimental_autoconfig_summary` field to the deploy output entry * drop the `experimental_` prefix * remove extra package.json modification
1 parent 011e4b3 commit af54c63

File tree

8 files changed

+227
-33
lines changed

8 files changed

+227
-33
lines changed

‎.changeset/cold-numbers-sneeze.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add new `autoconfig_summary` field to the deploy output entry
6+
7+
This change augments `wrangler deploy` output being printed to `WRANGLER_OUTPUT_FILE_DIRECTORY` or `WRANGLER_OUTPUT_FILE_PATH` to also include a new `autoconfig_summary` field containing the possible summary details for the autoconfig process (the field is `undefined` if autoconfig didn't run).
8+
9+
Note: the field is experimental and could change while autoconfig is not GA

‎packages/wrangler/src/__tests__/autoconfig/run-summary.test.ts‎

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("autoconfig run - buildOperationsSummary()", () => {
2525

2626
describe("interactive mode", () => {
2727
test("presents a summary for a simple project where only a wrangler.jsonc file needs to be created", async () => {
28-
await buildOperationsSummary(
28+
const summary = await buildOperationsSummary(
2929
{
3030
workerName: "worker-name",
3131
projectPath: "<PROJECT_PATH>",
@@ -47,10 +47,25 @@ describe("autoconfig run - buildOperationsSummary()", () => {
4747
}
4848
"
4949
`);
50+
51+
expect(summary).toMatchInlineSnapshot(`
52+
Object {
53+
"scripts": Object {},
54+
"wranglerConfig": Object {
55+
"$schema": "node_modules/wrangler/config-schema.json",
56+
"compatibility_date": "2025-01-01",
57+
"name": "worker-name",
58+
"observability": Object {
59+
"enabled": true,
60+
},
61+
},
62+
"wranglerInstall": false,
63+
}
64+
`);
5065
});
5166

5267
test("shows that wrangler will be added as a devDependency when not already installed as such", async () => {
53-
await buildOperationsSummary(
68+
const summary = await buildOperationsSummary(
5469
{
5570
workerName: "worker-name",
5671
projectPath: "<PROJECT_PATH>",
@@ -69,10 +84,28 @@ describe("autoconfig run - buildOperationsSummary()", () => {
6984
- wrangler (devDependency)
7085
`
7186
);
87+
88+
expect(summary).toMatchInlineSnapshot(`
89+
Object {
90+
"scripts": Object {
91+
"deploy": "wrangler deploy",
92+
"preview": "wrangler dev",
93+
},
94+
"wranglerConfig": Object {
95+
"$schema": "node_modules/wrangler/config-schema.json",
96+
"compatibility_date": "2025-01-01",
97+
"name": "worker-name",
98+
"observability": Object {
99+
"enabled": true,
100+
},
101+
},
102+
"wranglerInstall": true,
103+
}
104+
`);
72105
});
73106

74107
test("when a package.json is present wrangler@latest will be unconditionally installed (even if already present)", async () => {
75-
await buildOperationsSummary(
108+
const summary = await buildOperationsSummary(
76109
{
77110
workerName: "worker-name",
78111
projectPath: "<PROJECT_PATH>",
@@ -93,10 +126,28 @@ describe("autoconfig run - buildOperationsSummary()", () => {
93126
- wrangler (devDependency)
94127
`
95128
);
129+
130+
expect(summary).toMatchInlineSnapshot(`
131+
Object {
132+
"scripts": Object {
133+
"deploy": "wrangler deploy",
134+
"preview": "wrangler dev",
135+
},
136+
"wranglerConfig": Object {
137+
"$schema": "node_modules/wrangler/config-schema.json",
138+
"compatibility_date": "2025-01-01",
139+
"name": "worker-name",
140+
"observability": Object {
141+
"enabled": true,
142+
},
143+
},
144+
"wranglerInstall": true,
145+
}
146+
`);
96147
});
97148

98149
test("shows that when needed a framework specific configuration will be run", async () => {
99-
await buildOperationsSummary(
150+
const summary = await buildOperationsSummary(
100151
{
101152
workerName: "worker-name",
102153
projectPath: "<PROJECT_PATH>",
@@ -109,10 +160,14 @@ describe("autoconfig run - buildOperationsSummary()", () => {
109160
expect(std.out).toContain(
110161
'🛠️ Configuring project for Astro with "astro add cloudflare"'
111162
);
163+
164+
expect(summary.frameworkConfiguration).toBe(
165+
'Configuring project for Astro with "astro add cloudflare"'
166+
);
112167
});
113168

114169
test("doesn't show the framework specific configuration step for the Static framework", async () => {
115-
await buildOperationsSummary(
170+
const summary = await buildOperationsSummary(
116171
{
117172
workerName: "worker-name",
118173
projectPath: "<PROJECT_PATH>",
@@ -123,6 +178,7 @@ describe("autoconfig run - buildOperationsSummary()", () => {
123178
);
124179

125180
expect(std.out).not.toContain("🛠️ Configuring project for");
181+
expect(summary.frameworkConfiguration).toBeUndefined();
126182
});
127183
});
128184
});

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

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Buffer } from "node:buffer";
33
import { spawnSync } from "node:child_process";
44
import { randomFillSync } from "node:crypto";
55
import * as fs from "node:fs";
6+
import { readFile } from "node:fs/promises";
67
import * as path from "node:path";
78
import {
89
APIError,
@@ -15,7 +16,19 @@ import * as esbuild from "esbuild";
1516
import { http, HttpResponse } from "msw";
1617
import * as TOML from "smol-toml";
1718
import dedent from "ts-dedent";
18-
import { afterEach, beforeEach, describe, expect, it, test, vi } from "vitest";
19+
import {
20+
afterEach,
21+
assert,
22+
beforeEach,
23+
describe,
24+
expect,
25+
it,
26+
test,
27+
vi,
28+
} from "vitest";
29+
import { getDetailsForAutoConfig } from "../autoconfig/details";
30+
import { Static } from "../autoconfig/frameworks/static";
31+
import { runAutoConfig } from "../autoconfig/run";
1932
import { printBundleSize } from "../deployment-bundle/bundle-reporter";
2033
import { clearOutputFilePath } from "../output";
2134
import { getSubdomainValues } from "../triggers/deploy";
@@ -72,6 +85,7 @@ import {
7285
} from "./helpers/write-wrangler-config";
7386
import type { AssetManifest } from "../assets";
7487
import type { CustomDomain, CustomDomainChangeset } from "../deploy/deploy";
88+
import type { OutputEntry } from "../output";
7589
import type { PostTypedConsumerBody, QueueResponse } from "../queues/client";
7690
import type {
7791
Config,
@@ -104,6 +118,9 @@ vi.mock("../package-manager", async (importOriginal) => ({
104118
},
105119
}));
106120

121+
vi.mock("../autoconfig/details");
122+
vi.mock("../autoconfig/run");
123+
107124
describe("deploy", () => {
108125
mockAccountId();
109126
mockApiToken();
@@ -15786,6 +15803,100 @@ export default{
1578615803
expect(process.exitCode).not.toBe(0);
1578715804
});
1578815805
});
15806+
15807+
it("should output a deploy output entry to WRANGLER_OUTPUT_FILE_PATH containing a field with the autoconfig summary if autoconfig run", async () => {
15808+
const outputFile = "./output.json";
15809+
15810+
vi.mocked(getDetailsForAutoConfig).mockResolvedValue({
15811+
configured: false,
15812+
framework: new Static("static"),
15813+
workerName: "my-site",
15814+
projectPath: ".",
15815+
});
15816+
15817+
vi.mocked(runAutoConfig).mockImplementation(async () => {
15818+
const wranglerConfig = {
15819+
name: "my-site",
15820+
compatibility_date: "2025-12-02",
15821+
assets: {
15822+
directory: ".",
15823+
},
15824+
};
15825+
15826+
writeWranglerConfig(wranglerConfig);
15827+
15828+
return {
15829+
scripts: {
15830+
build: "npm run build-my-static-site",
15831+
},
15832+
wranglerInstall: true,
15833+
wranglerConfig,
15834+
};
15835+
});
15836+
15837+
await runWrangler("deploy --x-autoconfig --dry-run", {
15838+
...process.env,
15839+
WRANGLER_OUTPUT_FILE_PATH: outputFile,
15840+
});
15841+
15842+
const deployOutputEntry = (await readFile(outputFile, "utf8"))
15843+
.split("\n")
15844+
.filter(Boolean)
15845+
.map((line) => JSON.parse(line))
15846+
.find((obj) => obj.type === "deploy") as OutputEntry | undefined;
15847+
15848+
assert(deployOutputEntry?.type === "deploy");
15849+
15850+
expect(deployOutputEntry.autoconfig_summary).toMatchInlineSnapshot(`
15851+
Object {
15852+
"scripts": Object {
15853+
"build": "npm run build-my-static-site",
15854+
},
15855+
"wranglerConfig": Object {
15856+
"assets": Object {
15857+
"directory": ".",
15858+
},
15859+
"compatibility_date": "2025-12-02",
15860+
"name": "my-site",
15861+
},
15862+
"wranglerInstall": true,
15863+
}
15864+
`);
15865+
});
15866+
15867+
it("should output a deploy output entry to WRANGLER_OUTPUT_FILE_PATH not containing a field with the autoconfig summary if autoconfig didn't run", async () => {
15868+
const outputFile = "./output.json";
15869+
15870+
writeWranglerConfig({
15871+
name: "worker-name",
15872+
compatibility_date: "2025-12-02",
15873+
assets: {
15874+
directory: ".",
15875+
},
15876+
});
15877+
15878+
vi.mocked(getDetailsForAutoConfig).mockResolvedValue({
15879+
configured: true,
15880+
framework: new Static("static"),
15881+
workerName: "my-worker",
15882+
projectPath: ".",
15883+
});
15884+
15885+
await runWrangler("deploy --x-autoconfig --dry-run", {
15886+
...process.env,
15887+
WRANGLER_OUTPUT_FILE_PATH: outputFile,
15888+
});
15889+
15890+
const deployOutputEntry = (await readFile(outputFile, "utf8"))
15891+
.split("\n")
15892+
.filter(Boolean)
15893+
.map((line) => JSON.parse(line))
15894+
.find((obj) => obj.type === "deploy") as OutputEntry | undefined;
15895+
15896+
assert(deployOutputEntry?.type === "deploy");
15897+
15898+
expect(deployOutputEntry.autoconfig_summary).toBeUndefined();
15899+
});
1578915900
});
1579015901

1579115902
/** Write mock assets to the file system so they can be uploaded. */

‎packages/wrangler/src/__tests__/output.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe("writeOutput()", () => {
9494
targets: undefined,
9595
worker_name_overridden: false,
9696
wrangler_environment: undefined,
97+
autoconfig_summary: undefined,
9798
});
9899

99100
const outputFile = readFileSync(WRANGLER_OUTPUT_FILE_PATH, "utf8");
@@ -113,6 +114,7 @@ describe("writeOutput()", () => {
113114
version_id: "1234",
114115
targets: undefined,
115116
worker_name_overridden: false,
117+
autoconfig_summary: undefined,
116118
wrangler_environment: undefined,
117119
},
118120
]);
@@ -163,6 +165,7 @@ describe("writeOutput()", () => {
163165
targets: undefined,
164166
worker_name_overridden: false,
165167
wrangler_environment: undefined,
168+
autoconfig_summary: undefined,
166169
});
167170

168171
const outputFilePaths = readdirSync("output");
@@ -186,6 +189,7 @@ describe("writeOutput()", () => {
186189
targets: undefined,
187190
worker_name_overridden: false,
188191
wrangler_environment: undefined,
192+
autoconfig_summary: undefined,
189193
},
190194
]);
191195
});

0 commit comments

Comments
 (0)