UNPKG

@tamyla/ui-components-react

Version:

React-based UI component library with Factory Bridge pattern - integrates seamlessly with @tamyla/ui-components. Enhanced AI agent discoverability with structured component registry, comprehensive Storybook (8 components), and detailed guides.

93 lines (74 loc) • 3.37 kB
import fs from 'fs'; import path from 'path'; /** * Bundle Certification Script * Validates that styled-components and other peer dependencies are properly externalized * to prevent runtime errors like "z.div is not a function" */ const PEER_DEPENDENCIES = ['styled-components', 'react', 'react-dom']; const MAX_BUNDLE_SIZE_KB = 300; // Alert if bundle exceeds this size const MIN_EXTERNAL_IMPORTS = 3; // Should have at least react, react-dom, styled-components function validateBundle() { try { const bundlePath = path.resolve('dist/index.esm.js'); if (!fs.existsSync(bundlePath)) { console.error('āŒ Bundle not found. Run "npm run build" first.'); process.exit(1); } const content = fs.readFileSync(bundlePath, 'utf8'); const bundleSizeKB = (content.length / 1024); console.log('šŸ” Bundle Certification Report'); console.log('================================'); console.log(`šŸ“¦ Bundle size: ${bundleSizeKB.toFixed(1)} KB`); // Check bundle size if (bundleSizeKB > MAX_BUNDLE_SIZE_KB) { console.log(`āš ļø Warning: Bundle size exceeds ${MAX_BUNDLE_SIZE_KB}KB threshold`); } else { console.log('āœ… Bundle size is within acceptable limits'); } // Check peer dependencies externalization const externalizedDeps = []; const bundledDeps = []; PEER_DEPENDENCIES.forEach(dep => { const hasImport = content.includes(`from"${dep}"`) || content.includes(`from "${dep}"`) || content.includes(`from'${dep}'`) || content.includes(`from '${dep}'`); const mentions = (content.match(new RegExp(dep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g')) || []).length; if (hasImport && mentions <= 5) { externalizedDeps.push(dep); console.log(`āœ… ${dep}: Properly externalized (${mentions} mentions)`); } else if (mentions > 10) { bundledDeps.push(dep); console.log(`āŒ ${dep}: Appears to be bundled (${mentions} mentions)`); } else { console.log(`āš ļø ${dep}: Unclear status (${mentions} mentions)`); } }); // Validation results console.log('\nšŸ“‹ Certification Summary'); console.log('========================'); if (bundledDeps.length > 0) { console.log('āŒ CERTIFICATION FAILED'); console.log(`Bundled dependencies found: ${bundledDeps.join(', ')}`); console.log('These should be externalized to prevent runtime errors.'); process.exit(1); } if (externalizedDeps.length < MIN_EXTERNAL_IMPORTS) { console.log('āš ļø Warning: Fewer external imports than expected'); } console.log('āœ… CERTIFICATION PASSED'); console.log(`External dependencies: ${externalizedDeps.join(', ')}`); console.log('Bundle is ready for production use.'); // Show import sample for verification const firstLine = content.split('\n')[0]; if (firstLine.length > 100) { console.log(`\nšŸ“„ Import sample: ${firstLine.substring(0, 100)}...`); } } catch (error) { console.error('āŒ Bundle certification failed:', error.message); process.exit(1); } } // Run validation validateBundle();