Skip to content

Commit 4546eb3

Browse files
committed
fix trailing comma causing unncessary diffs
1 parent 5ca8991 commit 4546eb3

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,6 @@ describe("wrangler deploy with containers", () => {
716716
│ {
717717
│ ...
718718
│ \\"image\\": \\"docker.io/hello:world\\",
719-
│ - \\"instance_type\\": \\"dev\\"
720-
│ + \\"instance_type\\": \\"dev\\",
721719
│ + \\"observability\\": {
722720
│ + \\"logs\\": {
723721
│ + \\"enabled\\": true
@@ -762,8 +760,6 @@ describe("wrangler deploy with containers", () => {
762760
│ {
763761
│ ...
764762
│ \\"image\\": \\"docker.io/hello:world\\",
765-
│ - \\"instance_type\\": \\"dev\\"
766-
│ + \\"instance_type\\": \\"dev\\",
767763
│ + \\"observability\\": {
768764
│ + \\"logs\\": {
769765
│ + \\"enabled\\": true

packages/wrangler/src/cloudchamber/helpers/diff.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,30 @@ export const renderDiff = (results: Result[]) => {
561561
}
562562
}
563563
};
564+
565+
/**
566+
* Filter out trailing comma differences that are just formatting changes.
567+
* This prevents showing spurious diffs when JSON properties get trailing commas
568+
* added/removed due to new properties being inserted.
569+
*/
570+
export function filterTrailingCommaChanges(results: Result[]): Result[] {
571+
// First, identify pairs of removed/added lines that are just comma changes
572+
const commaChangePairs = new Set<Result>();
573+
574+
results.forEach((result) => {
575+
if (result.removed && result.value) {
576+
// Look for a corresponding added line that's the same but with comma
577+
const potentialMatch = results.find((r) =>
578+
r.added && r.value === result.value + ','
579+
);
580+
if (potentialMatch) {
581+
// This is a trailing comma change, mark both for filtering
582+
commaChangePairs.add(result);
583+
commaChangePairs.add(potentialMatch);
584+
}
585+
}
586+
});
587+
588+
// Filter out the identified comma change pairs
589+
return results.filter((result) => !commaChangePairs.has(result));
590+
}

packages/wrangler/src/containers/deploy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { inferInstanceType, promiseSpinner } from "../cloudchamber/common";
2424
import {
2525
diffLines,
26+
filterTrailingCommaChanges,
2627
printLine,
2728
renderDiff,
2829
sortObjectRecursive,
@@ -312,7 +313,8 @@ export async function apply(
312313
const prev = JSON.stringify({ containers: [normalisedPrevApp] }, null, 2);
313314
const now = JSON.stringify({ containers: [nowContainer] }, null, 2);
314315

315-
const results = diffLines(prev, now);
316+
const rawResults = diffLines(prev, now);
317+
const results = filterTrailingCommaChanges(rawResults);
316318
const changes = results.find((l) => l.added || l.removed) !== undefined;
317319

318320
if (!changes) {

0 commit comments

Comments
 (0)