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 🙏

© 2024 – Pkg Stats / Ryan Hefner

clean-package

v2.2.0

Published

Removes and replaces configuration keys in 'package.json' before creating an NPM package.

Downloads

90,932

Readme

Clean Package

This clean-package tool is used for removing development configuration from 'package.json' before publishing the package to NPM.

Release Version License

Install

npm install clean-package --save-dev

Integrated Usage

The clean-package tool works directly on the 'package.json' file, to avoid breaking the NPM lifecycle. This allows you to add a script to the 'package.json' to clean the file during packing.

{
  "name": "my-package",
  "version": "1.0.0",
  "scripts": {
    "prepack": "clean-package",
    "postpack": "clean-package restore"
  }
}

When the "prepack" script executes, a backup of the original package.json will be created. Ensure this file doesn't make it into your release package.

One way to accomplish this is to add the following to your .npmignore file:

*.backup

See CLI Usage for independent usage instructions.

JSON Configuration Files

Options can be configured in clean-package.config.json at the root of your project (where the package.json is).

{
  "indent": 2,
  "remove": [
    "eslintConfig",
    "jest"
  ]
}

Alternatively, you can choose to specify your configuration from within package.json using the clean-package key like so:

{
  "name": "my-package",
  "version": "1.0.0",
  "clean-package": {
    "indent": 2,
    "remove": [
      "eslintConfig",
      "jest"
    ]
  },

  // Or, a file path to a configuration.
  "clean-package": "./build/clean-package.config.js"
}

JavaScript Configuration File

You can also create the configuration using JavaScript in the clean-package.config.?(c|m)js at the root of your project:

module.exports = {
  indent: '\t',
  replace: {
    'config.port': '8080'
  }
};

Options

Command Line Usage

clean-package [[<source-path>] <backup-path>] [<option>...]

where <option> is one of:

  -c,  --config <path>                  Specify the path to a configuration file.

  -e,  --extends <name>...              Specify the name to a shareable configuration. (e.g. 'clean-package/common')

  -i,  --indent <value>                 Specify the indentation, overriding configuration from file.

  -rm, --remove <key>...                Specify the keys to remove, overriding configuration from file.

       --remove-add <key>...            Same as --remove without overriding configuration from file.

  -r,  --replace <key>=<value>...       Specify the keys to replace, overriding configuration from file.

       --replace-add <key>=<value>...   Same as --replace without overriding configuration from file.

       --print-config                   Print the combined configuration without executing command.

  -v,  --version                        Print the version number
clean-package restore [[<source-path>] <backup-path>] [<option>...]

alias: r

where <option> is one of:

  -c,  --config <path>                  Specify the path to a configuration file.

  -e,  --extends <name>...              Specify the name to a shareable configuration. (e.g. 'clean-package/common')

       --print-config                   Print the combined configuration without executing command.

Usage in Code

Should you desire, it is also possible to interface this package through code. Simply import the package like any other.

import { load, clean, restore, version } from 'clean-package';

Troubleshooting

How do I remove package scripts and use clean-package restore?

If you're integrating clean-package into the NPM lifecycle, removing all the package.json scripts with clean-package will also remove them from the current execution. This is just how NPM works.

For example, this configuration will remove the postpack script before it is ever requested by npm pack or npm publish, thereby effectively removing the event from the executing lifecycle.

{
  "scripts": {
    "prepack": "clean-package",
    "postpack": "clean-package restore"
  },
  "clean-package": {
    "remove": [
      "clean-package",
      "scripts"
    ]
  }
}

There are multiple ways to work around this (more than are offered here). One solution might be to manually run the command with npx clean-package restore. Another might be to define a custom script that would call pack and clean-package in sequence:

{
  "scripts": {
    "prepack": "clean-package",
    "new:pack": "npm pack && clean-package restore",
    "new:publish": "npm publish && clean-package restore"
  }
}