Skip to content

feat(bundlecheck): Add library API to access data programmatically - #487

Merged
aversini merged 5 commits into
mainfrom
feat(bundlecheck)-Add-library-API-to-access-data-programmatically
Jan 31, 2026
Merged

aversini merged 5 commits into
mainfrom
feat(bundlecheck)-Add-library-API-to-access-data-programmatically

Conversation

@aversini

Copy link
Copy Markdown
Collaborator

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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and getPackageVersions for 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

Comment thread packages/bundlecheck/src/index.ts Outdated
Comment thread packages/bundlecheck/src/index.ts Outdated
Comment thread packages/bundlecheck/src/index.ts Outdated
Comment thread packages/bundlecheck/src/__tests__/index.test.ts Outdated
Comment thread packages/bundlecheck/src/index.ts Outdated
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
aversini merged commit c1b2893 into main Jan 31, 2026
6 checks passed
@aversini
aversini deleted the feat(bundlecheck)-Add-library-API-to-access-data-programmatically branch January 31, 2026 21:20
@aversini aversini mentioned this pull request Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants