diff --git a/.github/actions/file-diff/index.js b/.github/actions/file-diff/index.js index bf7fce5a54d..b12ba2869ae 100644 --- a/.github/actions/file-diff/index.js +++ b/.github/actions/file-diff/index.js @@ -149,33 +149,31 @@ async function run() { ] : []), ], - ...fileMap.entries(), - ] - .reduce( - ( - table, - [readableFilename, { byteSize = 0, diffByteSize = 0 }] - ) => { - // @todo readable filename can be linked to html diff of the file? - // https://github.com/adobe/spectrum-css/pull/2093/files#diff-6badd53e481452b5af234953767029ef2e364427dd84cdeed25f5778b6fca2e6 - const row = [ - readableFilename, - byteSize === 0 ? "**removed**" : bytesToSize(byteSize), - diffByteSize === 0 ? "" : bytesToSize(diffByteSize), - ]; - - if (hasDiff && diffByteSize > 0) { - if (byteSize === 0) row.push("", ""); - else { - row.push(printChange(diffByteSize - byteSize), ""); - } + ].map((row) => `| ${row.join(" | ")} |`), + ...fileMap.entries().reduce( + ( + table, + [readableFilename, { byteSize = 0, diffByteSize = 0 }] + ) => { + // @todo readable filename can be linked to html diff of the file? + // https://github.com/adobe/spectrum-css/pull/2093/files#diff-6badd53e481452b5af234953767029ef2e364427dd84cdeed25f5778b6fca2e6 + const row = [ + readableFilename, + byteSize === 0 ? "**removed**" : bytesToSize(byteSize), + diffByteSize === 0 ? "" : bytesToSize(diffByteSize), + ]; + + if (hasDiff && diffByteSize > 0) { + if (byteSize === 0) row.push("", ""); + else { + row.push(printChange(diffByteSize - byteSize), ""); } + } - return [...table, row]; - }, - [] - ) - .map((row) => `| ${row.join(" | ")} |`), + return [...table, row]; + }, + [] + ).map((row) => `| ${row.join(" | ")} |`), ); markdown.push(...md); diff --git a/.github/actions/file-diff/utilities.js b/.github/actions/file-diff/utilities.js index f905d77b127..a4aa91331f6 100644 --- a/.github/actions/file-diff/utilities.js +++ b/.github/actions/file-diff/utilities.js @@ -62,12 +62,20 @@ function debugEmptyDirectory(path, pattern, { core }) { * @returns {string} The size in human readable format */ exports.bytesToSize = function (bytes) { + if (!bytes) return "-"; if (bytes === 0) return "0"; const sizes = ["bytes", "KB", "MB", "GB", "TB"]; + // Determine the size identifier to use (KB, MB, etc) const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - if (i === 0) return (bytes / 1000).toFixed(2) + " " + sizes[1]; + + if (i === 0) { + const value = (bytes / 1000).toFixed(2); + if (value === "0.00") return "< 0.01 KB"; + return value + " " + sizes[1]; + } + return (bytes / Math.pow(1024, i)).toFixed(2) + " " + sizes[i]; };