Skip to content

Commit

Permalink
docs: update install script to mjs and simplify (#1357)
Browse files Browse the repository at this point in the history
* docs: update install script to mjs and fix CI checks

* revert indent

* Update how-to.md

---------

Co-authored-by: typicode <typicode@gmail.com>
  • Loading branch information
starnayuta and typicode committed Jan 25, 2024
1 parent 534bfed commit e7ada20
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/how-to.md
Expand Up @@ -66,21 +66,23 @@ Modify the `prepare` script to never fail:
"prepare": "husky || true"
```

You'll still get a `command not found` error message in your output which may be confusing. To make it silent, create `.husky/install.js`:
You'll still get a `command not found` error message in your output which may be confusing. To make it silent, create `.husky/install.mjs`:

```js
// Skip Husky install in production and CI
import husky from 'husky'

if (process.env.NODE_ENV === 'production' || process.env.CI === '1') {
process.exit(0)
}
const husky = await import('husky')
husky()

console.log(husky())

This comment has been minimized.

Copy link
@jerome-benoit

jerome-benoit Jan 26, 2024

console.log(husky()) -> husky.default()

The package.json does not contain enough information to permit node.js to infer if the import is ESM or CommonJS and default to CJS.

```

Then, use it in `prepare`:

```json
"prepare": "node .husky/install.js"
"prepare": "node .husky/install.mjs"
```

## Testing Hooks Without Committing
Expand Down

0 comments on commit e7ada20

Please sign in to comment.