{"library":"package-build-stats","title":"npm Package Build Stats Analyzer","description":"package-build-stats is a JavaScript/TypeScript library designed to analyze the build size and performance metrics of npm packages. It simulates a package build process, including installation, minification (with Terser or esbuild), and gzipping, to provide detailed statistics such as gzipped size, uncompressed size, and bundle composition. The library is currently at version 8.2.7 and demonstrates an active release cadence with frequent updates and improvements. A key differentiator is its ability to utilize various package managers like Bun, pnpm, or Yarn for faster installations, and its beta support for analyzing local packages during development. It also allows for granular analysis by specifying custom top-level exports, beyond just the default export, and exposes a comprehensive event queue for monitoring build lifecycle events. This tool is the robust backend engine behind services like Bundlephobia, making it suitable for production use cases requiring accurate package size insights.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install package-build-stats"],"cli":null},"imports":["import { getPackageStats } from 'package-build-stats'","import { eventQueue } from 'package-build-stats'","import type { PackageStatsResult, BuildOptions } from 'package-build-stats'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { getPackageStats, eventQueue } from 'package-build-stats';\n\n// Listen to all lifecycle events during the build process\neventQueue.on('*', (eventName, data) => {\n  console.log(`[Event] ${eventName}:`, data);\n});\n\nasync function analyzePackage() {\n  try {\n    console.log('Analyzing moment@latest with Bun...');\n    const results = await getPackageStats('moment', {\n      client: 'bun', // Use Bun for faster installs\n      minifier: 'esbuild', // Faster minification\n      customImports: ['default', 'localeData'], // Analyze specific exports\n      installTimeout: 60000 // Increase timeout for potentially slow installs\n    });\n\n    console.log('\\n--- Build Stats for moment ---');\n    console.log(`Package: ${results.name}@${results.version}`);\n    console.log(`Minified size (gzipped): ${results.gzip} bytes`);\n    console.log(`Minified size (uncompressed): ${results.size} bytes`);\n    console.log('Details:', JSON.stringify(results, null, 2));\n\n    // Example for a specific version\n    console.log('\\nAnalyzing lodash@4.17.21 with pnpm...');\n    const lodashResults = await getPackageStats('lodash@4.17.21', { client: 'pnpm' });\n    console.log(`Package: ${lodashResults.name}@${lodashResults.version}`);\n    console.log(`Minified size (gzipped): ${lodashResults.gzip} bytes`);\n  } catch (error) {\n    console.error('Failed to analyze package:', error);\n    if (error instanceof Error) {\n      console.error(error.message);\n    }\n  }\n}\n\nanalyzePackage();","lang":"typescript","description":"This quickstart demonstrates how to import and utilize the `getPackageStats` function with various options, including custom package managers and specific imports, while also showing how to subscribe to lifecycle events for real-time feedback during package analysis.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}