Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bundle analyzer script #1626

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = {
'**/*.spec.tsx',
'./jest/setup.ts',
'./cypress/**',
'./analyzeTest.ts',
],
optionalDependencies: false,
peerDependencies: false,
Expand Down
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';

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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
},
"devDependencies": {
"@cypress/webpack-preprocessor": "^5.9.1",
"@discoveryjs/json-ext": "0.6.1",
"@swc/core": "1.3.19",
"@swc/jest": "^0.2.23",
"@testing-library/jest-dom": "^6.4.5",
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
Loading