Skip to content

Commit

Permalink
chore: update workflows 5
Browse files Browse the repository at this point in the history
  • Loading branch information
WomB0ComB0 committed Oct 2, 2024
1 parent e54c0df commit cedaa8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
- name: Install dependencies
run: bun install
- name: Build app
env:
SKIP_BUILD_PRODUCT_REDIRECTS: 1
run: bun run build
- name: Install Playwright Browsers
run: bunx playwright install --with-deps
Expand All @@ -57,4 +59,4 @@ jobs:
with:
name: playwright-report
path: playwright-report/
retention-days: 30
retention-days: 30
4 changes: 3 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
- name: Install dependencies
run: bun install
- name: Build code
env:
SKIP_BUILD_PRODUCT_REDIRECTS: 1
run: bun run build
- name: Test code
run: bun run test
run: bun run test
27 changes: 14 additions & 13 deletions report-bundle-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// edited to work with the appdir by @raphaelbadia

// @ts-check
const gzSize = require('gzip-size');
const mkdirp = require('mkdirp');
const fs = require('fs');
const path = require('path');
import gzSize from 'gzip-size';
import mkdirp from 'mkdirp';
import fs from 'fs';
import path from 'path';

/** @typedef {{ raw: number, gzip: number }} ScriptSizes */
/** @typedef {Record<string, ScriptSizes>} PageSizes */
Expand Down Expand Up @@ -42,16 +42,16 @@ try {
fs.accessSync(nextMetaRoot, fs.constants.R_OK);
} catch (err) {
console.error(
`No build output found at "${nextMetaRoot}" - you may not have your working directory set correctly, or not have run "next build".`,
`No build output found at "${nextMetaRoot}" - you may not have your working directory set correctly, or not have run "next build".`
);
process.exit(1);
}

// if so, we can import the build manifest
/** @type {BuildManifest} */
const buildMeta = require(path.join(nextMetaRoot, 'build-manifest.json'));
const buildMeta = JSON.parse(fs.readFileSync(path.join(nextMetaRoot, 'build-manifest.json'), 'utf8'));
/** @type {AppDirManifest} */
const appDirMeta = require(path.join(nextMetaRoot, 'app-build-manifest.json'));
const appDirMeta = JSON.parse(fs.readFileSync(path.join(nextMetaRoot, 'app-build-manifest.json'), 'utf8'));

/** @type {Record<string, [number, number]>} */
const memoryCache = {};
Expand All @@ -63,12 +63,12 @@ const globalBundleSizes = getScriptSizes(globalBundle);
const allPageSizes = Object.entries(buildMeta.pages).reduce(
(acc, [pagePath, scriptPaths]) => {
const scriptSizes = getScriptSizes(
scriptPaths.filter((scriptPath) => !globalBundle.includes(scriptPath)),
scriptPaths.filter((scriptPath) => !globalBundle.includes(scriptPath))
);
acc[pagePath] = scriptSizes;
return acc;
},
/** @type {PageSizes} */ ({}),
/** @type {PageSizes} */({})
);

const globalAppDirBundle = buildMeta.rootMainFiles || [];
Expand All @@ -78,12 +78,12 @@ const globalAppDirBundleSizes = getScriptSizes(globalAppDirBundle);
const allAppDirSizes = Object.entries(appDirMeta.pages).reduce(
(acc, [pagePath, scriptPaths]) => {
const scriptSizes = getScriptSizes(
scriptPaths.filter((scriptPath) => !globalAppDirBundle.includes(scriptPath)),
scriptPaths.filter((scriptPath) => !globalAppDirBundle.includes(scriptPath))
);
acc[pagePath] = scriptSizes;
return acc;
},
/** @type {PageSizes} */ ({}),
/** @type {PageSizes} */({})
);

// format and write the output
Expand Down Expand Up @@ -114,7 +114,7 @@ function getScriptSizes(scriptPaths) {
acc.gzip += gzipSize;
return acc;
},
{ raw: 0, gzip: 0 },
{ raw: 0, gzip: 0 }
);
}

Expand All @@ -133,6 +133,7 @@ function getScriptSize(scriptPath) {
try {
const textContent = fs.readFileSync(p, encoding);
const rawSize = Buffer.byteLength(textContent, encoding);
// @ts-ignore
const gzipSize = gzSize.sync(textContent);
memoryCache[p] = [rawSize, gzipSize];
return [rawSize, gzipSize];
Expand All @@ -149,7 +150,7 @@ function getScriptSize(scriptPath) {
function getOptions(pathPrefix = process.cwd()) {
try {
/** @type {{nextBundleAnalysis?: Partial<Options>, name: string}} */
const pkg = require(path.join(pathPrefix, 'package.json'));
const pkg = JSON.parse(fs.readFileSync(path.join(pathPrefix, 'package.json'), 'utf8'));
return { ...pkg.nextBundleAnalysis, name: pkg.name };
} catch (error) {
console.error('Error reading package.json', error);
Expand Down

0 comments on commit cedaa8b

Please sign in to comment.