├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── dependabot.yml │ └── nodejs.yml ├── .gitignore ├── .prettierrc.json ├── .vercelignore ├── .vscode ├── launch.json └── settings.json ├── API.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── api └── index.ts ├── package-lock.json ├── package.json ├── public ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── logo.png ├── logo.svg ├── robots.txt ├── safari-pinned-tab.svg └── site.webmanifest ├── src ├── browser.tsx ├── components │ ├── BarGraph.tsx │ ├── CarbonAd.tsx │ ├── Footer.tsx │ ├── Image.tsx │ ├── LinkedLogo.tsx │ ├── LinkedLogos.tsx │ ├── Logo.tsx │ ├── OctocatCorner.tsx │ ├── PageContainer.tsx │ ├── SearchBar.tsx │ ├── Sponsors.tsx │ └── Stats.tsx ├── page-props │ ├── common.ts │ ├── compare.ts │ └── results.ts ├── pages │ ├── 404.tsx │ ├── 500.tsx │ ├── _document.tsx │ ├── compare.tsx │ ├── index.tsx │ ├── parse-failure.tsx │ └── result.tsx ├── server.ts ├── types.ts └── util │ ├── backend │ ├── db-redis.ts │ ├── db.ts │ ├── lookup.ts │ ├── npm-stats.ts │ └── npm-wrapper.ts │ ├── badge.ts │ ├── constants.ts │ ├── not-found-error.ts │ ├── npm-api.ts │ └── npm-parser.ts ├── test ├── a-directory │ ├── a-nested-directory │ │ ├── example3.txt │ │ └── example4.txt │ ├── example1.txt │ └── example2.txt ├── hardlink │ └── orig.txt ├── npm-api.test.ts ├── npm-parser.test.ts └── npm-stats.test.ts ├── tsconfig.json └── vercel.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: styfle 2 | -------------------------------------------------------------------------------- /.github/workflows/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: monthly 7 | open-pull-requests-limit: 10 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: monthly 12 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | tags: 8 | - '!*' 9 | pull_request: 10 | workflow_dispatch: 11 | 12 | env: 13 | FORCE_COLOR: 2 14 | 15 | jobs: 16 | test: 17 | name: Node.js ${{ matrix.node }} on ${{ matrix.os }} 18 | timeout-minutes: 3 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | os: [ubuntu-latest] 23 | node: [22] 24 | runs-on: ${{ matrix.os }} 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@v4 28 | - name: Use Node.js ${{ matrix.node }} 29 | uses: actions/setup-node@v4 30 | with: 31 | node-version: ${{ matrix.node }} 32 | - run: corepack enable npm 33 | - run: npm --version 34 | - run: npm install 35 | - run: npm run lint 36 | - run: npm run test 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .DS_Store 4 | .env 5 | .next 6 | pages/*.js 7 | src/*.js 8 | test/hardlink/link 9 | dev.sh 10 | .now 11 | .vercel 12 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "typescript", 3 | "printWidth": 100, 4 | "tabWidth": 4, 5 | "useTabs": false, 6 | "semi": true, 7 | "singleQuote": true, 8 | "trailingComma": "all", 9 | "bracketSpacing": true, 10 | "bracketSameLine": false, 11 | "arrowParens": "avoid", 12 | "proseWrap": "never" 13 | } 14 | -------------------------------------------------------------------------------- /.vercelignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .DS_Store 4 | .env 5 | .next 6 | pages/*.js 7 | src/*.js 8 | dev.sh 9 | 10 | .github 11 | .vscode 12 | .prettierrc.json 13 | test 14 | *.md 15 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "attach", 10 | "name": "Attach", 11 | "port": 9229 12 | }, 13 | { 14 | "type": "node", 15 | "request": "launch", 16 | "name": "Launch Program", 17 | "program": "${workspaceFolder}/dist/src/server.js", 18 | "preLaunchTask": "tsc: build - tsconfig.json", 19 | "outFiles": [ 20 | "${workspaceFolder}/dist/**/*.js" 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib", 3 | "files.exclude": { 4 | "**/.git": true, 5 | "**/.svn": true, 6 | "**/.hg": true, 7 | "**/CVS": true, 8 | "**/.DS_Store": true, 9 | "node_modules": true, 10 | "dist": true, 11 | } 12 | } -------------------------------------------------------------------------------- /API.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | If you intend to use this API, please add your website to the list below and set your client's `user-agent` request header to match. 4 | 5 | If you forget to set a `user-agent`, you will likely be blocked. 6 | 7 | ## Users 8 | 9 | Current websites using this API: 10 | 11 | - https://badgen.net 12 | - https://cnpmjs.org 13 | - https://npm.taobao.org 14 | - https://bestofjs.org 15 | - https://socket.dev 16 | - [picocolors-size-benchmark](https://github.com/alexeyraspopov/picocolors/pull/76) 17 | - [dependencies-dashboard](https://github.com/shakib1729/dependencies-dashboard-main) 18 | 19 | ## Endpoints 20 | 21 | - v1: `GET /api.json` 22 | - v2: `GET /v2/api.json` 23 | 24 | You can use the npm package name and version (cached for up to one week): 25 | 26 | [`https://packagephobia.com/api.json?p=satori@0.4.3`](https://packagephobia.com/api.json?p=satori@0.4.3) 27 | 28 | Or just the npm package name, which will automatically use the latest version (cached for thirty seconds): 29 | 30 | [`https://packagephobia.com/api.json?p=satori`](https://packagephobia.com/api.json?p=satori) 31 | 32 | > This caching is done using a [`Cache-Control`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header, see [`server.ts`](https://github.com/styfle/packagephobia/blob/main/src/server.ts). 33 | 34 | ### Example response from v1 35 | 36 | ```json 37 | { 38 | "publishSize":3686131, 39 | "installSize":8724612 40 | } 41 | ``` 42 | 43 | ### Example response from v2 44 | 45 | ```json 46 | { 47 | "name": "satori", 48 | "version": "0.4.3", 49 | "publish": { 50 | "bytes": 3686131, 51 | "files": 19, 52 | "pretty": "3.52 MB", 53 | "color": "#007EC6" 54 | }, 55 | "install": { 56 | "bytes": 8724612, 57 | "files": 297, 58 | "pretty": "8.32 MB", 59 | "color": "#DFB317" 60 | } 61 | } 62 | ``` 63 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at abuse@ceriously.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://www.contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: https://www.contributor-covenant.org/ 46 | [version]: https://www.contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for considering contributing to Package Phobia! 4 | 5 | The goal of this project can be found in the README.md so this document will focus on building, running, and testing the code. 6 | 7 | ## Getting Started 8 | 9 | First, clone this repository. 10 | 11 | ```sh 12 | git clone https://github.com/styfle/packagephobia 13 | cd packagephobia 14 | ``` 15 | 16 | ### Redis 17 | 18 | You will need to run `redis` either locally or in the cloud such as [upstash.com](https://upstash.com/?ref=packagephobia). 19 | 20 | If you have docker, you can get started quickly with the following command. 21 | 22 | ```sh 23 | docker run -p 6379:6379 redis 24 | ``` 25 | 26 | ### Env 27 | 28 | Create a `.env` file in the root directory. 29 | 30 | ``` 31 | # required settings 32 | REDIS_URL="redis://127.0.0.1:6379" 33 | 34 | # optional settings 35 | PORT="3000" 36 | NPM_REGISTRY_URL="https://registry.npmjs.com" 37 | ``` 38 | 39 | ## Running the code 40 | 41 | Install [Vercel](https://vercel.com/download) CLI 42 | 43 | ```sh 44 | npm install -g vercel 45 | ``` 46 | 47 | Run the development environment 48 | 49 | ```sh 50 | vercel dev 51 | ``` 52 | 53 | Now the web app should be available at http://localhost:3000 54 | 55 | 56 | ## Testing the code 57 | 58 | Make sure the tests are passing. 59 | 60 | ``` 61 | npm run test 62 | ``` 63 | 64 | ## Deploying the code 65 | 66 | Each PR is automatically deployed to [Vercel](https://vercel.com/?utm_source=packagephobia) via the [GitHub Integration](https://vercel.com/github). 67 | 68 | If you want to deploy from the command line, you'll need to install [Vercel](https://vercel.com) CLI with `npm i -g vercel`. 69 | 70 | Then you can simply run `vercel` to deploy. 71 | 72 | ## Submitting a PR 73 | 74 | Wow you're doing great! Before you submit a Pull Request, please create an issue so that we can discuss the problem you are solving. When we're all on the same page, make sure you test the code and prettify the code. And please add additional tests if possible. 75 | 76 | ```sh 77 | npm run test 78 | npm run prettier 79 | ``` 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Steven 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Package Phobia 4 | [![tests](https://github.com/styfle/packagephobia/workflows/Tests/badge.svg)](https://github.com/styfle/packagephobia/actions?workflow=Tests) 5 | ![uptime](https://badgen.net/uptime-robot/week/m783908968-e68af1e88fe9d03309911b73) 6 | 7 | 8 | 9 | - ⚖️ Find the cost of adding a new dependency to your project 10 | - 🕗 Save yourself time and disk space with this web app 11 | - 📈 Detect javascript bloat over time with a chart 12 | - 🛡️ Get a badge/shield for your README 13 | - 📡 Fetch size from json API to integrate into any tool 14 | 15 | *...as seen on [AWS Developer Tools Blog](https://aws.amazon.com/blogs/developer/how-we-halved-the-publish-size-of-modular-aws-sdk-for-javascript-clients/) and [npm weekly](https://medium.com/npm-inc/87f3bd77529#1883) and [ponyfoo weekly](https://ponyfoo.com/weekly/111/how-css-works-integration-testing-angular-6-optimizing-react-and-the-future-of-javascript) and [habr](https://habr.com/company/zfort/blog/354060/) and [rwpod](https://www.rwpod.com/posts/2018/04/23/podcast-06-16.html) and [wolf report](https://michael-wolfenden.github.io/2018/04/20/april-20th-2018/) and [the changelog](https://changelog.com/news/find-the-cost-of-adding-a-new-dependency-to-your-project-gbj6) and all over twitter* 16 | 17 | ## What is the purpose? 18 | 19 | Package Phobia reports the size of an npm package *before* you install it, and records the size over time. 20 | 21 | This is useful for inspecting potential `dependencies` or `devDependencies` without using up precious disk space or waiting minutes for `npm install`. Ain't nobody got time for dat. 22 | 23 | Results are saved so the first person might wait a bit to view package size, but everyone else gets to see the results instantly! 24 | 25 | ## [Demo](https://packagephobia.com) 26 | 27 | A good use case might be comparing test runners, web frameworks, or even bundlers. Click one of the links below to see Package Phobia in action! 28 | 29 | - Test Harnesses: [tap](https://packagephobia.com/result?p=tap) vs [tape](https://packagephobia.com/result?p=tape) 30 | - Web Frameworks: [express](https://packagephobia.com/result?p=express) vs [micro](https://packagephobia.com/result?p=micro) 31 | - JavaScript Bundlers: [webpack](https://packagephobia.com/result?p=webpack) vs [rollup](https://packagephobia.com/result?p=rollup) 32 | - Task Runners: [grunt](https://packagephobia.com/result?p=grunt) vs [gulp](https://packagephobia.com/result?p=gulp) 33 | - HTTP Requests: [request](https://packagephobia.com/result?p=request) vs [node-fetch](https://packagephobia.com/result?p=node-fetch) 34 | - Glob Patterns: [glob](https://packagephobia.com/result?p=glob) vs [tiny-glob](https://packagephobia.com/result?p=tiny-glob) 35 | - Arguments: [yargs](https://packagephobia.com/result?p=yargs) vs [arg](https://packagephobia.com/result?p=arg) 36 | - Site Generators: [gatsby](https://packagephobia.com/result?p=gatsby) vs [next](https://packagephobia.com/result?p=next) 37 | - Type Checkers: [typescript](https://packagephobia.com/result?p=typescript) vs [flow-bin](https://packagephobia.com/result?p=flow-bin) 38 | - Linters: [eslint](https://packagephobia.com/result?p=eslint) vs [jslint](https://packagephobia.com/result?p=jslint) 39 | - Color Formatters: [chalk](https://packagephobia.com/result?p=chalk) vs [picocolors](https://packagephobia.com/result?p=picocolors) 40 | - Command Line Interfaces: [@angular/cli](https://packagephobia.com/result?p=%40angular%2Fcli) vs [@babel/cli](https://packagephobia.com/result?p=%40babel%2Fcli) 41 | - Desktop Frameworks: [nw](https://packagephobia.com/result?p=nw) vs [electron](https://packagephobia.com/result?p=electron) 42 | - Headless Browsers: [puppeteer](https://packagephobia.com/result?p=puppeteer) vs [chrome-aws-lambda](https://packagephobia.com/result?p=chrome-aws-lambda) 43 | - Package Managers: [npm](https://packagephobia.com/result?p=npm) vs [yarn](https://packagephobia.com/result?p=yarn) 44 | 45 | ## API 46 | 47 | If you would like to use the Package Phobia API in your project, please create a PR modifying [API Users](https://github.com/styfle/packagephobia/blob/main/API.md#users). 48 | 49 | See [API.md](https://github.com/styfle/packagephobia/blob/main/API.md) for more usage details. 50 | 51 | ## Prior Art 52 | 53 | Package Phobia is inspired by [Bundle Phobia](https://github.com/pastelsky/bundlephobia) and [Cost Of Modules](https://github.com/siddharthkp/cost-of-modules). 54 | 55 | ## How is this different? 56 | 57 | - [Package Phobia](https://packagephobia.com) **THIS TOOL** web app that reports the install size of a package over time. 58 | - [Bundle Phobia](https://bundlephobia.com) web app that reports the size after webpack bundles the package over time. 59 | - [Bundle.js](https://bundlejs.com) web app that reports the size after esbuild bundles the custom code snippet. 60 | - [Pkg-Size](https://pkg-size.dev) web app that reports the size after esbuild bundles one or more packages. 61 | - [Cost Of Modules](https://github.com/siddharthkp/cost-of-modules) cli that reports the size of your currently installed packages. 62 | - [Badge Size](https://github.com/ngryman/badge-size) badge service that reports the gzip size of a single file from a package as svg. 63 | - [Size Limit](https://github.com/ai/size-limit) cli that fails if the bundled (or non-bundled) size of your app is too large. 64 | - [Bundle Size](https://github.com/siddharthkp/bundlesize) cli that fails CI if a file's size is too large. 65 | - [Package Size](https://github.com/egoist/package-size) cli that compares the bundle size of multiple packages. 66 | - [npm Size](https://github.com/egoist/npm-size) cli that compares the npm install size of multiple packages. 67 | - [Require So Slow](https://github.com/ofrobots/require-so-slow) cli that traces the time of each `require` module in a node.js app. 68 | - [Why Bundled?](https://github.com/d4rkr00t/whybundled) cli that uses webpack stats to show your number of imports and package size. 69 | - [Do you even lift?](https://github.com/npm/do-you-even-lift) - cli that reports size after rollup bundles the package via npm team. 70 | - [Import Cost](https://github.com/wix/import-cost) extension (and cli) that displays package size inline in the editor. 71 | - [npm Download Size](https://github.com/arve0/npm-download-size) web app that reports the download size (network traffic) of a package. 72 | - [npm Download Size cli](https://github.com/arve0/npm-download-size-cli) cli that reports the download size (network traffic) of a package. 73 | - [Build Size](https://github.com/Daniel15/BuildSize) - GitHub App that comments on a PR with the size of your build artifacts 74 | - [Pkg Size](http://pkgsize.com) - web app that displays package size and file count over time (static data only) 75 | - [BundleWatch](https://github.com/bundlewatch/bundlewatch) - cli that checks if your bundle exceeds a specific size and also tracks increase 76 | - [PackWatch](https://github.com/mcataford/packwatch) - cli that checks if your package tarball exceeds a specific size and also tracks increase 77 | 78 | ## Why is the size different than size on disk? 79 | 80 | Did you install a package and compare the size on disk with the size reported on Package Phobia? 81 | 82 | This number will likely be different because Package Phobia doesn't know anything about your hard drive so it can't predict how blocks are allocated. 83 | 84 | Packages are known to contain many small `.js` files which can actually use up a lot of disk space, more than if there was one large, contiguous file. 85 | 86 | See [this question](https://superuser.com/q/66825/27229) for more details. 87 | 88 | ## What are the long term goals? 89 | 90 | Ideally, this information could be listed on npmjs.com, npms.io, or bundlephobia.com. 91 | 92 | Below are the relevant feature requests for each website. 93 | 94 | - [GitHub issue for bundlephobia.com](https://github.com/pastelsky/bundlephobia/issues/40) 95 | - [GitHub issue for npmjs.com](https://github.com/npm/www/issues/197) 96 | - [GitHub issue for npms.io](https://github.com/npms-io/npms-www/issues/219) 97 | - [GitHub issue for staticgen.com](https://github.com/netlify/staticgen/issues/359) 98 | - [GitHub issue for cost-of-modules](https://github.com/siddharthkp/cost-of-modules/issues/50) 99 | - [GitHub issue for npm-cli](https://github.com/npm/npm/issues/20427) 100 | - [GitHub issue for bundlesize](https://github.com/siddharthkp/bundlesize/issues/205) 101 | - [GitHub issue for npmgraph.an](https://github.com/anvaka/npmgraph.an/issues/25) 102 | 103 | Hopefully, this would lead to publishers taking notice of their bloated packages such as the following: 104 | 105 | - [micro is not micro](https://github.com/zeit/micro/issues/234) 106 | - [ava is not minimal](https://github.com/avajs/ava/issues/1622) 107 | - [typescript has doubled in size since v2.0.0](https://github.com/Microsoft/TypeScript/issues/23339) 108 | - [bundlesize is 10x larger after npm install since v0.14.0](https://github.com/siddharthkp/bundlesize/issues/213) 109 | - [jquery@3.3.0 accidentally adds 300 dependencies](https://twitter.com/styfle/status/985955164573065217) 110 | - [socket.io is 6x smaller](https://twitter.com/styfle/status/986224072882380802) 111 | - [serve@7.0.0 is 3x smaller](https://twitter.com/styfle/status/1001901854417178624) 112 | - [webpack-cli@3.0.0 is 4x smaller](https://twitter.com/styfle/status/1006605750981021697) 113 | - [v8n@1.1.1 is 11x smaller](https://twitter.com/styfle/status/1022433043498364931) 114 | - [now@13.0.0-canary.6 is 2x smaller](https://twitter.com/styfle/status/1064512498706116617) 115 | - [typescript@5.0.0-beta is 41% smaller](https://twitter.com/styfle/status/1619058702753071105) 116 | 117 | ## npm dependencies in the media 118 | 119 | I'm not the first one to notice npm packages are snowballing into bloated dependencies of dependencies. 120 | 121 | Below are some other users who comically point out this JS bloat. 122 | 123 | | [thomasfuchs](https://twitter.com/thomasfuchs/status/977541462199029760) 124 | | [ben_a_adams](https://twitter.com/ben_a_adams/status/979358943561609216) 125 | | [devrant](https://devrant.com/rants/760537/heaviest-objects-in-the-universe) 126 | | [turnoff.us](https://turnoff.us/geek/npm-install/) 127 | | [styfle](https://twitter.com/styfle/status/968180698149539841) 128 | | [davej](https://github.com/npm/npm/issues/10361) 129 | | [FredyC](https://github.com/yarnpkg/yarn/issues/2088) 130 | | [tomitrescak](https://github.com/npm/npm/issues/12515) 131 | | [maybekatz](https://twitter.com/maybekatz/status/988893800054456320) 132 | | [hichaelmart](https://twitter.com/hichaelmart/status/988882864270962688) 133 | | [brad_frost](https://twitter.com/brad_frost/status/996014341592961025) 134 | | [Bryan_Chapel](https://twitter.com/Bryan_Chapel/status/1002680482159648769) 135 | | [getabitlit](https://twitter.com/getabitlit/status/1013524294394003456) 136 | | [iamdevloper](https://twitter.com/iamdevloper/status/1013767672369242112) 137 | | [rickhanlonii](https://twitter.com/rickhanlonii/status/1062319416107560961) 138 | | 139 | 140 | ## Contributing 141 | 142 | See [CONTRIBUTING.md](https://github.com/styfle/packagephobia/blob/main/CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](https://github.com/styfle/packagephobia/blob/main/CODE_OF_CONDUCT.md) before you start writing any code 143 | 144 | ## Sponsors 145 | 146 | - Web hosting sponsored by [vercel.com](https://vercel.com/?utm_source=packagephobia) 147 | - Database sponsored by [upstash.com](https://upstash.com/?ref=packagephobia) 148 | 149 | ## Author 150 | 151 | Developed by [styfle](https://styfle.dev) 152 | -------------------------------------------------------------------------------- /api/index.ts: -------------------------------------------------------------------------------- 1 | import { handler } from '../src/server'; 2 | 3 | export default handler; 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "packagephobia", 3 | "private": true, 4 | "engines": { 5 | "node": "22.x" 6 | }, 7 | "scripts": { 8 | "prettier": "prettier \"./**/*.ts\" \"./**/*.tsx\" --write", 9 | "git-pre-commit": "npm run prettier && git add -A", 10 | "lint": "npm run prettier && git diff --exit-code", 11 | "test": "tsc && rm -f test/hardlink/link && ln test/hardlink/orig.txt test/hardlink/link && node --test" 12 | }, 13 | "repository": "styfle/packagephobia", 14 | "author": "styfle", 15 | "license": "MIT", 16 | "dependencies": { 17 | "badgen": "^3.2.3", 18 | "ioredis": "^5.4.1", 19 | "lru-cache": "^10.2.0", 20 | "react": "^18.2.0", 21 | "react-dom": "^18.2.0", 22 | "semver": "^7.6.0" 23 | }, 24 | "devDependencies": { 25 | "@types/node": "^20.12.7", 26 | "@types/react": "^18.2.79", 27 | "@types/react-dom": "^18.2.25", 28 | "@types/semver": "^7.5.8", 29 | "npm": "^10.4.0", 30 | "prettier": "^3.2.5", 31 | "typescript": "^5.4.5" 32 | }, 33 | "packageManager": "npm@10.9.0" 34 | } 35 | -------------------------------------------------------------------------------- /public/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styfle/packagephobia/fc6e2ba52abfac1a47f639629123c04c9cd5d5a4/public/android-chrome-192x192.png -------------------------------------------------------------------------------- /public/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styfle/packagephobia/fc6e2ba52abfac1a47f639629123c04c9cd5d5a4/public/android-chrome-512x512.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styfle/packagephobia/fc6e2ba52abfac1a47f639629123c04c9cd5d5a4/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styfle/packagephobia/fc6e2ba52abfac1a47f639629123c04c9cd5d5a4/public/favicon-16x16.png -------------------------------------------------------------------------------- /public/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styfle/packagephobia/fc6e2ba52abfac1a47f639629123c04c9cd5d5a4/public/favicon-32x32.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styfle/packagephobia/fc6e2ba52abfac1a47f639629123c04c9cd5d5a4/public/favicon.ico -------------------------------------------------------------------------------- /public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/styfle/packagephobia/fc6e2ba52abfac1a47f639629123c04c9cd5d5a4/public/logo.png -------------------------------------------------------------------------------- /public/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: AhrefsBot 2 | Disallow: / 3 | User-agent: Barkrowler 4 | Disallow: / 5 | User-agent: Bytespider 6 | Disallow: / 7 | User-agent: DotBot 8 | Disallow: / 9 | User-agent: GPTBot 10 | Disallow: / 11 | User-agent: marketgoo 12 | Disallow: / 13 | User-agent: MJ12bot 14 | Disallow: / 15 | User-agent: Moz dotbot 16 | Disallow: / 17 | User-agent: PetalBot 18 | Disallow: / 19 | User-agent: prerender 20 | Disallow: / 21 | User-agent: SEMrush 22 | Disallow: / 23 | -------------------------------------------------------------------------------- /public/safari-pinned-tab.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /public/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Package Phobia", 3 | "short_name": "PP", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/android-chrome-512x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png" 14 | } 15 | ], 16 | "start_url": "/?utm_source=a2hs", 17 | "theme_color": "#333333", 18 | "background_color": "#333333", 19 | "display": "standalone" 20 | } 21 | -------------------------------------------------------------------------------- /src/browser.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { hydrate } from 'react-dom'; 3 | import Index from './pages/index'; 4 | import { containerId } from './util/constants'; 5 | 6 | const app = ; 7 | const el = document.getElementById(containerId); 8 | hydrate(app, el); 9 | -------------------------------------------------------------------------------- /src/components/BarGraph.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { getReadableFileSize } from '../util/npm-parser'; 3 | import type { PkgSize } from '../types'; 4 | const stylesheet = ` 5 | .bar-graph{ 6 | height:55vh; 7 | padding-bottom:10vh; 8 | display:flex; 9 | align-items:baseline; 10 | margin:0; 11 | justify-content:center; 12 | max-width: 80vw; 13 | overflow-x: auto; 14 | } 15 | .bar-graph__bar-group{ 16 | height:100%; 17 | position:relative; 18 | width:1.6vw; 19 | min-width:15px; 20 | margin:0 5px; 21 | } 22 | .bar-graph__bar,.bar-graph__bar2{ 23 | width:100%; 24 | position:absolute; 25 | left:0; 26 | bottom:0; 27 | transition:background 0.2s; 28 | animation:grow 0.4s cubic-bezier(0.305,0.42,0.205,1.2); 29 | transform-origin:100% 100%; 30 | cursor:pointer; 31 | } 32 | .color1 { 33 | background: #32DE85; 34 | } 35 | .color2 { 36 | background: #26A664; 37 | } 38 | .bar-graph__bar-group--disabled .bar-graph__bar{ 39 | background: var(--muted); 40 | } 41 | .bar-graph__bar2{ 42 | z-index:1; 43 | pointer-events:none; 44 | } 45 | .bar-graph__bar:hover, .bar-graph__bar2:hover{ 46 | box-shadow: inset 0 0 10px 10px rgba(0, 0, 0, 0.1); 47 | } 48 | .bar-graph__bar-version{ 49 | font-size:0.8rem; 50 | position:absolute; 51 | bottom:-50px; 52 | font-weight:400; 53 | display:block; 54 | transform:rotate(-90deg); 55 | transform-origin:50% 50%; 56 | width:100%; 57 | text-align:right; 58 | font-variant-numeric:tabular-nums; 59 | color: var(--muted-foreground); 60 | transition:opacity 0.2s,color 0.2s; 61 | animation:fade-in 0.5s 0.1s forwards cubic-bezier(0.305,0.42,0.205,1.2); 62 | font-family:"Source Code Pro","SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace; 63 | letter-spacing:-1px; 64 | } 65 | @media screen and (max-width:48em){ 66 | .bar-graph__bar-version{ 67 | font-size:0.75rem; 68 | } 69 | } 70 | @media screen and (max-width:40em){ 71 | .bar-graph__bar-version{ 72 | font-size:0.7rem; 73 | } 74 | } 75 | .bar-graph-container:hover .bar-graph__bar-version{ 76 | opacity:1; 77 | color: var(--foreground); 78 | } 79 | .bar-graph__bar-group:hover .bar-graph__bar-version{ 80 | color: var(--foreground); 81 | } 82 | .bar-graph__legend{ 83 | font-size:0.8rem; 84 | padding-top:15px; 85 | display:flex; 86 | text-transform:uppercase; 87 | justify-content:center; 88 | color:#6d747d; 89 | } 90 | @media screen and (max-width:48em){ 91 | .bar-graph__legend{ 92 | font-size:0.75rem; 93 | } 94 | } 95 | @media screen and (max-width:40em){ 96 | .bar-graph__legend{ 97 | font-size:0.7rem; 98 | } 99 | } 100 | .bar-graph__legend__colorbox{ 101 | width:15px; 102 | height:15px; 103 | margin-right:10px; 104 | } 105 | .bar-graph__legend__bar1,.bar-graph__legend__bar2{ 106 | display:flex; 107 | align-items:center; 108 | } 109 | .bar-graph__legend__bar1{ 110 | margin-right:40px; 111 | } 112 | @keyframes grow{ 113 | from{ 114 | transform:scaleY(0); 115 | } 116 | to{ 117 | transform:scaleY(1); 118 | } 119 | } 120 | @keyframes fade-in{ 121 | from{ 122 | opacity:0; 123 | } 124 | to{ 125 | opacity:0.7; 126 | } 127 | }`; 128 | 129 | interface Props { 130 | readings: PkgSize[]; 131 | getHref: (r: PkgSize) => string; 132 | } 133 | 134 | export default class BarGraph extends React.PureComponent { 135 | render() { 136 | const { readings, getHref } = this.props; 137 | 138 | const gzipValues = readings 139 | .filter(reading => !reading.disabled) 140 | .map(reading => reading.publishSize); 141 | 142 | const sizeValues = readings 143 | .filter(reading => !reading.disabled) 144 | .map(reading => reading.installSize); 145 | 146 | const maxValue = Math.max(...[...gzipValues, ...sizeValues]); 147 | const scale = 100 / maxValue; 148 | 149 | return ( 150 |
151 | `; 11 | -------------------------------------------------------------------------------- /src/components/PageContainer.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const style: React.CSSProperties = { 4 | display: 'flex', 5 | flexDirection: 'column', 6 | justifyContent: 'center', 7 | alignItems: 'center', 8 | minHeight: '80vh', 9 | padding: '1rem', 10 | }; 11 | 12 | interface Props { 13 | children: React.ReactNode; 14 | } 15 | 16 | export default function PageContainer(props: Props) { 17 | return
{props.children}
; 18 | } 19 | -------------------------------------------------------------------------------- /src/components/SearchBar.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { pages } from '../util/constants'; 3 | 4 | const form: React.CSSProperties = { 5 | display: 'flex', 6 | alignItems: 'center', 7 | justifyContent: 'center', 8 | maxWidth: 'calc(100vw - 2rem)', 9 | }; 10 | 11 | const height = '4rem'; 12 | const radius = '3px'; 13 | 14 | const input: React.CSSProperties = { 15 | color: 'var(--muted-foreground)', 16 | background: 'var(--search-input)', 17 | fontSize: '2.4rem', 18 | textAlign: 'center', 19 | fontFamily: 20 | '"Source Code Pro","SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace', 21 | fontWeight: 300, 22 | maxWidth: `calc(100% - ${height})`, 23 | border: '1px solid var(--border)', 24 | borderRadius: `${radius} 0 0 ${radius}`, 25 | height: height, 26 | }; 27 | 28 | const button: React.CSSProperties = { 29 | minWidth: height, 30 | width: height, 31 | height: height, 32 | padding: '0.7rem', 33 | background: 'var(--search-input)', 34 | border: '1px solid var(--border)', 35 | fill: 'var(--muted-foreground)', 36 | borderLeft: 'none', 37 | borderRadius: `0 ${radius} ${radius} 0`, 38 | cursor: 'pointer', 39 | }; 40 | 41 | export default (props: { autoFocus: boolean; defaultValue?: string }) => ( 42 |
43 | 58 | 63 |
64 | ); 65 | -------------------------------------------------------------------------------- /src/components/Sponsors.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const SPONSORS = [ 4 | 14 | 21 | 25 | 26 | , 27 | 31 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 52 | 56 | 61 | 65 | 70 | 71 | 76 | 80 | 81 | , 82 | ]; 83 | 84 | export default function Sponsors() { 85 | return ( 86 |
87 | {SPONSORS.map((sponsor, index) => ( 88 |
97 | {sponsor} 98 |
99 | ))} 100 |
101 | ); 102 | } 103 | -------------------------------------------------------------------------------- /src/components/Stats.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import type { SizeWithUnit } from '../types'; 3 | 4 | interface Props { 5 | publish: SizeWithUnit; 6 | install: SizeWithUnit; 7 | } 8 | 9 | export default function Stats(props: Props) { 10 | return ( 11 |
12 | 13 | 14 |
15 | ); 16 | } 17 | 18 | type StatProp = { 19 | size: string; 20 | unit: string; 21 | label: string; 22 | scale?: number; 23 | color?: string; 24 | textAlign?: 'center' | 'right'; 25 | }; 26 | 27 | export function Stat(props: StatProp) { 28 | const { 29 | size, 30 | unit, 31 | label, 32 | scale = 1, 33 | color = 'var(--foreground)', 34 | textAlign = 'center', 35 | } = props; 36 | 37 | const styleValue: React.CSSProperties = { 38 | fontSize: `${3 * scale}rem`, 39 | fontWeight: 'bold', 40 | color, 41 | }; 42 | 43 | const styleUnit: React.CSSProperties = { 44 | fontSize: `${2.4 * scale}rem`, 45 | color: '#666E78', 46 | fontWeight: 'bold', 47 | marginLeft: '4px', 48 | }; 49 | 50 | const styleLabel: React.CSSProperties = { 51 | fontSize: `${1 * scale}rem`, 52 | color: '#666E78', 53 | textTransform: 'uppercase', 54 | letterSpacing: '2px', 55 | textAlign, 56 | marginBottom: '25px', 57 | }; 58 | 59 | return ( 60 |
61 |
62 | {size} 63 | {unit} 64 |
65 |
{label}
66 |
67 | ); 68 | } 69 | -------------------------------------------------------------------------------- /src/page-props/common.ts: -------------------------------------------------------------------------------- 1 | import { findOne } from '../util/backend/db'; 2 | import { insert as insertRedis } from '../util/backend/db-redis'; 3 | import { getAllDistTags } from '../util/npm-api'; 4 | import { calculatePackageSize } from '../util/backend/npm-stats'; 5 | import { versionUnknown } from '../util/constants'; 6 | import type { NpmManifest, PkgSize } from '../types'; 7 | 8 | export async function getPkgDetails( 9 | manifest: NpmManifest | null, 10 | name: string, 11 | version: string | null, 12 | force: boolean, 13 | tmpDir: string, 14 | ) { 15 | let cacheResult = true; 16 | let isLatest = false; 17 | 18 | if (!manifest) { 19 | console.error(`Package "${name}" does not exist in npm`); 20 | return packageNotFound(name); 21 | } 22 | 23 | const tagToVersion = getAllDistTags(manifest); 24 | if (!version) { 25 | version = tagToVersion.latest; 26 | isLatest = true; 27 | cacheResult = false; 28 | } else if (typeof tagToVersion[version] !== 'undefined') { 29 | version = tagToVersion[version] || ''; 30 | cacheResult = false; 31 | } 32 | 33 | const allVersions = manifest.versions; 34 | if (!allVersions.includes(version)) { 35 | console.error(`Version ${name}@${version} does not exist in npm`); 36 | return packageNotFound(name); 37 | } 38 | 39 | let pkgSize = await findOne(name, version); 40 | if (!pkgSize || force) { 41 | console.log(`Cache miss - running "npm i ${name}@${version}" in ${tmpDir}...`); 42 | const start = new Date(); 43 | pkgSize = await calculatePackageSize(name, version, tmpDir); 44 | const end = new Date(); 45 | const sec = (end.getTime() - start.getTime()) / 1000; 46 | console.log(`Calculated size of ${name}@${version} in ${sec}s`); 47 | await insertRedis(pkgSize); 48 | } 49 | 50 | const result = { 51 | pkgSize, 52 | cacheResult, 53 | isLatest, 54 | allVersions, 55 | }; 56 | return result; 57 | } 58 | 59 | function packageNotFound(name: string) { 60 | const pkgSize: PkgSize = { 61 | name, 62 | version: versionUnknown, 63 | publishSize: 0, 64 | installSize: 0, 65 | publishFiles: 0, 66 | installFiles: 0, 67 | disabled: true, 68 | }; 69 | const result = { 70 | pkgSize, 71 | cacheResult: false, 72 | isLatest: false, 73 | allVersions: [], 74 | manifest: null, 75 | }; 76 | return result; 77 | } 78 | -------------------------------------------------------------------------------- /src/page-props/compare.ts: -------------------------------------------------------------------------------- 1 | import { fetchManifest } from '../util/npm-api'; 2 | import { getPkgDetails } from './common'; 3 | import type { CompareProps, PackageVersion } from '../types'; 4 | 5 | export async function getCompareProps( 6 | inputStr: string, 7 | pkgVersions: PackageVersion[], 8 | force: boolean, 9 | tmpDir: string, 10 | ): Promise { 11 | const promises = pkgVersions.map(async ({ name, version }) => { 12 | const manifest = await fetchManifest(name); 13 | return getPkgDetails(manifest, name, version, force, tmpDir); 14 | }); 15 | const results = await Promise.all(promises); 16 | 17 | return { inputStr, results }; 18 | } 19 | -------------------------------------------------------------------------------- /src/page-props/results.ts: -------------------------------------------------------------------------------- 1 | import { isFullRelease } from '../util/npm-parser'; 2 | import { findAll } from '../util/backend/db'; 3 | import { getAllDistTags, getVersionsForChart } from '../util/npm-api'; 4 | import { getPkgDetails } from './common'; 5 | import { NotFoundError } from '../util/not-found-error'; 6 | import type { NpmManifest, PackageVersion, ResultProps } from '../types'; 7 | 8 | export async function getResultProps( 9 | inputStr: string, 10 | pkgVersions: PackageVersion[], 11 | manifest: NpmManifest | null, 12 | force: boolean, 13 | tmpDir: string, 14 | ): Promise { 15 | const parsed = pkgVersions[0]; 16 | if (!parsed) { 17 | throw new Error('Expected one or more versions'); 18 | } 19 | if (!manifest) { 20 | throw new NotFoundError({ resource: parsed.name }); 21 | } 22 | const { pkgSize, allVersions, cacheResult, isLatest } = await getPkgDetails( 23 | manifest, 24 | parsed.name, 25 | parsed.version, 26 | force, 27 | tmpDir, 28 | ); 29 | 30 | const { name, version } = pkgSize; 31 | const tagToVersion = getAllDistTags(manifest); 32 | 33 | const filteredVersions = 34 | pkgVersions.length > 1 35 | ? pkgVersions.map(p => tagToVersion[p.version || ''] || p.version).filter(notEmpty) 36 | : isFullRelease(version) 37 | ? allVersions.filter(isFullRelease) 38 | : allVersions; 39 | 40 | const chartVersions = getVersionsForChart(filteredVersions, version, 7); 41 | 42 | const cachedVersions = await findAll(name); 43 | 44 | const readings = chartVersions.map(v => { 45 | return ( 46 | cachedVersions[v] || { 47 | name: name, 48 | version: v, 49 | publishSize: 0, 50 | installSize: 0, 51 | publishFiles: 0, 52 | installFiles: 0, 53 | disabled: true, 54 | } 55 | ); 56 | }); 57 | 58 | return { 59 | pkgSize, 60 | readings, 61 | cacheResult, 62 | isLatest, 63 | inputStr, 64 | }; 65 | } 66 | 67 | function notEmpty(value: T | null | undefined): value is T { 68 | return value !== null && value !== undefined; 69 | } 70 | -------------------------------------------------------------------------------- /src/pages/404.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Image from '../components/Image'; 4 | import Footer from '../components/Footer'; 5 | import PageContainer from '../components/PageContainer'; 6 | 7 | import { pages } from '../util/constants'; 8 | 9 | export default (props: { resource: string }) => ( 10 | <> 11 | 12 |
13 |

404 Not Found

14 | 15 |

Oops, "{props.resource}" does not exist.

16 |

17 | Go Home You 18 |

19 |
20 | 21 | 22 |
23 | 24 |