Skip to content

Commit

Permalink
Fix bundle analyzer script
Browse files Browse the repository at this point in the history
Signed-off-by: Gowtham Shanmugasundaram <[email protected]>
  • Loading branch information
GowthamShanmugam committed Oct 8, 2024
1 parent 6f69f2e commit d136c67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 8 additions & 7 deletions analyzeTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs';
import { parseChunked } from '@discoveryjs/json-ext';

Check failure on line 2 in analyzeTest.ts

View workflow job for this annotation

GitHub Actions / resolve-dependencies (16)

'@discoveryjs/json-ext' should be listed in the project's dependencies, not devDependencies

const pluginName = process.env.PLUGIN;
const MAX_ASSET_SIZE = 17; //17 MiB
Expand All @@ -12,17 +13,17 @@ const stringifyMiB = (value: ReturnType<typeof toMiB>): string =>

const getParsedStatFile = () => {
const filePath = getStatsFilePath();
const statsFile = fs.readFileSync(filePath, 'utf-8');
return JSON.parse(statsFile);

return parseChunked(fs.createReadStream(filePath, { encoding: 'utf8' }));
};

type BundleDataMap = Record<string, number>;

// [Valid Bundles, Violating Bunldes]
type GetBundleInformation = () => [BundleDataMap, BundleDataMap];
type GetBundleInformation = () => Promise<[BundleDataMap, BundleDataMap]>;

const getBundleInformation: GetBundleInformation = () => {
const statsData = getParsedStatFile();
const getBundleInformation: GetBundleInformation = async () => {
const statsData = await getParsedStatFile();
const validAssets = {};
const violatingAssets = {};

Expand All @@ -39,8 +40,8 @@ const getBundleInformation: GetBundleInformation = () => {
return [validAssets, violatingAssets];
};

const validateBuild = () => {
const [validAssets, violatingAssets] = getBundleInformation();
const validateBuild = async () => {
const [validAssets, violatingAssets] = await getBundleInformation();
if (Object.keys(violatingAssets).length > 0) {
// eslint-disable-next-line no-console
console.error('Assets are larger than expected', violatingAssets);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
"stylelint-config-sass-guidelines": "^8.0.0",
"stylelint-config-standard": "^22.0.0",
"stylelint-order": "^4.1.0",
"webpack-dev-server": "^4.15.2"
"webpack-dev-server": "^4.15.2",
"@discoveryjs/json-ext": "0.6.1"
},
"resolutions": {
"jest-environment-jsdom/jsdom": "^20.0.3",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,11 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@discoveryjs/[email protected]":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.6.1.tgz#593da7a17a31a72a874e313677183334a49b01c9"
integrity sha512-boghen8F0Q8D+0/Q1/1r6DUEieUJ8w2a1gIknExMSHBsJFOr2+0KUfHiVYBvucPwl3+RU5PFBK833FjFCh3BhA==

"@discoveryjs/json-ext@^0.5.0":
version "0.5.3"
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.3.tgz#90420f9f9c6d3987f176a19a7d8e764271a2f55d"
Expand Down

0 comments on commit d136c67

Please sign in to comment.