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

reinstall-node-modules

v2.0.0

Published

(re)install node modules only if they have changed

Downloads

241

Readme

(re)install-node-modules

Build Status codecov

Have you ever been in the situation you were facing an issue that was simply caused by not having (re)installed node modules after someone had changed it?

Are you tired of telling people to (re)install their node modules when they ask you why something is not working?

This lightweight package might be the perfect solution for you! It (re)installs node modules whenever the target package file has changed!

Installation

Install the package with your favorite manager

npm install reinstall-node-modules --save-dev
yarn add reinstall-node-modules --dev

Usage

You may use it in the scripts field of your package.json

{
  "scripts": {
    "reinstall": "reinstall-node-modules"
  }
}

However it's highly recommended to use a git hook to run it! There's no other way to make sure everybody has the correct node modules!

Hook

If you wanna use a hook for this it's recommended to use post-merge. An easy way to use git hooks is the husky package what would require to add the following to your package.json

{
  "husky": {
    "hooks": {
      "post-merge": "reinstall-node-modules"
    }
  }
}

Import

It's also possible import the package and use it programmatically though most of the time an npm-script or hook makes more sense.

const installer = require('reinstall-node-modules');
const options = {};

installer(options);

Options

| Option | Type | Default | | ---------- | ------- | -------------- | | manager | string | 'npm' | | file | string | 'package.json' | | install | boolean | true | | updateHash | boolean | true | | notify | boolean | false |

manager

The manager option defines the package manager that gets used to (re)install the node modules. By default it's npm but you can use whatever you like (as long as it supports the install command).

If you wanna e.g. use yarn instead of npm you only need to pass it as option

reinstall-node-modules --manager yarn

file

The file option defines the path to the target package file that gets used to determine whether it's necessary to (re)install node modules or not (based on its content). You can use either a relative or an absolute path here. By default it's package.json assuming there's such a file in your current working directory.

If you wanna e.g. use package-lock.json instead of package.json you only need to pass it as option

reinstall-node-modules --file package-lock.json

install

The install option defines if an actual (re)install is executed. So to disable it you only need to set it false

reinstall-node-modules --install false

updateHash

The updateHash option defines if a *.hash file is written to disk. Be careful with disabling this because your target package file will be considered as changed then every time.

reinstall-node-modules --update false

notify

The notify option defines if a notification gets sent in case the target package file has changed. This is in particular useful if you have disabled install to gently inform your colleagues they should (re)install their node modules.

reinstall-node-modules --notify true

Config

Usually you set the options via command line arguments (e.g. --install false). If you prefer a config file instead just create a reinstall-node-modules.json file in your process cwd.

Credits

This package is inspired by install-changed.

Last but not least, if this package is helpful to you it'll be great when you give me a star on github and share it. Keeps me motivated to continue the development.