From b49fc82c2bd0e47b40a7baa8ba439d90be31c814 Mon Sep 17 00:00:00 2001 From: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:59:16 +0100 Subject: [PATCH] add size reporter GH action (#4745) --- .github/workflows/node.yml | 1 + tracker/package.json | 1 + tracker/report-sizes.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 tracker/report-sizes.js diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index b5aec1de0..d2ddefe80 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -32,3 +32,4 @@ jobs: - run: npm run check-format --prefix ./assets - run: npm run test --prefix ./assets - run: npm run deploy --prefix ./tracker + - run: npm run report-sizes --prefix ./tracker diff --git a/tracker/package.json b/tracker/package.json index 35c3f40bf..d1b222583 100644 --- a/tracker/package.json +++ b/tracker/package.json @@ -2,6 +2,7 @@ "scripts": { "deploy": "node compile.js", "test": "npm run deploy && npx playwright test --config=./test/support/playwright.config.js", + "report-sizes": "node report-sizes.js", "start": "node test/support/server.js" }, "license": "MIT", diff --git a/tracker/report-sizes.js b/tracker/report-sizes.js new file mode 100644 index 000000000..01f63ab43 --- /dev/null +++ b/tracker/report-sizes.js @@ -0,0 +1,28 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const PrivTrackerDir = '../priv/tracker/js/'; + +const toReport = [ + 'plausible.js', + 'plausible.pageleave.js', + 'plausible.manual.pageleave.js', + 'plausible.hash.pageleave.js' +]; + +const results = []; + +toReport.forEach((filename) => { + const filePath = path.join(PrivTrackerDir, filename); + if (fs.statSync(filePath).isFile()) { + results.push({ + 'Filename': filename, + 'Real Size (Bytes)': fs.statSync(filePath).size, + 'Gzipped Size (Bytes)': execSync(`gzip -c -9 "${filePath}"`).length, + 'Brotli Size (Bytes)': execSync(`brotli -c -q 11 "${filePath}"`).length + }); + } +}); + +console.table(results)