Repository navigation
feat: add @node-cli/bundlecheck package #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e718cdc
feat: add @node-cli/bundlecheck package
aversini 026a0be
code review
aversini 441609d
Preserve package subpath in analysis and output
aversini d1aa2ba
Bump bundlecheck Node engine to >=20
aversini 492a31c
code review
aversini e420864
code review
aversini da7b13a
Update bundler.ts
aversini d9d3fba
code review
aversini 03ee924
Disable kleur when --boring flag is set
aversini 8fc58e3
Always show +/- sign for trend sizes
aversini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/swcrc", | ||
| "exclude": ["test"], | ||
| "jsc": { | ||
| "target": "es2022", | ||
| "parser": { | ||
| "syntax": "typescript" | ||
| }, | ||
| "externalHelpers": false | ||
| }, | ||
| "module": { | ||
| "type": "es6" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # @node-cli/bundlecheck | ||
|
|
||
|  | ||
|
|
||
| A CLI tool to check the bundle size of npm packages, similar to [bundlephobia.com](https://bundlephobia.com/). | ||
|
|
||
| ## Features | ||
|
|
||
| - Check bundle size of any npm package | ||
| - Support for specific package versions (e.g., `lodash@4.17.0`) | ||
| - Interactive version selection with `--versions` flag | ||
| - Bundle size trend analysis with `--trend` flag (bar graph across versions) | ||
| - Support for checking specific exports (tree-shaking) | ||
| - Automatic externalization of React and React-DOM | ||
| - Raw and gzip sizes with configurable compression level | ||
| - Fast bundling using esbuild (with pnpm support) | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install -g @node-cli/bundlecheck | ||
| ``` | ||
|
|
||
| Or use with npx: | ||
|
|
||
| ```bash | ||
| npx @node-cli/bundlecheck <package-name> | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Check entire package | ||
|
|
||
| ```bash | ||
| bundlecheck lodash | ||
| bundlecheck @mantine/core | ||
| ``` | ||
|
|
||
| ### Check a specific version | ||
|
|
||
| ```bash | ||
| bundlecheck lodash@4.17.0 | ||
| bundlecheck @versini/ui-panel@1.0.0 | ||
| ``` | ||
|
|
||
| ### Choose version interactively | ||
|
|
||
| ```bash | ||
| bundlecheck lodash --versions | ||
| bundlecheck @mantine/core --versions | ||
| ``` | ||
|
|
||
| This will fetch available versions from npm and let you select one from a list. | ||
|
|
||
| ### Show bundle size trend | ||
|
|
||
| ```bash | ||
| bundlecheck lodash --trend # default: 5 versions | ||
| bundlecheck clsx --trend 3 # custom: 3 versions | ||
| ``` | ||
|
|
||
| This analyzes recent versions and displays a bar graph showing how the bundle size has evolved: | ||
|
|
||
| ``` | ||
| Bundle Size Trend: clsx | ||
| ──────────────────────────────────────────────────────────── | ||
|
|
||
| Gzip Size: | ||
| 2.1.1 ██████████████████████████████ 331 B | ||
| 2.0.0 █████████████████████████████ 321 B | ||
| 1.2.0 █████████████████████████████ 318 B | ||
| 1.0.4 ████████████████████████████ 308 B | ||
| 1.0.1 ██████████████████████████ 285 B | ||
|
|
||
| Raw Size: | ||
| 2.1.1 ██████████████████████████████ 527 B | ||
| ... | ||
|
|
||
| ──────────────────────────────────────────────────────────── | ||
| Change from 1.0.1 to 2.1.1: | ||
| Gzip: +46 B (+16.1%) | ||
| Raw: +108 B (+25.8%) | ||
| ``` | ||
|
|
||
| ### Check specific exports (tree-shaking) | ||
|
|
||
| ```bash | ||
| bundlecheck @mantine/core "ScrollArea,Button" | ||
| bundlecheck lodash "debounce,throttle" | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| | Flag | Short | Description | | ||
| | ------------------- | ----------- | ------------------------------------------------------- | | ||
| | `--help` | `-h` | Display help instructions | | ||
| | `--version` | `-v` | Output the current version | | ||
| | `--versions` | `-V` | Choose from available package versions interactively | | ||
| | `--trend [N]` | `-t [N]` | Show bundle size trend for N versions (default: 5) | | ||
| | `--boring` | `-b` | Do not use color output | | ||
| | `--gzipLevel <n>` | `-g <n>` | Gzip compression level (1-9, default: 5) | | ||
| | `--external <pkgs>` | `-e <pkgs>` | Comma-separated additional packages to mark as external | | ||
| | `--noExternal` | `-n` | Do not mark any packages as external | | ||
|
aversini marked this conversation as resolved.
|
||
|
|
||
| ### Examples | ||
|
|
||
| ```bash | ||
| # Check the entire lodash package | ||
| bundlecheck lodash | ||
|
|
||
| # Check a specific version | ||
| bundlecheck lodash@4.17.0 | ||
| bundlecheck @versini/ui-panel@1.0.0 | ||
|
|
||
| # Check specific exports from @mantine/core | ||
| bundlecheck @mantine/core "ScrollArea,Button" | ||
|
|
||
| # Check react itself (without marking it as external) | ||
| bundlecheck react -n | ||
|
|
||
| # Add vue and svelte as additional externals | ||
| bundlecheck some-package --external "vue,svelte" | ||
|
|
||
| # Use a different gzip compression level | ||
| bundlecheck lodash --gzipLevel 6 | ||
|
|
||
| # Choose version interactively | ||
| bundlecheck lodash --versions | ||
|
|
||
| # Show bundle size trend (default: 5 versions) | ||
| bundlecheck lodash --trend | ||
|
|
||
| # Show bundle size trend for 3 versions | ||
| bundlecheck lodash --trend 3 | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. Creates a temporary directory | ||
| 2. Installs the specified npm package | ||
| 3. Creates an entry file importing the package/exports | ||
| 4. Bundles with esbuild (minified, tree-shaken) | ||
| 5. Reports raw and gzip sizes | ||
| 6. Cleans up temporary files | ||
|
|
||
| ## Default Externals | ||
|
|
||
| By default, `react` and `react-dom` are marked as external (not included in the bundle size) since most React-based packages expect these as peer dependencies. This matches how these packages would typically be used in a real application. | ||
|
|
||
| To include React/React-DOM in the bundle size calculation, use the `--no-external` flag. | ||
|
|
||
| ## License | ||
|
|
||
| MIT - see [LICENSE](./LICENSE) for details. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| { | ||
| "name": "@node-cli/bundlecheck", | ||
| "version": "1.0.0", | ||
| "license": "MIT", | ||
|
aversini marked this conversation as resolved.
|
||
| "author": "Arno Versini", | ||
| "description": "CLI tool to check the bundle size of npm packages (like bundlephobia)", | ||
| "type": "module", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/bundler.js" | ||
| } | ||
| }, | ||
| "bin": "dist/bundlecheck.js", | ||
| "files": [ | ||
| "dist", | ||
| "README.md" | ||
| ], | ||
| "node": ">=20", | ||
| "scripts": { | ||
| "build": "npm-run-all --serial clean build:types build:js build:barrel", | ||
| "build:barrel": "barrelsby --delete --directory dist --pattern \"**/*.d.ts\" --name \"index.d\"", | ||
| "build:js": "swc --strip-leading-paths --source-maps --out-dir dist src", | ||
| "build:types": "tsc", | ||
| "clean": "rimraf dist types coverage", | ||
| "comments:fix": "comments --merge-line-comments 'src/**/*.ts'", | ||
| "lint": "biome lint src", | ||
| "lint:fix": "biome check src --write --no-errors-on-unmatched", | ||
| "test": "vitest run --globals", | ||
| "test:coverage": "vitest run --coverage --globals", | ||
| "test:watch": "vitest --globals", | ||
| "watch": "swc --strip-leading-paths --watch --out-dir dist src" | ||
| }, | ||
| "dependencies": { | ||
| "@inquirer/select": "5.0.4", | ||
| "@node-cli/logger": "workspace:*", | ||
|
aversini marked this conversation as resolved.
|
||
| "@node-cli/parser": "workspace:*", | ||
| "esbuild": "0.27.2", | ||
| "kleur": "4.1.5", | ||
| "semver": "7.7.1" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "devDependencies": { | ||
| "@node-cli/comments": "workspace:*", | ||
| "@vitest/coverage-v8": "4.0.16", | ||
| "vitest": "4.0.16" | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.