Skip to content

Commit

Permalink
chore: update workflows 8
Browse files Browse the repository at this point in the history
  • Loading branch information
WomB0ComB0 committed Oct 2, 2024
1 parent 12a49fb commit c698459
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"analyze": "cross-env ANALYZE=true next build",
"analyze": "cross-env ANALYZE=true next build && bun report-bundle-size.js",
"analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build",
"analyze:server": "cross-env BUNDLE_ANALYZE=server next build",
"build": "next build",
Expand Down
25 changes: 15 additions & 10 deletions report-bundle-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
// edited to work with the appdir by @raphaelbadia

// @ts-check
const gzipSize = require('gzip-size');
const mkdirp = require('mkdirp');
const fs = require('fs');
const path = require('path');
import { gzipSize } from 'gzip-size';
import { mkdirp } from 'mkdirp';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/** @typedef {{ raw: number, gzip: number }} ScriptSizes */
/** @typedef {Record<string, ScriptSizes>} PageSizes */
Expand Down Expand Up @@ -95,7 +99,8 @@ const rawData = JSON.stringify({
// log outputs to the gh actions panel
console.log(rawData);

mkdirp.sync(path.join(nextMetaRoot, 'analyze/'));
// Changed this line to use mkdirp directly
await mkdirp(path.join(nextMetaRoot, 'analyze/'));
fs.writeFileSync(path.join(nextMetaRoot, 'analyze/__bundle_analysis.json'), rawData);

// --------------
Expand All @@ -109,9 +114,9 @@ fs.writeFileSync(path.join(nextMetaRoot, 'analyze/__bundle_analysis.json'), rawD
function getScriptSizes(scriptPaths) {
return scriptPaths.reduce(
(acc, scriptPath) => {
const [rawSize, gzipSize] = getScriptSize(scriptPath);
const [rawSize, gzSize] = getScriptSize(scriptPath);
acc.raw += rawSize;
acc.gzip += gzipSize;
acc.gzip += gzSize;
return acc;
},
{ raw: 0, gzip: 0 }
Expand All @@ -133,9 +138,9 @@ function getScriptSize(scriptPath) {
try {
const textContent = fs.readFileSync(p, encoding);
const rawSize = Buffer.byteLength(textContent, encoding);
const gzipSizeValue = gzipSize.sync(textContent);
memoryCache[p] = [rawSize, gzipSizeValue];
return [rawSize, gzipSizeValue];
const gzSize = gzipSize.sync(textContent);
memoryCache[p] = [rawSize, gzSize];
return [rawSize, gzSize];
} catch (error) {
console.error(`Error reading file: ${p}`, error);
return [0, 0];
Expand Down

0 comments on commit c698459

Please sign in to comment.