Skip to content

Commit 5ec53ae

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

File tree

8 files changed

+330
-179
lines changed

8 files changed

+330
-179
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: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14711,6 +14711,34 @@ export default{
1471114711
});
1471214712
});
1471314713

14714+
function normalizeLogWithConfigDiff(log: string): string {
14715+
// If the path is long the log could be wrapped so we need to remove the potential wrapping
14716+
let normalizedLog = log.replace(/"main":\s*"/, '"main": "');
14717+
14718+
if (process.platform === "win32") {
14719+
// On windows the snapshot paths incorrectly use double slashes, such as:
14720+
// `\"main\": \"C://Users//RUNNER~1//AppData//Local//Temp//wrangler-testse63LuJ//index.js\",
14721+
// so in the `main` field we replace all possible occurrences of `//` with just `\\`
14722+
// (so that the path normalization of `normalizeString` can appropriately work)
14723+
normalizedLog = normalizedLog.replace(
14724+
/"main": "(.*?)"/,
14725+
(_, mainPath: string) => `"main": "${mainPath.replaceAll("//", "\\")}"`
14726+
);
14727+
}
14728+
14729+
normalizedLog = normalizeString(normalizedLog);
14730+
14731+
// Let's remove the various extra characters for colors to get a more clear output
14732+
normalizedLog = normalizedLog
14733+
.replaceAll("", "X")
14734+
.replaceAll(/X\[\d+(?:;\d+)?m/g, "");
14735+
14736+
// Let's also normalize Windows newlines
14737+
normalizedLog = normalizedLog.replaceAll("\r\n", "\n");
14738+
14739+
return normalizedLog;
14740+
}
14741+
1471414742
describe("config remote differences", () => {
1471514743
it("should present a diff warning to the user when there are differences between the local config (json/jsonc) and the dash config", async () => {
1471614744
writeWorkerSource();
@@ -14760,16 +14788,15 @@ export default{
1476014788
await runWrangler("deploy --x-remote-diff-check");
1476114789

1476214790
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
14763-
"▲ [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:
14791+
"▲ [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:
14792+
14793+
{
14794+
vars: {
14795+
- MY_VAR: \\"abc\\"
14796+
+ MY_VAR: 123
14797+
}
14798+
}
1476414799
14765-
\\"workers_dev\\": true,
14766-
\\"preview_urls\\": false,
14767-
\\"vars\\": {
14768-
- \\"MY_VAR\\": \\"abc\\"
14769-
+ \\"MY_VAR\\": 123
14770-
},
14771-
\\"define\\": {},
14772-
\\"durable_objects\\": {
1477314800
1477414801
Deploying the Worker will override the remote configuration with your local one.
1477514802
@@ -14828,43 +14855,21 @@ export default{
1482814855
// to be able to show toml content/diffs, that combined with the fact that json(c) config files are the
1482914856
// recommended ones moving forward makes this small shortcoming of the config diffing acceptable
1483014857
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
14831-
"▲ [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:
14858+
"▲ [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:
14859+
14860+
{
14861+
vars: {
14862+
- MY_VAR: \\"abc\\"
14863+
+ MY_VAR: \\"this is a toml file\\"
14864+
}
14865+
}
1483214866
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\\": {
1484114867
1484214868
Deploying the Worker will override the remote configuration with your local one.
1484314869
1484414870
"
1484514871
`);
1484614872
});
14847-
14848-
function normalizeLogWithConfigDiff(log: string): string {
14849-
// If the path is long the log could be wrapped so we need to remove the potential wrapping
14850-
let normalizedLog = log.replace(/"main":\s*"/, '"main": "');
14851-
14852-
if (process.platform === "win32") {
14853-
// On windows the snapshot paths incorrectly use double slashes, such as:
14854-
// `\"main\": \"C://Users//RUNNER~1//AppData//Local//Temp//wrangler-testse63LuJ//index.js\",
14855-
// so in the `main` field we replace all possible occurrences of `//` with just `\\`
14856-
// (so that the path normalization of `normalizeString` can appropriately work)
14857-
normalizedLog = normalizedLog.replace(
14858-
/"main": "(.*?)"/,
14859-
(_, mainPath: string) =>
14860-
`"main": "${mainPath.replaceAll("//", "\\")}"`
14861-
);
14862-
}
14863-
14864-
normalizedLog = normalizeString(normalizedLog);
14865-
14866-
return normalizedLog;
14867-
}
1486814873
});
1486914874

1487014875
describe("with strict mode enabled", () => {
@@ -14904,17 +14909,16 @@ export default{
1490414909

1490514910
await runWrangler("deploy --x-remote-diff-check --strict");
1490614911

14907-
expect(std.warn).toMatchInlineSnapshot(`
14908-
"▲ [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:
14909-
14910-
\\"bindings\\": []
14911-
},
14912-
\\"observability\\": {
14913-
- \\"enabled\\": true,
14914-
+ \\"enabled\\": false,
14915-
\\"head_sampling_rate\\": 1,
14916-
\\"logs\\": {
14917-
\\"enabled\\": false,
14912+
expect(normalizeLogWithConfigDiff(std.warn)).toMatchInlineSnapshot(`
14913+
"▲ [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:
14914+
14915+
{
14916+
observability: {
14917+
- enabled: true
14918+
+ enabled: false
14919+
}
14920+
}
14921+
1491814922
1491914923
Deploying the Worker will override the remote configuration with your local one.
1492014924

0 commit comments

Comments
 (0)