Update frontend-js-size.yml

This commit is contained in:
syuilo 2026-06-20 14:55:54 +09:00
commit 4c9dd0e5ff

View file

@ -147,7 +147,7 @@ jobs:
.replaceAll('\\', '\\\\') .replaceAll('\\', '\\\\')
.replaceAll('{', '\\{') .replaceAll('{', '\\{')
.replaceAll('}', '\\}') .replaceAll('}', '\\}')
.replaceAll('%', '\\%'); .replaceAll('%', '\\\\%');
} }
function formatDiff(beforeSize, diff) { function formatDiff(beforeSize, diff) {
@ -171,13 +171,7 @@ jobs:
function entryDisplayName(entry) { function entryDisplayName(entry) {
if (!entry) return ''; if (!entry) return '';
return entry.displayName === entry.file || entry.hasOriginalFileName return entry.displayName || entry.file;
? entry.displayName
: `${entry.displayName} (${entry.file})`;
}
function hasOriginalFileName(key, chunk) {
return chunk.src != null || (key.startsWith('src/') && /\.(?:m?[jt]sx?|vue)$/.test(key));
} }
function findEntryKey(manifest) { function findEntryKey(manifest) {
@ -247,7 +241,6 @@ jobs:
key: stableKey, key: stableKey,
displayName, displayName,
file: builtFile.relativePath, file: builtFile.relativePath,
hasOriginalFileName: hasOriginalFileName(key, chunk),
size, size,
}); });
byFile.add(builtFile.relativePath); byFile.add(builtFile.relativePath);
@ -299,7 +292,7 @@ jobs:
const afterSize = afterEntry?.size ?? null; const afterSize = afterEntry?.size ?? null;
return { return {
key, key,
file: entryDisplayName(afterEntry ?? beforeEntry), name: entryDisplayName(afterEntry ?? beforeEntry),
beforeSize, beforeSize,
afterSize, afterSize,
diff: sizeDiff(beforeSize, afterSize), diff: sizeDiff(beforeSize, afterSize),
@ -314,11 +307,11 @@ jobs:
} }
const lines = [ const lines = [
'| File | Before | After | Diff |', '| Chunk | Before | After | Diff |',
'| --- | ---: | ---: | ---: |', '| --- | ---: | ---: | ---: |',
]; ];
for (const row of rows) { for (const row of rows) {
lines.push(`| ${escapeCell(row.file)} | ${formatBytes(row.beforeSize)} | ${formatBytes(row.afterSize)} | ${formatDiff(row.beforeSize, row.diff)} |`); lines.push(`| \`${escapeCell(row.name)}\` | ${formatBytes(row.beforeSize)} | ${formatBytes(row.afterSize)} | ${formatDiff(row.beforeSize, row.diff)} |`);
} }
return lines.join('\n'); return lines.join('\n');
} }
@ -328,7 +321,7 @@ jobs:
const entry = report.chunks[key]; const entry = report.chunks[key];
return { return {
key, key,
file: entryDisplayName(entry), name: entryDisplayName(entry),
size: entry.size, size: entry.size,
}; };
}); });
@ -340,18 +333,18 @@ jobs:
} }
const lines = [ const lines = [
'| File | Size |', '| Chunk | Size |',
'| --- | ---: |', '| --- | ---: |',
]; ];
for (const row of rows) { for (const row of rows) {
lines.push(`| ${escapeCell(row.file)} | ${formatBytes(row.size)} |`); lines.push(`| \`${escapeCell(row.name)}\` | ${formatBytes(row.size)} |`);
} }
return lines.join('\n'); return lines.join('\n');
} }
function topKeys(keys, before, after) { function topKeys(keys, before, after) {
return compareRows(keys, before, after) return compareRows(keys, before, after)
.sort((a, b) => b.sortSize - a.sortSize || a.file.localeCompare(b.file)) .sort((a, b) => b.sortSize - a.sortSize || a.name.localeCompare(b.name))
.slice(0, topLimit) .slice(0, topLimit)
.map((row) => row.key); .map((row) => row.key);
} }
@ -360,7 +353,7 @@ jobs:
return Math.abs(b.diff ?? 0) - Math.abs(a.diff ?? 0) return Math.abs(b.diff ?? 0) - Math.abs(a.diff ?? 0)
|| (b.diff ?? 0) - (a.diff ?? 0) || (b.diff ?? 0) - (a.diff ?? 0)
|| b.sortSize - a.sortSize || b.sortSize - a.sortSize
|| a.file.localeCompare(b.file); || a.name.localeCompare(b.name);
} }
function topDiffKeys(keys, before, after) { function topDiffKeys(keys, before, after) {
@ -382,23 +375,23 @@ jobs:
const commonChunkKeys = commonKeys(before, after); const commonChunkKeys = commonKeys(before, after);
const topRows = compareRows(topKeys(commonChunkKeys, before, after), before, after) const topRows = compareRows(topKeys(commonChunkKeys, before, after), before, after)
.sort((a, b) => b.sortSize - a.sortSize || a.file.localeCompare(b.file)); .sort((a, b) => b.sortSize - a.sortSize || a.name.localeCompare(b.name));
const diffRows = compareRows(topDiffKeys(commonChunkKeys, before, after), before, after) const diffRows = compareRows(topDiffKeys(commonChunkKeys, before, after), before, after)
.sort(compareDiffRows); .sort(compareDiffRows);
const addedRows = chunkRows(addedKeys(before, after), after) const addedRows = chunkRows(addedKeys(before, after), after)
.sort((a, b) => b.size - a.size || a.file.localeCompare(b.file)); .sort((a, b) => b.size - a.size || a.name.localeCompare(b.name));
const removedRows = chunkRows(removedKeys(before, after), before) const removedRows = chunkRows(removedKeys(before, after), before)
.sort((a, b) => b.size - a.size || a.file.localeCompare(b.file)); .sort((a, b) => b.size - a.size || a.name.localeCompare(b.name));
const startupKeys = new Set([ const startupKeys = new Set([
...before.startupKeys, ...before.startupKeys,
...after.startupKeys, ...after.startupKeys,
]); ]);
const startupRows = compareRows([...startupKeys].filter((key) => before.chunks[key] != null && after.chunks[key] != null), before, after) const startupRows = compareRows([...startupKeys].filter((key) => before.chunks[key] != null && after.chunks[key] != null), before, after)
.sort((a, b) => b.sortSize - a.sortSize || a.file.localeCompare(b.file)); .sort((a, b) => b.sortSize - a.sortSize || a.name.localeCompare(b.name));
const body = [ const body = [
marker, marker,
@ -406,7 +399,7 @@ jobs:
'', '',
'### Top 10 largest chunk diffs', '### Top 10 largest chunk diffs',
'', '',
markdownTable(diffRows, '_No JavaScript chunk size changes found._'), markdownTable(diffRows, '_No chunk size changes found._'),
'', '',
'### Top 10 largest chunks', '### Top 10 largest chunks',
'<details>', '<details>',
@ -415,17 +408,17 @@ jobs:
'', '',
'</details>', '</details>',
'', '',
'### Added chunks', `### Added chunks (${addedRows.length})`,
'<details>', '<details>',
'', '',
markdownChunkTable(addedRows, '_No JavaScript chunks added._'), markdownChunkTable(addedRows, '_No chunks added._'),
'', '',
'</details>', '</details>',
'', '',
'### Removed chunks', `### Removed chunks (${removedRows.length})`,
'<details>', '<details>',
'', '',
markdownChunkTable(removedRows, '_No JavaScript chunks removed._'), markdownChunkTable(removedRows, '_No chunks removed._'),
'', '',
'</details>', '</details>',
'', '',