Repository navigation
Conversation
Expose a programmatic Library API for @node-cli/bundlecheck: adds src/index.ts which implements getBundleStats, getBundleTrend, getPackageVersions and re-exports utilities (formatBytes, parsePackageSpecifier, clearCache, getCacheCount). Update package.json to include main and correct exports to point at dist/index.js. Expand README with detailed Programmatic Usage and API reference. Add comprehensive unit tests at src/__tests__/index.test.ts that mock underlying modules and cover caching, options, trend analysis, and utility helpers.
There was a problem hiding this comment.
Pull request overview
This PR adds a programmatic library API to @node-cli/bundlecheck, enabling developers to analyze npm package bundle sizes directly from their Node.js applications without using the CLI.
Changes:
- Exposes three main API functions:
getBundleStats,getBundleTrend, andgetPackageVersionsfor programmatic bundle analysis - Updates package.json to properly export the new library API as the main entry point
- Adds comprehensive documentation with usage examples and API reference in README
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| packages/bundlecheck/src/index.ts | Implements the library API with type definitions, main functions (getBundleStats, getBundleTrend, getPackageVersions), and re-exports of utility functions |
| packages/bundlecheck/src/tests/index.test.ts | Comprehensive unit tests covering all API functions, caching behavior, options handling, and edge cases |
| packages/bundlecheck/package.json | Updates main entry point and exports field to point to dist/index.js for library usage |
| packages/bundlecheck/README.md | Adds detailed "Programmatic Usage" section with examples, API reference tables, and utility function documentation |
Standardize and polish inline comments and JSDoc-style documentation across the bundlecheck package. Files updated: bundlecheck.ts, bundler.ts, cache.ts, defaults.ts, index.ts, trend.ts, versions.ts. Changes are primarily non-functional: add punctuation, clarify intent in comments, expand docblocks, improve error/message text clarity, and make cache/platform/registry notes more explicit. No behavioral changes intended.
Treat percent changes as null when the oldest size is zero. Update TrendChange types and JSDoc to allow rawPercent as number | null and clarify gzipPercent behavior. Add runtime guards in getBundleTrend to avoid dividing by zero and only call toFixed when percent is not null. Add a unit test covering the division-by-zero case and update README comments to match the new nullable semantics. Also include minor comment/export cleanup.
Update unit tests to assert that index.ts re-exports delegate to the underlying cache module. Rename imported cache functions to clearCacheMock/getCacheCountMock, import the re-exported clearCache and getCacheCount from index, and adjust tests to call the re-exported functions while verifying the underlying mocked functions are invoked (and return expected values). Also reorder a checkBundleSize import and add clarifying comments in the tests.
aversini
deleted the
feat(bundlecheck)-Add-library-API-to-access-data-programmatically
branch
January 31, 2026 21:20
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.
Expose a programmatic Library API for @node-cli/bundlecheck: adds src/index.ts which implements getBundleStats, getBundleTrend, getPackageVersions and re-exports utilities (formatBytes, parsePackageSpecifier, clearCache, getCacheCount). Update package.json to include main and correct exports to point at dist/index.js. Expand README with detailed Programmatic Usage and API reference. Add comprehensive unit tests at src/tests/index.test.ts that mock underlying modules and cover caching, options, trend analysis, and utility helpers.