Skip to content

Commit

Permalink
v9 (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode authored Jan 25, 2024
1 parent a5c36f5 commit ec13855
Show file tree
Hide file tree
Showing 51 changed files with 5,274 additions and 5,669 deletions.
3 changes: 0 additions & 3 deletions .commitlintrc.json

This file was deleted.

5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true
[*]
end_of_line = lf
indent_style = tab
insert_final_newline = false
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

40 changes: 8 additions & 32 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,11 @@
Husky improves your commits and more 🐶 _woof!_

# Install

```
npm install husky -D
```

# Usage

Edit `package.json > prepare` script and run it once:

```sh
npm pkg set scripts.prepare="husky install"
npm run prepare
```

Add a hook:

```sh
npx husky add .husky/pre-commit "npm test"
git add .husky/pre-commit
```

Make a commit:

```sh
git commit -m "Keep calm and commit"
# `npm test` will run every time you commit
```

_For more use cases (project in sub-directory, custom directory, CI support, ...), see documentation._

## Documentation

https://typicode.github.io/husky

**Important** Upgrading from v4 to v8 requires migrating previous config, please see the docs.
**Important** Upgrading from v4 to v9 requires migrating previous config, please see the docs.

## Articles

Expand All @@ -54,6 +23,13 @@ MIT

# Sponsors

<p align="center">
<a href="./docs/sponsorkit/sponsors.svg">
<img src='./docs/sponsorkit/sponsors.svg'/>
</a>
</p>


## Companies

Does your company use husky? Ask your manager or marketing team if your company would be interested in supporting this project.
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
cache: npm
- run: npm ci
- name: Build
run: npm run docs:build
working-directory: ./docs
run: npx vitepress build
- uses: actions/configure-pages@v2
- uses: actions/upload-pages-artifact@v1
with:
Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@ permissions:
contents: read # to fetch code (actions/checkout)

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- run: npm ci --ignore-scripts
- run: npm run lint

test:
strategy:
matrix:
node-version: [16, 18, 20]
node-version: [18, 20]
os: [ubuntu-latest, macOS-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -31,4 +21,4 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm --version
- run: npm ci --ignore-scripts
- run: npm test
- run: ./test.sh
9 changes: 3 additions & 6 deletions .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm test
node-version: 20
- run: ./test.sh

publish-npm:
needs: build
Expand All @@ -31,9 +30,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run build
node-version: 20
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
lib
node_modules
husky-*.tgz
tsconfig.tsbuildinfo
*.log
docs/.vitepress/cache
docs/.vitepress/dist
docs/.env
docs/sponsorkit/.cache.json
docs/sponsorkit/sponsors.json
docs/sponsorkit/sponsors.png
4 changes: 0 additions & 4 deletions .husky/commit-msg

This file was deleted.

4 changes: 1 addition & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm test
./test.sh
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
test*
docs
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disable=SC1090,SC2164
1 change: 0 additions & 1 deletion CONTRIBUTING.md

This file was deleted.

37 changes: 0 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1 @@
# husky

> Modern native Git hooks made easy
Husky improves your commits and more 🐶 *woof!*

# Install

```
npm install husky --save-dev
```

# Usage

Edit `package.json > prepare` script and run it once:

```sh
npm pkg set scripts.prepare="husky install"
npm run prepare
```

Add a hook:

```sh
npx husky add .husky/pre-commit "npm test"
git add .husky/pre-commit
```

Make a commit:

```sh
git commit -m "Keep calm and commit"
# `npm test` will run
```

# Documentation

https://typicode.github.io/husky
21 changes: 21 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
import f, { writeFileSync as w } from 'fs'
import i from './index.js'

let a = process.argv[2]

if (a == 'init') {
let p = process.env.npm_package_json
let d = JSON.parse(f.readFileSync(p))
d.scripts.prepare = 'husky'
w('package.json', JSON.stringify(d, null, /\t/.test() ? '\t' : 2))

This comment has been minimized.

Copy link
@glensc

glensc Jan 31, 2024

Contributor

/\t/.test() is never true?

I think you wanted to run /\t/.test(d) here?

This comment has been minimized.

Copy link
@typicode

typicode Jan 31, 2024

Author Owner

Good catch, that's correct

This comment has been minimized.

Copy link
@glensc

glensc Feb 1, 2024

Contributor

Cross link the fix so I and future me can follow :)

This comment has been minimized.

Copy link
@glensc

glensc Feb 1, 2024

Contributor

And i think it's more complicated, you need to save result of f.readFileSync(p) call to compare for /\t/

This comment has been minimized.

Copy link
@glensc

glensc Feb 1, 2024

Contributor
process.stdout.write(i())
w('.husky/pre-commit', process.env.npm_config_user_agent.split('/')[0] + ' test')
process.exit()
}

let d = c => console.error(`${c} command is deprecated`)
if (['add', 'set', 'uninstall'].includes(a)) { d(a); process.exit(1) }
if (a == 'install') d(a)

process.stdout.write(i(a == 'install' ? undefined : a))
25 changes: 25 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { defineConfig } from 'vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "Husky",
description: "Git hooks made easy",
base: '/husky/',
themeConfig: {
// outline: [2, 3],
socialLinks: [
{ icon: 'github', link: 'https://github.com/typicode/husky' },
],
carbonAds: {
code: 'CWYDP53L',
placement: 'typicodegithubio',
},
sidebar: [
{ text: 'Introduction', link: '/' },
{ text: 'Get Started', link: '/get-started' },
{ text: 'How To', link: '/how-to' },
{ text: 'Troubleshoot', link: '/troubleshoot' },
{ text: 'Migrate from v4', link: '/migrate-from-v4' },
],
}
})
45 changes: 0 additions & 45 deletions docs/.vitepress/config.ts

This file was deleted.

63 changes: 63 additions & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Get started

## Install

::: code-group

```shell [npm]
npm install --save-dev husky
```

```shell [pnpm]
pnpm add --save-dev husky
```

```shell [yarn]
yarn add --dev husky
# Add pinst ONLY if your package is not private
yarn add --dev pinst
```

```shell [bun]
bun add --dev husky
```

:::

## `husky init` (recommended)

The `init` command simplifies setting up husky in a project. It creates a `pre-commit` script in `.husky/` and updates the `prepare` script in `package.json`. Modifications can be made later to suit your workflow.

::: code-group

```shell [npm]
npx husky init
```

```shell [pnpm]
pnpm exec husky init
```

```shell [yarn]
# Due to specific caveats and differences with other package managers,
# refer to the How To section.
```

```shell [bun]
bunx husky init
```

:::


## Try it

Congratulations! You've successfully set up your first Git hook with just one command 🎉. Let's test it:

```shell
git commit -m "Keep calm and commit"
# test script will run every time you commit
```

_For manual setup and more information, see the [How To](how-to) section._

Loading

0 comments on commit ec13855

Please sign in to comment.