npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

clean-pkg-json

v2.1.0

Published

Clean package.json before publish by removing unnecessary properties

Readme

clean-pkg-json

Only publish necessary package.json properties.

clean-pkg-json removes development-only properties, such as devDependencies, most scripts, and tool configs, from package.json right before you pack or publish.

Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️

Install

npm install -D clean-pkg-json

Setup

Run it in the prepack script, after your build:

// package.json
{
    "scripts": {
        "prepack": "npm run build && clean-pkg-json",
    },
}

prepack runs on npm pack and npm publish (and the pnpm and Yarn equivalents), so the cleaned package.json is what gets published.

Good to know

  • Build before cleaning. Run clean-pkg-json after the build, in the same prepack script.
  • package.json stays cleaned. After a local npm pack, restore it with git checkout package.json.
  • Don't run it as a separate step before other tools. Use prepack. If you must, keep what those tools need, for example clean-pkg-json --keep packageManager.
  • Don't restore package.json in postpack. It publishes the uncleaned metadata.
  • Preview the cleaned package.json with clean-pkg-json --dry. It prints the result and doesn't write the file.
  • Don't trust the numbers from npm pack --dry-run. clean-pkg-json doesn't change package.json during an npm dry run, so npm's file sizes, shasum, and integrity describe the original file. clean-pkg-json prints a note when this happens. For the real values, pack without --dry-run, then run git checkout package.json.
  • With pnpm 11+ and Yarn 4, dry runs clean package.json too. Restore it afterward with git checkout package.json.
  • Build before cleaning: exports and imports entries are removed when their files aren't in the package. Files that aren't built yet look missing, so their entries get removed. A warning is printed when this happens.
  • package.json stays cleaned: clean-pkg-json rewrites package.json in place and doesn't keep a copy.
  • Separate steps: every command after the cleanup sees the cleaned file. For example, without packageManager, Corepack falls back to its default version, so clean-pkg-json && changeset publish in a Yarn 4 project runs changesets with Yarn 1. In prepack, the publish tool has already started before the cleanup runs.
  • postpack: npm reads package.json again after postpack to build the registry metadata. A restore there sends the original file, including all scripts, to the registry while the tarball has the cleaned one.
  • npm dry runs: npm pack --dry-run and npm publish --dry-run still run prepack and build the tarball in memory. clean-pkg-json detects the dry run (npm_config_dry_run, which pnpm 10 also sets), prints the cleaned result, and leaves package.json unchanged, so npm packs the original file. npm packs only the package.json on disk, so a dry run can't pack the cleaned file without changing it. Restoring the file afterward would need a separate postpack step, which doesn't run if the pack fails or is interrupted.
  • pnpm 11+ and Yarn 4: they don't tell lifecycle scripts about a dry run, so clean-pkg-json can't detect it and writes the file as in a real pack.

Example

Given this package.json:

{
    "name": "my-package",
    "version": "1.0.0",
    "description": "A useful package",
    "type": "module",
    "main": "dist/index.js",
    "types": "dist/index.d.ts",
    "files": [
        "dist"
    ],
    "scripts": {
        "build": "pkgroll",
        "lint": "eslint .",
        "test": "vitest",
        "prepack": "npm run build && clean-pkg-json"
    },
    "dependencies": {
        "lodash": "^4.0.0"
    },
    "devDependencies": {
        "pkgroll": "^2.0.0",
        "vitest": "^1.0.0",
        "clean-pkg-json": "^2.0.0"
    },
    "eslintConfig": {
        "extends": [
            "@pvtnbr"
        ]
    },
    "lint-staged": {
        "*.ts": "eslint --fix"
    },
    "simple-git-hooks": {
        "pre-commit": "npx lint-staged"
    }
}

The published package.json is:

{
    "name": "my-package",
    "version": "1.0.0",
    "description": "A useful package",
    "type": "module",
    "main": "dist/index.js",
    "types": "dist/index.d.ts",
    "files": [
        "dist"
    ],
    "dependencies": {
        "lodash": "^4.0.0"
    }
}

Flags

| Flag | Description | | - | - | | -k, --keep <property name> | Keep more properties, e.g. -k eslintConfig or -k scripts.prepare. Accepts multiple flags or a comma-separated list. | | -r, --remove <property name> | Remove properties that are kept by default, e.g. -r scripts.postinstall. Accepts multiple flags or a comma-separated list. | | -d, --dry | Print the cleaned package.json without writing it. | | -v, --verbose | Log what is kept and removed. | | --published-only=false | Don't prune exports and imports. | | -h, --help | Show help. | | --version | Show version. |

How it works

  • Properties: only properties that consumers use are kept. Everything else is removed.
  • Scripts: only install hooks (preinstall, install, postinstall) are kept, because they run when someone installs your package. If no scripts are left, scripts is removed.
  • exports and imports: entries that point to files outside the published package are removed, so consumers can't resolve to files that don't exist. In conditional entries, only the unpublished branches are removed.

Default preserved properties

npm

  • name
  • version
  • private
  • publishConfig
  • scripts.preinstall
  • scripts.install
  • scripts.postinstall
  • gypfile
  • binary (prebuild-install, node-pre-gyp)
  • files
  • bin
  • browser
  • main
  • directories
  • man
  • dependencies
  • peerDependencies
  • peerDependenciesMeta
  • bundleDependencies
  • bundledDependencies
  • optionalDependencies
  • engines
  • os
  • cpu
  • libc
  • description
  • keywords
  • author
  • maintainers
  • contributors
  • license
  • homepage
  • repository
  • bugs
  • funding

CDNs

Node.js

  • type
  • exports
  • imports

VSCode Extension Manifest

  • sponsor
  • publisher
  • displayName
  • categories
  • galleryBanner
  • preview
  • contributes
  • activationEvents
  • badges
  • markdown
  • qna
  • extensionPack
  • extensionDependencies
  • extensionKind
  • icon

Angular Package Format

  • fesm2020
  • fesm2015
  • esm2020
  • es2020

TypeScript

  • types
  • typings
  • typesVersions
  • typescript (content mapper manifest, TypeScript 7.1+)

Bundlers (Webpack, Rollup, esbuild)

Agent Skills

This package ships with agent skills for AI coding assistants.