Skip to content

Commit

Permalink
fix: adjust more complex var whitespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
castastrophe committed May 7, 2024
1 parent 748ea97 commit 3c38cda
Show file tree
Hide file tree
Showing 26 changed files with 2,606 additions and 857 deletions.
38 changes: 9 additions & 29 deletions .github/actions/file-diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ async function run() {
`**Total size**: ${bytesToSize(overallHeadSize)}<sup>*</sup>`,
];

let summaryTable = [];

if (sections.length === 0) {
summary.push(...["", " 🎉 No changes detected in any packages"]);
} else {
Expand All @@ -96,7 +94,7 @@ async function run() {
*/
let changeSummary = "";
if (baseOutput.size > 0 && hasBase && hasChange) {
changeSummary = `**Total change (Δ)**: ${printChange(overallHeadSize, overallBaseSize)} (${printPercentChange(overallHeadSize, overallBaseSize)})`;
changeSummary = `**Total change (Δ)**: ${printChange(overallBaseSize, overallHeadSize)} (${printPercentChange(overallHeadSize, overallBaseSize)})`;
} else if (baseOutput.size > 0 && hasBase && !hasChange) {
changeSummary = `No change in file sizes`;
}
Expand All @@ -105,15 +103,11 @@ async function run() {
summary.push(
changeSummary,
"",
"<small><em>Table reports on changes to a package's main file. Other changes can be found in the collapsed <a href=\"#details\">Details</a> section below.</em></small>",
""
);
}

markdown.push(
"<a name=\"details\"></a>",
`<details>`,
`<summary><b>Details</b></summary>`,
""
);

Expand Down Expand Up @@ -151,18 +145,14 @@ async function run() {
) {
data.push(printChange(headMainSize, baseMainSize));
}

if (data.length > 0) {
summaryTable.push([name, bytesToSize(headMainSize), data]);
}
}


const md = ["", `#### ${name}`, ""];
md.push(
...[
["File", "Head", ...(hasBase ? ["Base", "Δ"] : [])],
[" - ", " - ", ...(hasBase ? [" - ", " - "] : [])],
["File", "Head", ...(hasBase ? ["Base", "Δ"] : []), "Minified", "Gzipped"],
[" - ", " - ", ...(hasBase ? [" - ", " - "] : []), "-", "-"],
].map((row) => `| ${row.join(" | ")} |`),
...[...fileMap.entries()]
.reduce(
Expand All @@ -180,8 +170,10 @@ async function run() {
isRemoved(headByteSize, baseByteSize) ? " - " : bytesToSize(headByteSize),
...(hasBase ? [
bytesToSize(baseByteSize),
isRemoved(headByteSize, baseByteSize) ? "🚨 deleted, moved, or renamed" : isNew(headByteSize, baseByteSize) ? "🎉 **new**" : `${printChange(headByteSize, baseByteSize)}${difference(headByteSize, baseByteSize) !== 0 ? ` (${printPercentChange(headByteSize , baseByteSize)})` : ""}`,
isRemoved(headByteSize, baseByteSize) ? "🚨 deleted, moved, or renamed" : isNew(headByteSize, baseByteSize) ? "🎉 **new**" : `${printChange(headByteSize, baseByteSize)}${difference(baseByteSize, headByteSize) !== 0 ? ` (${printPercentChange(headByteSize , baseByteSize)})` : ""}`,
] : []),
"-", // @todo: add minified size here
"-" // @todo: add gzipped size here
]
];
},
Expand All @@ -193,18 +185,7 @@ async function run() {
markdown.push(...md);
});

markdown.push("", `</details>`);
}

if (summaryTable.length > 0) {
// Add the headings to the summary table if it contains data
summaryTable = [
["Package", "Size", ...(hasBase ? ["Δ"] : [])],
["-", "-", ...(hasBase ? ["-"] : [])],
...summaryTable,
];

summary.push(...summaryTable.map((row) => `| ${row.join(" | ")} |`));
markdown.push("");
}

markdown.push(
Expand Down Expand Up @@ -276,7 +257,7 @@ const isNew = (v1, v0) => (v1 && v1 > 0) && (!v0 || v0 === 0);
* @param {number} difference
* @returns {string}
*/
const printChange = function (v0, v1) {
const printChange = function (v1, v0) {
/** Calculate the change in size: v1 - v0 = change */
const d = difference(v1, v0);
return d === 0
Expand Down Expand Up @@ -321,9 +302,8 @@ const makeTable = function (PACKAGES, filePath, path) {
// Check if a minified output of this file exists
if (existsSync(join(dirname(packagePath), main.replace(/\.css$/, ".min.css")))) {
mainFile = mainFile.replace(/\.css$/, ".min.css");
} else {

}
}
}

const mainFileOnly = [...fileMap.keys()].filter((file) => file.endsWith(mainFile));
Expand Down

0 comments on commit 3c38cda

Please sign in to comment.