Repository navigation
feat(bundlecheck): Add package exports analysis and installer - #496
Merged
aversini merged 5 commits intoFeb 1, 2026
Merged
Conversation
Introduce named-export analysis for npm packages by parsing TypeScript declaration files and a temporary installer to fetch packages. - Add src/exports.ts: parses .d.ts files (with re-exports), extracts named/runtime exports and returns counts. - Add src/exports-installer.ts: safely installs a package into a temp dir (pnpm preferred, npm fallback), validates registry, returns parsed exports and resolved version, and exposes an alias for backward compatibility. - Add getPackageExports API in src/index.ts that installs the package and returns structured PackageExports (including runtime vs type-only counts). - Integrate export info into bundling flow: bundler now imports getNamedExports and includes namedExportCount in BundleResult; display shows export summary. - Persist named export count in cache: add named_export_count column (with migration), include value in getCachedResult/setCachedResult. - Update README to document getPackageExports usage, types and examples. These changes enable consumers to inspect package named exports (and runtime-only exports) and persist that metadata for faster subsequent checks.
Add comprehensive unit tests for export discovery and the package installer. Two new test suites were added: exports.test.ts covers parsing TypeScript declaration files (functions, classes, consts, types, interfaces, enums, re-exports, aliasing, common paths, error handling, circular import protection, sorting and deduplication), and exports-installer.test.ts covers installing packages in a temp dir (pnpm/npm selection, registry handling/validation, package.json writing, reading installed version, cleanup on success/failure, and calling getNamedExports). Also update index.test.ts to mock and test getPackageExports behavior (resolving versions, passing registry, and mapping exports/runtimeExports) by mocking installPackage.
There was a problem hiding this comment.
Pull request overview
This pull request adds a comprehensive package exports analysis feature to the bundlecheck tool, enabling users to programmatically retrieve and display the named exports of npm packages by analyzing their TypeScript declarations.
Changes:
- Introduces a new public API method
getPackageExports()for fetching named exports and runtime exports from npm packages - Adds CLI display enhancements to show export counts in bundle analysis results
- Implements core parsing logic for TypeScript declaration files with recursive re-export handling
- Updates cache schema to store named export counts with backward-compatible migration
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/bundlecheck/src/index.ts |
Adds getPackageExports() public API function, new types (PackageExport, PackageExports), and integrates namedExportCount into BundleStats |
packages/bundlecheck/src/exports.ts |
Implements TypeScript declaration file parsing with regex-based export extraction, recursive re-export following, and duplicate detection |
packages/bundlecheck/src/exports-installer.ts |
Provides package installation utilities with temporary directory management, registry validation, and pnpm/npm fallback logic |
packages/bundlecheck/src/bundler.ts |
Integrates export counting into bundle analysis workflow by calling getNamedExports() and adding namedExportCount to results |
packages/bundlecheck/src/cache.ts |
Extends cache schema with named_export_count column and implements backward-compatible migration for existing databases |
packages/bundlecheck/src/bundlecheck.ts |
Updates CLI output to display export information with intelligent formatting (shows names, count, or fallback message) |
packages/bundlecheck/src/__tests__/exports.test.ts |
Comprehensive unit tests covering all export types, edge cases (circular imports, aliasing, type detection), and error handling |
packages/bundlecheck/src/__tests__/exports-installer.test.ts |
Tests for package installation, registry handling, pnpm/npm detection, cleanup, and security validation |
packages/bundlecheck/src/__tests__/index.test.ts |
API integration tests for getPackageExports() covering version resolution, registry options, and export mapping |
packages/bundlecheck/README.md |
Adds documentation for getPackageExports() API with usage examples, type definitions, and updates to BundleStats type |
Improve and standardize comments and JSDoc across the bundlecheck package. Changes include wrapping long comment lines, adding punctuation, clarifying regex/pattern explanations, adding small JSDoc blocks (e.g., migrations, parse helpers), and tidying comment wording in files: bundlecheck.ts, bundler.ts, cache.ts, defaults.ts, exports-installer.ts, exports.ts, and index.ts. These are non-functional, documentation-only changes aimed at readability and maintainability.
aversini
deleted the
feat(bundlecheck)-Add-package-exports-analysis-and-installer
branch
February 1, 2026 16:56
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for retrieving and displaying the named exports of npm packages in the
bundlechecktool. It introduces a new API method, updates the CLI and caching logic to include export counts, and adds comprehensive tests for the new functionality.New API & Documentation:
getPackageExportsfunction to the public API, allowing users to fetch all named exports (including types) and runtime exports from an npm package by analyzing its TypeScript declarations. Documentation and usage examples were added toREADME.md. [1] [2] [3] [4]CLI and Display Improvements:
bundlecheck.tsto display a summary of named exports, showing either the export names, the count, or a fallback message, depending on the available data. [1] [2]Core Logic & Caching:
namedExportCountfield, which is stored and retrieved from the cache database. Migrations ensure backward compatibility for existing caches. [1] [2] [3] [4] [5] [6] [7] [8] [9]Testing:
exports-installerlogic and thegetPackageExportsAPI, covering scenarios for package installation, registry handling, cleanup, and export mapping. [1] [2] [3]