Skip to content

Commit d57af5c

Browse files
improve the diffing representation for wrangler deploy (run under --x-remote-diff-check)
1 parent f29b0b0 commit d57af5c

File tree

8 files changed

+277
-147
lines changed

8 files changed

+277
-147
lines changed

.changeset/silver-pears-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
improve the diffing representation for `wrangler deploy` (run under `--x-remote-diff-check`)

packages/wrangler/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"@types/glob-to-regexp": "^0.4.1",
9696
"@types/is-ci": "^3.0.0",
9797
"@types/javascript-time-ago": "^2.0.3",
98+
"@types/json-diff": "^1.0.3",
9899
"@types/mime": "^3.0.4",
99100
"@types/minimatch": "^5.1.2",
100101
"@types/node": "catalog:default",
@@ -128,6 +129,7 @@
128129
"is-ci": "^3.0.1",
129130
"itty-time": "^1.0.6",
130131
"javascript-time-ago": "^2.5.4",
132+
"json-diff": "^1.0.6",
131133
"md5-file": "5.0.0",
132134
"mime": "^3.0.0",
133135
"minimatch": "^5.1.0",

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14762,14 +14762,13 @@ export default{
1476214762
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
1476314763
"▲ [WARNING] The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:
1476414764
14765-
\\"workers_dev\\": true,
14766-
\\"preview_urls\\": false,
14767-
\\"vars\\": {
14768-
- \\"MY_VAR\\": \\"abc\\"
14769-
+ \\"MY_VAR\\": 123
14770-
},
14771-
\\"define\\": {},
14772-
\\"durable_objects\\": {
14765+
{
14766+
vars: {
14767+
- MY_VAR: \\"abc\\"
14768+
+ MY_VAR: 123
14769+
}
14770+
}
14771+
1477314772
1477414773
Deploying the Worker will override the remote configuration with your local one.
1477514774
@@ -14830,14 +14829,13 @@ export default{
1483014829
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
1483114830
"▲ [WARNING] The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:
1483214831
14833-
\\"workers_dev\\": true,
14834-
\\"preview_urls\\": false,
14835-
\\"vars\\": {
14836-
- \\"MY_VAR\\": \\"abc\\"
14837-
+ \\"MY_VAR\\": \\"this is a toml file\\"
14838-
},
14839-
\\"define\\": {},
14840-
\\"durable_objects\\": {
14832+
{
14833+
vars: {
14834+
- MY_VAR: \\"abc\\"
14835+
+ MY_VAR: \\"this is a toml file\\"
14836+
}
14837+
}
14838+
1484114839
1484214840
Deploying the Worker will override the remote configuration with your local one.
1484314841
@@ -14907,14 +14905,13 @@ export default{
1490714905
expect(std.warn).toMatchInlineSnapshot(`
1490814906
"▲ [WARNING] The local configuration being used (generated from your local configuration file) differs from the remote configuration of your Worker set via the Cloudflare Dashboard:
1490914907
14910-
\\"bindings\\": []
14911-
},
14912-
\\"observability\\": {
14913-
- \\"enabled\\": true,
14914-
+ \\"enabled\\": false,
14915-
\\"head_sampling_rate\\": 1,
14916-
\\"logs\\": {
14917-
\\"enabled\\": false,
14908+
{
14909+
observability: {
14910+
- enabled: true
14911+
+ enabled: false
14912+
}
14913+
}
14914+
1491814915
1491914916
Deploying the Worker will override the remote configuration with your local one.
1492014917

packages/wrangler/src/__tests__/deploy/config-diffs.test.ts

Lines changed: 108 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("getRemoteConfigsDiff", () => {
2929
} as unknown as Config
3030
);
3131

32-
expect(diff.toString()).toEqual("");
32+
expect(diff).toBe(null);
3333
expect(nonDestructive).toBe(true);
3434
});
3535

@@ -60,13 +60,13 @@ describe("getRemoteConfigsDiff", () => {
6060
} as unknown as Config
6161
);
6262

63+
assert(diff);
6364
expect(diff.toString()).toMatchInlineSnapshot(`
64-
" {
65-
- \\"compatibility_date\\": \\"2025-07-08\\",
66-
+ \\"compatibility_date\\": \\"2025-07-09\\",
67-
\\"main\\": \\"/tmp/src/index.js\\",
68-
\\"compatibility_flags\\": [],
69-
\\"name\\": \\"silent-firefly-dbe3\\","
65+
" {
66+
- compatibility_date: \\"2025-07-08\\"
67+
+ compatibility_date: \\"2025-07-09\\"
68+
}
69+
"
7070
`);
7171
expect(nonDestructive).toBe(false);
7272
});
@@ -97,21 +97,65 @@ describe("getRemoteConfigsDiff", () => {
9797
],
9898
} as unknown as Config
9999
);
100+
assert(diff);
100101
expect(diff.toString()).toMatchInlineSnapshot(`
101-
" {
102-
\\"binding\\": \\"MY_KV\\",
103-
\\"id\\": \\"my-kv-123\\"
104-
+ },
105-
+ {
106-
+ \\"binding\\": \\"MY_KV_2\\",
107-
+ \\"id\\": \\"my-kv-456\\"
108-
}
109-
],
110-
\\"workers_dev\\": true,"
102+
" {
103+
kv_namespaces: [
104+
...
105+
[32m+ {[39m
106+
[32m+ binding: \\"MY_KV_2\\"[39m
107+
[32m+ id: \\"my-kv-456\\"[39m
108+
[32m+ }[39m
109+
]
110+
}
111+
"
111112
`);
112113
expect(nonDestructive).toBe(true);
113114
});
114115

116+
it("should handle a diffing scenario with only deletions", () => {
117+
const { diff, nonDestructive } = getRemoteConfigDiff(
118+
{
119+
name: "silent-firefly-dbe3",
120+
main: "/tmp/src/index.js",
121+
workers_dev: true,
122+
preview_urls: false,
123+
compatibility_date: "2025-07-08",
124+
compatibility_flags: undefined,
125+
placement: undefined,
126+
limits: undefined,
127+
tail_consumers: undefined,
128+
account_id: "account-id-123",
129+
kv_namespaces: [{ binding: "MY_KV", id: "my-kv-123" }],
130+
},
131+
{
132+
name: "silent-firefly-dbe3",
133+
main: "/tmp/src/index.js",
134+
workers_dev: true,
135+
preview_urls: false,
136+
compatibility_date: "2025-07-08",
137+
compatibility_flags: undefined,
138+
placement: undefined,
139+
limits: undefined,
140+
tail_consumers: undefined,
141+
account_id: "account-id-123",
142+
} as unknown as Config
143+
);
144+
assert(diff);
145+
expect(diff.toString()).toMatchInlineSnapshot(`
146+
" {
147+
- kv_namespaces: [
148+
- {
149+
- binding: \\"MY_KV\\"
150+
- id: \\"my-kv-123\\"
151+
- }
152+
- ]
153+
}
154+
"
155+
`);
156+
expect(nonDestructive).toBe(false);
157+
});
158+
115159
it("should handle a diffing scenario with modifications and removals", () => {
116160
const { diff, nonDestructive } = getRemoteConfigDiff(
117161
{
@@ -137,33 +181,23 @@ describe("getRemoteConfigsDiff", () => {
137181
account_id: "account-id-123",
138182
} as unknown as Config
139183
);
184+
assert(diff);
140185
expect(diff.toString()).toMatchInlineSnapshot(`
141-
" {
142-
\\"name\\": \\"silent-firefly-dbe3\\",
143-
\\"main\\": \\"src/index.js\\",
144-
- \\"compatibility_date\\": \\"2025-07-08\\",
145-
+ \\"compatibility_date\\": \\"2025-07-09\\",
146-
\\"observability\\": {
147-
- \\"enabled\\": true,
148-
+ \\"enabled\\": false,
149-
\\"head_sampling_rate\\": 1,
150-
\\"logs\\": {
151-
\\"enabled\\": false,
152-
153-
...
154-
155-
},
156-
\\"account_id\\": \\"account-id-123\\",
157-
\\"workers_dev\\": true,
158-
+ \\"preview_urls\\": false
159-
- \\"preview_urls\\": false,
160-
- \\"kv_namespaces\\": [
161-
- {
162-
- \\"binding\\": \\"MY_KV\\",
163-
- \\"id\\": \\"my-kv-123\\"
164-
- }
165-
- ]
166-
}"
186+
" {
187+
- kv_namespaces: [
188+
- {
189+
- binding: \\"MY_KV\\"
190+
- id: \\"my-kv-123\\"
191+
- }
192+
- ]
193+
- compatibility_date: \\"2025-07-08\\"
194+
+ compatibility_date: \\"2025-07-09\\"
195+
observability: {
196+
- enabled: true
197+
+ enabled: false
198+
}
199+
}
200+
"
167201
`);
168202
expect(nonDestructive).toBe(false);
169203
});
@@ -196,7 +230,7 @@ describe("getRemoteConfigsDiff", () => {
196230
undefined,
197231
{ enabled: false }
198232
);
199-
expect(diff.toString()).toMatchInlineSnapshot(`""`);
233+
expect(diff).toBe(null);
200234
});
201235

202236
it("should treat a remote undefined equal to a remote { enabled: false, logs: { enabled: false } }", () => {
@@ -205,7 +239,7 @@ describe("getRemoteConfigsDiff", () => {
205239
undefined,
206240
{ enabled: false, logs: { enabled: false } }
207241
);
208-
expect(diff.toString()).toMatchInlineSnapshot(`""`);
242+
expect(diff).toBe(null);
209243
});
210244

211245
it("should correctly show the diff of boolean when the remote is undefined and the local is { enabled: true }", () => {
@@ -214,14 +248,15 @@ describe("getRemoteConfigsDiff", () => {
214248
undefined,
215249
{ enabled: true }
216250
);
251+
assert(diff);
217252
expect(diff.toString()).toMatchInlineSnapshot(`
218-
" {
219-
\\"observability\\": {
220-
- \\"enabled\\": false,
221-
+ \\"enabled\\": true,
222-
\\"head_sampling_rate\\": 1,
223-
\\"logs\\": {
224-
\\"enabled\\": false,"
253+
" {
254+
observability: {
255+
[31m- enabled: false[39m
256+
[32m+ enabled: true[39m
257+
}
258+
}
259+
"
225260
`);
226261
});
227262

@@ -231,15 +266,17 @@ describe("getRemoteConfigsDiff", () => {
231266
undefined,
232267
{ logs: { enabled: true } }
233268
);
269+
assert(diff);
234270
expect(diff.toString()).toMatchInlineSnapshot(`
235-
" {
236-
\\"observability\\": {
237-
\\"logs\\": {
238-
- \\"enabled\\": false,
239-
+ \\"enabled\\": true,
240-
\\"head_sampling_rate\\": 1,
241-
\\"invocation_logs\\": true
242-
},"
271+
" {
272+
observability: {
273+
logs: {
274+
- enabled: false
275+
+ enabled: true
276+
}
277+
}
278+
}
279+
"
243280
`);
244281
});
245282

@@ -249,7 +286,7 @@ describe("getRemoteConfigsDiff", () => {
249286
{ enabled: false, head_sampling_rate: 1, logs: { enabled: true } },
250287
{ enabled: false, logs: { enabled: true, invocation_logs: true } }
251288
);
252-
expect(diff.toString()).toMatchInlineSnapshot(`""`);
289+
expect(diff).toBe(null);
253290
});
254291

255292
it("should correctly not show logs.invocation_logs being added remotely", () => {
@@ -260,15 +297,17 @@ describe("getRemoteConfigsDiff", () => {
260297
},
261298
{ logs: { enabled: true, head_sampling_rate: 0.9 } }
262299
);
300+
assert(diff);
263301
expect(diff.toString()).toMatchInlineSnapshot(`
264-
" \\"observability\\": {
265-
\\"logs\\": {
266-
\\"enabled\\": true,
267-
- \\"head_sampling_rate\\": 1,
268-
+ \\"head_sampling_rate\\": 0.9,
269-
\\"invocation_logs\\": true
270-
},
271-
\\"enabled\\": false,"
302+
" {
303+
observability: {
304+
logs: {
305+
- head_sampling_rate: 1
306+
+ head_sampling_rate: 0.9
307+
}
308+
}
309+
}
310+
"
272311
`);
273312
});
274313
});

0 commit comments

Comments
 (0)