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

amend-package

v1.0.1

Published

Modify npm installed packages.

Downloads

20

Readme

amend-package

[!CAUTION] Modify package is not recommended. Do not use this way unless there is no other solution and you known there is no risk in your scenario.

Modify npm installed packages.

  • Modify package.json.
  • Add sub package.json.

amend-package has been tested in npm v8+, pnpm v8, yarn v1.x, node v16+.

Usage

  1. Install, e.g.,
npm install -D amend-package
  1. Write your modification code in your amend-package.config.js (or name it yourself)
  • Note: there is some built-in xxx.config.js, list it using --list-builtin-config and use it directly using --builtin-config xxx.config.js.
  1. Run the script as follows. In most scenarios you should better put it in postinstall of the package.json of you project, then it can be called automatically after npm install. e.g.:
{
  "scripts": {
    "postinstall": "npx amend-package --config amend-package.config.cjs"
  }
}

cli usage examples

# Print help
npx amend-package --help

# Modify all packages.
npx amend-package --config amend-package.config.cjs

# Modify all packages, but try run without real modification.
npx amend-package --config amend-package.config.cjs --dry-run

# Modify the specified package.
npx amend-package --config amend-package.config.cjs --package some_pkg_name
# Revert the modifications to all packages.
npx amend-package --config amend-package.config.cjs --revert

# Revert the modifications to the specified package.
npx amend-package --config amend-package.config.cjs --revert --package some_pkg_name

cli options

  • --help Print help.

  • --config Specify the config file path. At present only CommonJS is supported in the config file. The config file is loaded via const config = require(require('node:path').resolve(cmdInputConfigPath)). See the example config files in "amend-package/builtin-config/*.config.cjs". Either --builtin-config or --config must be specified.

  • --builtin-config Specify the config file name. e.g. --builtin-config fix-vue-echarts-esm.config.cjs Either --builtin-config or --config must be specified.

  • --list-builtin-config List built-in config files.

  • --dry-run Just log what will be changed but do not change anything.

  • --package <package_name> Specify the package (npm package name) to modify. If not specified, modify all packages. e.g. --package some_pkg_name

  • --revert Revert the modifications.

  • --builtin-case List built-in cases.

  • --case <case_name> Specify a case to run. If not specified, run all cases.

Example of amend-package.config.cjs

module.exports = {
  amenderMap: {

    'some_package_1': ({
      setPackageJSONAttr,
      ensureSubPackageJSON,
      getPackageJSONAttrClone,
      getPackageVersion
    }) => {
      const currentVersion = getPackageVersion();
      const expectedVersion = '5.1.2';
      if (currentVersion !== expectedVersion) {
        throw new Error(
          'Please check the patch logic when upgrade "some_package_1".'
          + ' currentVersion: ' + currentVersion
          + ' expectedVersion: ' + expectedVersion
        );
      }
      setPackageJSONAttr('type', 'module');
      setPackageJSONAttr('exports', {
        ".": {
            "types": "./index.d.ts",
            "require": "./dist/zrender.js",
            "import": "./index.js"
        },
        "./*": "./*",
      });
      ensureSubPackageJSON(['dist'], ({setPackageJSONAttr}) => setPackageJSONAttr('type', 'commonjs'));
      ensureSubPackageJSON(['build'], ({setPackageJSONAttr}) => setPackageJSONAttr('type', 'commonjs'));
    },

    'some_package_2': ({
      setPackageJSONAttr,
      ensureSubPackageJSON,
      getPackageJSONAttrClone,
      getPackageVersion
    }) => {
      // ...
    },
    // ...

  },
};