Skip to content

Commit

Permalink
docs: recommend prepare for npm/pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Feb 20, 2022
1 parent a07a176 commit 50f7d1b
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@

> `pinst` lets you have `postinstall` hook that runs only in dev 🍺
This can be useful if you want to automatically run commands just after `npm install`, but don't want your package users to be affected.
__Important__ if your project is using npm or pnpm, you can achieve the desired effect by setting a `prepare` hook instead. `pinst` is mainly useful for Yarn 2+ since it doesn't support `prepare` hook. See https://yarnpkg.com/advanced/lifecycle-scripts

## Usage

```sh
$ npm install pinst --save-dev
```

```js
// package.json
{
"scripts": {
"postinstall": "<some dev only command>",
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable"
"prepack": "pinst --disable",
"postpack": "pinst --enable"
}
}
```

```sh
$ npm publish
```

_On `prepublishOnly`, `postinstall` will be renamed to `_postinstall` (disabled)_
_On `prepack`, `postinstall` will be renamed to `_postinstall` (disabled)_

_On `postpublish`, it will be renamed back to `postinstall` (enabled)_
_On `postpack`, it will be renamed back to `postinstall` (enabled)_

## CLI

Expand All @@ -39,15 +31,6 @@ _On `postpublish`, it will be renamed back to `postinstall` (enabled)_
--silent, -s
```

## Try it

To test that everything works without actually publishing your package, you can manually run the following commands:

```sh
$ npm run prepublishOnly
$ npm run postpublish
```

## Tips

By inverting commands, you can also use `pinst` to enable `postinstall` for your users only and not yourself.
Expand Down

0 comments on commit 50f7d1b

Please sign in to comment.