From a83ed7e97a0ea9bb64f756c7b41e5d664d26b8c5 Mon Sep 17 00:00:00 2001 From: Nitin Date: Mon, 12 Feb 2024 11:46:20 +0530 Subject: [PATCH] fix: updates --- .../blade/scripts/generateBundleSizeInfo.js | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/blade/scripts/generateBundleSizeInfo.js b/packages/blade/scripts/generateBundleSizeInfo.js index f3691b81492..4869042a0c2 100644 --- a/packages/blade/scripts/generateBundleSizeInfo.js +++ b/packages/blade/scripts/generateBundleSizeInfo.js @@ -36,7 +36,7 @@ const main = async () => { 'VisuallyHidden', ]; const sizes = []; - const sizeLimitConfig = []; + // Get all the components name exported from the bundle and add them to the size-limit configuration indexPaths.forEach((indexPath) => { const fileContent = fs.readFileSync(path.resolve(__dirname, `../${indexPath}`), 'utf8'); @@ -55,15 +55,25 @@ const main = async () => { const componentName = node.exported.name; // We don't want to add Icon components to the size-limit configuration - if (!(excludedComponents.includes(componentName) || componentName.startsWith('Base'))) { + if ( + !( + excludedComponents.includes(componentName) || + componentName.startsWith('Base') || + componentName === 'default' + ) + ) { exportedComponents.push(componentName); } }, + ExportNamedDeclaration: ({ node }) => { + if (node.specifiers[0].exported.name === 'default') + console.log('specifiers->', node.source.value); + }, }); console.log('🚀 ~ indexPaths.forEach ~ exportedComponents:', exportedComponents); - if (exportedComponents.length > 0 && !exportedComponents.includes('default')) { + if (exportedComponents.length > 0) { const imports = exportedComponents.join(', '); // Write size-limit configuration to .size-limit.json for each component fs.writeFileSync( @@ -84,23 +94,23 @@ const main = async () => { 2, ), ); - } - // Run size-limit command and capture the output to gather size information - const { stdout } = execa.commandSync('yarn size-limit --json'); + // Run size-limit command and capture the output to gather size information + const { stdout } = execa.commandSync('yarn size-limit --json'); - // Process the size-limit output to extract relevant information - const jsonLikeString = stdout - .split('\n') // remove new line chars => [] - .map((item) => item.trim()) // remove whitespace - .filter((item) => item !== '') // filter empty array items - .join(''); + // Process the size-limit output to extract relevant information + const jsonLikeString = stdout + .split('\n') // remove new line chars => [] + .map((item) => item.trim()) // remove whitespace + .filter((item) => item !== '') // filter empty array items + .join(''); - sizes.push( - JSON.parse( - jsonLikeString.substring(jsonLikeString.indexOf('[') + 1, jsonLikeString.indexOf(']')), - ), - ); + sizes.push( + JSON.parse( + jsonLikeString.substring(jsonLikeString.indexOf('[') + 1, jsonLikeString.indexOf(']')), + ), + ); + } }); // Write the gathered size information to the specified file