chore(dev): refactor frontend bundle report

This commit is contained in:
syuilo 2026-06-24 15:08:43 +09:00
commit 1173550784
2 changed files with 2 additions and 11 deletions

View file

@ -530,19 +530,13 @@ function renderFrontendBundleReport(before, after) {
return lines.join('\n');
}
function renderVisualizerArtifactLink() {
const artifactUrl = process.env.FRONTEND_BUNDLE_REPORT_ARTIFACT_URL;
const artifactName = process.env.FRONTEND_BUNDLE_REPORT_ARTIFACT_NAME || 'frontend-bundle-report';
const htmlFile = process.env.FRONTEND_BUNDLE_REPORT_HTML_FILE || 'frontend-bundle-visualizer.html';
return `> [Bundle visualizer HTML](${artifactUrl}) is included in the ${code(artifactName)} artifact as ${code(htmlFile)}.`;
}
const args = process.argv.slice(2);
const [beforeDir, afterDir, beforeStatsFile, afterStatsFile, outFile] = args;
const before = await collectReport(beforeDir);
const after = await collectReport(afterDir);
const beforeStats = JSON.parse(await fs.readFile(beforeStatsFile, 'utf8'));
const afterStats = JSON.parse(await fs.readFile(afterStatsFile, 'utf8'));
const visualizerArtifactLink = `> [Bundle visualizer HTML](${process.env.FRONTEND_BUNDLE_REPORT_ARTIFACT_URL}) is included in the ${code('frontend-bundle-visualizer')} artifact as ${code('frontend-bundle-visualizer.html')}.`;
const body = [
marker,
@ -555,7 +549,7 @@ const body = [
'',
renderFrontendBundleReport(collectVisualizerReport(beforeStats), collectVisualizerReport(afterStats)),
'',
renderVisualizerArtifactLink(),
visualizerArtifactLink,
].join('\n');
await fs.writeFile(outFile, body);

View file

@ -141,8 +141,6 @@ jobs:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
FRONTEND_BUNDLE_REPORT_ARTIFACT_URL: ${{ steps.upload-bundle-visualizer.outputs.artifact-url }}
FRONTEND_BUNDLE_REPORT_ARTIFACT_NAME: frontend-bundle-visualizer
FRONTEND_BUNDLE_REPORT_HTML_FILE: frontend-bundle-visualizer.html
run: |
REPORT_DIR="$RUNNER_TEMP/frontend-bundle-report"
node after/.github/scripts/frontend-js-size.mjs before after "$REPORT_DIR/before-stats.json" "$REPORT_DIR/after-stats.json" "$REPORT_DIR/frontend-js-size-report.md"
@ -157,7 +155,6 @@ jobs:
REPORT_DIR="$RUNNER_TEMP/frontend-bundle-report"
test -s "$REPORT_DIR/before-stats.json"
test -s "$REPORT_DIR/after-stats.json"
test -s "$REPORT_DIR/frontend-bundle-visualizer.html"
test -s "$REPORT_DIR/frontend-js-size-report.md"
cat "$REPORT_DIR/frontend-js-size-report.md" >> "$GITHUB_STEP_SUMMARY"