stylelint-standard 0.0.1-security → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of stylelint-standard might be problematic. Click here for more details.

@@ -0,0 +1,40 @@
1
+ import { defineConfig, presets } from 'sponsorkit'
2
+
3
+ export default defineConfig({
4
+ // includePrivate: true,
5
+ tiers: [
6
+ {
7
+ title: 'Past Sponsors',
8
+ monthlyDollars: -1,
9
+ preset: presets.xs,
10
+ },
11
+ {
12
+ title: 'Backers',
13
+ preset: presets.base,
14
+ },
15
+ {
16
+ title: 'Sponsors',
17
+ monthlyDollars: 10,
18
+ preset: presets.medium,
19
+ // to insert custom elements after the tier block
20
+ composeAfter: (composer, _tierSponsors, _config) => {
21
+ composer.addSpan(10)
22
+ },
23
+ },
24
+ {
25
+ title: 'Bronze Sponsors',
26
+ monthlyDollars: 100,
27
+ preset: presets.large,
28
+ },
29
+ {
30
+ title: 'Silver Sponsors',
31
+ monthlyDollars: 250,
32
+ preset: presets.large,
33
+ },
34
+ {
35
+ title: 'Gold Sponsors',
36
+ monthlyDollars: 500,
37
+ preset: presets.xl,
38
+ },
39
+ ],
40
+ })
@@ -0,0 +1,41 @@
1
+ # Troubleshoot
2
+
3
+ ## Command not found
4
+
5
+ See [How To](how-to) for solutions.
6
+
7
+ ## Hooks not running
8
+
9
+ 1. Verify the file name is correct. For example, `precommit` or `pre-commit.sh` are invalid names. Refer to the Git hooks [documentation](https://git-scm.com/docs/githooks) for valid names.
10
+ 2. Run `git config core.hooksPath` and ensure it points to `.husky/_` (or your custom hooks directory).
11
+ 1. Confirm your Git version is above `2.9`.
12
+
13
+ ## `.git/hooks/` Not Working After Uninstall
14
+
15
+ If hooks in `.git/hooks/` don't work post-uninstalling `husky`, execute `git config --unset core.hooksPath`.
16
+
17
+ ## Yarn on Windows
18
+
19
+ Git hooks might fail with Yarn on Windows using Git Bash (`stdin is not a tty`). For Windows users, implement this workaround:
20
+
21
+ 1. Create `.husky/common.sh`:
22
+
23
+ ```shell
24
+ command_exists () {
25
+ command -v "$1" >/dev/null 2>&1
26
+ }
27
+
28
+ # Workaround for Windows 10, Git Bash, and Yarn
29
+ if command_exists winpty && test -t 1; then
30
+ exec < /dev/tty
31
+ fi
32
+ ```
33
+
34
+ 2. Source it where Yarn commands are run:
35
+
36
+ ```shell
37
+ # .husky/pre-commit
38
+ . .husky/common.sh
39
+
40
+ yarn ...
41
+ ```
@@ -0,0 +1,63 @@
1
+ # 快速开始
2
+
3
+ ## 安装
4
+
5
+ ::: code-group
6
+
7
+ ```shell [npm]
8
+ npm install --save-dev husky
9
+ ```
10
+
11
+ ```shell [pnpm]
12
+ pnpm add --save-dev husky
13
+ ```
14
+
15
+ ```shell [yarn]
16
+ yarn add --dev husky
17
+ # 如果你的项目不是私有的,那么只需要安装 pinst
18
+ yarn add --dev pinst
19
+ ```
20
+
21
+ ```shell [bun]
22
+ bun add --dev husky
23
+ ```
24
+
25
+ :::
26
+
27
+ ## `husky init` <Badge type="tip" text="推荐" />
28
+
29
+ `init` 命令简化了项目中的 husky 设置。它会在 `.husky/` 中创建 `pre-commit` 脚本,并更新 `package.json` 中的 `prepare` 脚本。随后可根据你的工作流进行修改。
30
+
31
+ ::: code-group
32
+
33
+ ```shell [npm]
34
+ npx husky init
35
+ ```
36
+
37
+ ```shell [pnpm]
38
+ pnpm exec husky init
39
+ ```
40
+
41
+ ```shell [yarn]
42
+ # 由于特殊的注意事项和与其他包管理器的差异,
43
+ # 请参考“如何使用”章节。
44
+ ```
45
+
46
+ ```shell [bun]
47
+ bunx husky init
48
+ ```
49
+
50
+ :::
51
+
52
+
53
+ ## 试一试
54
+
55
+ 恭喜你!你已经成功地用一个命令设置了你的第一个 Git 钩子 🎉。让我们测试一下:
56
+
57
+ ```shell
58
+ git commit -m "Keep calm and commit"
59
+ # 测试脚本会在每次提交时运行
60
+ ```
61
+
62
+ _有关手动设置和更多信息,请参见 [如何使用](how-to.md) 章节_
63
+
@@ -0,0 +1,326 @@
1
+ # 如何使用
2
+
3
+ ## 添加新 Hook
4
+
5
+ 添加 hook 与创建文件一样简单。可以通过你喜欢的编辑器、脚本或 echo 命令来实现。例如,在 Linux/macOS 中:
6
+ ```shell
7
+ echo "npm test" > .husky/pre-commit
8
+ ```
9
+
10
+ ## 启动文件
11
+
12
+ Husky 允许你在运行钩子之前执行本地命令。它从这些文件中读取命令:
13
+
14
+ - `$XDG_CONFIG_HOME/husky/init.sh`
15
+ - `~/.config/husky/init.sh`
16
+ - `~/.huskyrc` (已弃用)
17
+
18
+ Windows 系统:`C:\Users\yourusername\.config\husky\init.sh`
19
+
20
+ ## 跳过 Git 钩子
21
+
22
+ ### 对于单个命令
23
+
24
+ 大多数 Git 命令都包含一个 `-n/--no-verify` 选项来用于跳过钩子:
25
+
26
+ ```sh
27
+ git commit -m "..." -n # 跳过 Git 钩子
28
+ ```
29
+
30
+ 对于没有使用此标识的命令,使用 HUSKY=0 来临时禁用钩子:
31
+
32
+ ```shell
33
+ HUSKY=0 git ... # 临时禁用所有 Git 钩子
34
+ git ... # 钩子会再次运行
35
+ ```
36
+
37
+ ### 对于多个命令
38
+
39
+ 在一个较长的时间里禁用钩子(例如,在变基或者合并期间):
40
+
41
+ ```shell
42
+ export HUSKY=0 # 禁用所有 Git 钩子
43
+ git ...
44
+ git ...
45
+ unset HUSKY # 重新启用钩子
46
+ ```
47
+
48
+ ### 对于 GUI 或全局
49
+
50
+ 要在 GUI 客户端或全局禁用 Git 钩子,请修改 Husky 配置:
51
+
52
+ ```sh
53
+ # ~/.config/husky/init.sh
54
+ export HUSKY=0 # Husky 不会安装,也不会再你的机器上运行钩子
55
+ ```
56
+
57
+ ## CI 服务器和 Docker
58
+
59
+ 要避免在 CI 服务器或 Docker 中安装 Git 钩子,请使用 `HUSKY=0`。例如,在 GitHub Actions 中:
60
+
61
+ ```yml
62
+ # https://docs.github.com/en/actions/learn-github-actions/variables
63
+ env:
64
+ HUSKY: 0
65
+ ```
66
+
67
+ 如果只安装 `dependencies`(不是 `devDependencies`),`"prepare": "husky"` 脚本可能会失败,因为 Husky 不会被安装。
68
+
69
+ 你有多种解决方案。
70
+
71
+ 修改 `prepare` 脚本使其永远不会失败:
72
+
73
+ ```json
74
+ // package.json
75
+ "prepare": "husky || true"
76
+ ```
77
+
78
+ 你仍然会在输出中看到一个 `command not found` 的错误消息,这可能会让你很感到困惑。为了让它消失,创建 `.husky/install.mjs`:
79
+
80
+ <!-- Since husky may not be installed, it must be imported dynamically after prod/CI check -->
81
+ ```js
82
+ // 在生产环境或 CI 环境中跳过 Husky 的安装
83
+ if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') {
84
+ process.exit(0)
85
+ }
86
+ const husky = (await import('husky')).default
87
+ console.log(husky())
88
+ ```
89
+
90
+ 然后,在 `prepare` 脚本中使用它:
91
+
92
+ ```json
93
+ "prepare": "node .husky/install.mjs"
94
+ ```
95
+
96
+ ## 测试钩子
97
+
98
+ 要测试一个钩子,将 `exit 1` 添加到钩子脚本以中止 Git 命令:
99
+
100
+ ```shell
101
+ # .husky/pre-commit
102
+
103
+ # 你的 WIP 脚本
104
+ # ...
105
+
106
+ exit 1
107
+ ```
108
+
109
+ ```shell
110
+ git commit -m "testing pre-commit code"
111
+ # 提交不会被创建
112
+ ```
113
+
114
+ ## 项目不在 Git 根目录
115
+
116
+ 出于安全考虑,Husky 不会安装在父目录(`../`)中。但是,你可以在 `prepare` 脚本中更改目录。
117
+
118
+ 考虑一下这个项目结构:
119
+
120
+ ```
121
+ .
122
+ ├── .git/
123
+ ├── backend/ # 没有 package.json
124
+ └── frontend/ # package.json 中带有 husky
125
+ ```
126
+
127
+ 像这样设置你的 prepare 脚本:
128
+
129
+ ```json
130
+ "prepare": "cd .. && husky frontend/.husky"
131
+ ```
132
+
133
+ 在你的 hook 脚本中,将目录切换回相关的子目录:
134
+
135
+ ```shell
136
+ # frontend/.husky/pre-commit
137
+ cd frontend
138
+ npm test
139
+ ```
140
+
141
+ ## 非 shell 脚本钩子
142
+
143
+ 为了运行需要使用脚本语言的脚本,对每个适用的钩子使用以下模式:
144
+
145
+ (使用钩子 `pre-commit` 和 NodeJS 的示例)
146
+ 1. 为钩子创建一个入口:
147
+ ```shell
148
+ .husky/pre-commit
149
+ ```
150
+ 2. 在文件中添加以下内容:
151
+ ```shell
152
+ node .husky/pre-commit.js
153
+ ```
154
+ 3. 在 `.husky/pre-commit.js` 文件中:
155
+ ```javascript
156
+ // 你的 NodeJS 代码
157
+ // ...
158
+ ```
159
+
160
+ ## Bash
161
+
162
+ 钩子脚本需要与 POSIX 兼容,以确保最佳兼容性,因为并非每个人都有 bash (例如 Windows 用户)。
163
+
164
+ 也就是说,如果你的团队不使用 Windows,你可以这样使用 Bash:
165
+
166
+ ```shell
167
+ # .husky/pre-commit
168
+
169
+ bash << EOF
170
+ # Put your bash script inside
171
+ # ...
172
+ EOF
173
+ ```
174
+
175
+ ## Node 版本管理器和 GUI
176
+
177
+ 如果您在 GUI 中使用 Git 钩子,并通过版本管理器(比如 `nvm`、`n`、`fnm`、`asdf`、`volta` 等等)安装 Node,由于 `PATH` 环境变量问题,你可能会遇到 `command not found` 报错。
178
+
179
+ ### 了解 `PATH` 和版本管理器
180
+
181
+ `PATH` 是一个包含目录列表的环境变量,你的 shell 在这些目录中检索命令,如果没找到这个命令,你就会得到一个 `command not found` 报错。
182
+
183
+ 在 shell 中运行 `echo $PATH` 来查看其内容。
184
+
185
+ 版本管理器的工作方式如下:
186
+ 1. 将初始化代码添加到 shell 启动文件(`.zshrc`、`.bashrc` 等),它会在每次打开终端时运行。
187
+ 2. 将 Node 版本下载到主文件夹下的目录中。
188
+
189
+ 例如,如果你有两个 Node 版本:
190
+
191
+ ```shell
192
+ ~/version-manager/Node-X/node
193
+ ~/version-manager/Node-Y/node
194
+ ```
195
+
196
+ 打开终端将初始化版本管理器,它将选择一个版本(比如 `Node-Y`)并预先设置其到 `PATH` 的路径:
197
+
198
+ ```shell
199
+ echo $PATH
200
+ # 输出
201
+ ~/version-manager/Node-Y/:...
202
+ ```
203
+
204
+ 现在,Node 指向 `Node-Y`。切换到 `Node-X` 时会相应地改变 `PATH`:
205
+
206
+ ```shell
207
+ echo $PATH
208
+ # 输出
209
+ ~/version-manager/Node-X/:...
210
+ ```
211
+
212
+ 出现这个问题是因为在终端之外启动的 GUI 没有初始化版本管理器,导致 `PATH` 没有 Node 安装路径。因此,来自 GUI 的 Git 钩子常常会失败。
213
+
214
+ ### 解决方案
215
+
216
+ husky 在每个钩子之前都会执行 `~/.config/husky/init.sh`。将版本管理器初始化代码复制到这里,以确保在 GUI 中运行。
217
+
218
+ `nvm` 示例:
219
+
220
+ ```shell
221
+ # ~/.config/husky/init.sh
222
+ export NVM_DIR="$HOME/.nvm"
223
+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # 加载 nvm
224
+ ```
225
+
226
+ 或者,如果你的 shell 启动文件快速且轻量,也可以直接使用:
227
+
228
+ ```shell
229
+ # ~/.config/husky/init.sh
230
+ . ~/.zshrc
231
+ ```
232
+
233
+ ## 手动设置
234
+
235
+ Git 需要配置,husky 需要在 `.husky/` 中设置文件。
236
+
237
+ 在仓库中运行一次 `husky` 命令。理想情况下,将其设置在 `package.json` 的 `prepare` 脚本中,以便每次安装后自动执行<Badge type="tip" text="推荐" />。
238
+
239
+ ::: code-group
240
+
241
+ ```json [npm]
242
+ {
243
+ "scripts": {
244
+ "prepare": "husky" // [!code hl]
245
+ }
246
+ }
247
+ ```
248
+
249
+ ```json [pnpm]
250
+ {
251
+ "scripts": {
252
+ "prepare": "husky" // [!code hl]
253
+ }
254
+ }
255
+ ```
256
+
257
+ ```json [yarn]
258
+ {
259
+ "scripts": {
260
+ // Yarn 不支持 prepare 脚本
261
+ "postinstall": "husky",
262
+ // 如果发布到 npmjs.com,需要加上这个
263
+ "prepack": "pinst --disable",
264
+ "postpack": "pinst --enable"
265
+ }
266
+ }
267
+ ```
268
+
269
+ ```json [bun]
270
+ {
271
+ "scripts": {
272
+ "prepare": "husky" // [!code hl]
273
+ }
274
+ }
275
+ ```
276
+
277
+ :::
278
+
279
+ 运行一次 `prepare`:
280
+
281
+ ::: code-group
282
+
283
+ ```sh [npm]
284
+ npm run prepare
285
+ ```
286
+
287
+ ```sh [pnpm]
288
+ pnpm run prepare
289
+ ```
290
+
291
+ ```sh [yarn]
292
+ # Yarn 不支持 `prepare`
293
+ yarn run postinstall
294
+ ```
295
+
296
+ ```sh [bun]
297
+ bun run prepare
298
+ ```
299
+
300
+ :::
301
+
302
+ 在 `.husky/` 目录中创建一个 `pre-commit` 文件:
303
+
304
+ ::: code-group
305
+
306
+ ```shell [npm]
307
+ # .husky/pre-commit
308
+ npm test
309
+ ```
310
+
311
+ ```shell [pnpm]
312
+ # .husky/pre-commit
313
+ pnpm test
314
+ ```
315
+
316
+ ```shell [yarn]
317
+ # .husky/pre-commit
318
+ yarn test
319
+ ```
320
+
321
+ ```sh [bun]
322
+ # .husky/pre-commit
323
+ bun test
324
+ ```
325
+
326
+ :::
@@ -0,0 +1,81 @@
1
+ ![npm](https://img.shields.io/npm/dm/husky)
2
+
3
+ > 使现代的原生 Git 钩子变得简单
4
+
5
+ Husky 能使你的提交变得更好 🐶 _汪!_
6
+
7
+ 在提交或推送时,自动化 **检查提交信息**、**检查代码** 和 **运行测试**。
8
+
9
+ 从 [这里](./get-started.md) 快速开始。
10
+
11
+ [查看 v9 更新日志](https://github.com/typicode/husky/releases/tag/v9.0.1)去发现所有新特性! 🚀
12
+
13
+ ## 特性
14
+
15
+ - 仅有 `2 kB`(📦 _gzip 压缩后_),没有任何依赖。
16
+ - 非常快(运行速度约 `~1ms`)
17
+ - 使用新 Git 特性(`core.hooksPath`)
18
+ - 支持:
19
+ - macOS、Linux、Windows
20
+ - Git GUI、Node 版本管理器、自定义钩子目录、嵌套项目、Monorepos
21
+ - [所有 13 个客户端 Git 钩子](https://git-scm.com/docs/githooks)
22
+
23
+ 更多:
24
+ - Branch-specific 钩子
25
+ - 使用 POSIX shell 为高级案例编写脚本
26
+ - 遵循 Git 的原生钩子组织结构
27
+ - 使用 `prepare` 脚本与 [npm](https://docs.npmjs.com/cli/v10/using-npm/scripts#best-practices) 最佳实践保持一致
28
+ - Opt-in/opt-out 选项
29
+ - 用户友好的报错信息
30
+
31
+ ## 赞助者
32
+
33
+ 支持这个项目来成为一个赞助者 [点击此处](https://github.com/sponsors/typicode) 💖
34
+
35
+ ### 特别赞助
36
+
37
+ <p align="center">
38
+ <a href="https://app.tea.xyz/sign-up?r=8L2HWfJB6hs">
39
+ <img src="https://github.com/typicode/husky/assets/5502029/1b95c571-0157-48bc-a147-0d8d2fbc1d8a" /><br/>
40
+ Get rewards for your open-source contributions
41
+ </a>
42
+ </p>
43
+
44
+ ### GitHub
45
+
46
+ <p align="center">
47
+ <a href="../sponsorkit/sponsors.svg">
48
+ <img src='../sponsorkit/sponsors.svg'/>
49
+ </a>
50
+ </p>
51
+
52
+ ### Open Collective
53
+
54
+ <a href="https://opencollective.com/husky/tiers/company/0/website"><img src="https://opencollective.com/husky/tiers/company/0/avatar.svg?avatarHeight=120"></a>
55
+ <a href="https://opencollective.com/husky/tiers/company/1/website"><img src="https://opencollective.com/husky/tiers/company/1/avatar.svg?avatarHeight=120"></a>
56
+ <a href="https://opencollective.com/husky/tiers/company/2/website"><img src="https://opencollective.com/husky/tiers/company/2/avatar.svg?avatarHeight=120"></a>
57
+ <a href="https://opencollective.com/husky/tiers/company/3/website"><img src="https://opencollective.com/husky/tiers/company/3/avatar.svg?avatarHeight=120"></a>
58
+ <a href="https://opencollective.com/husky/tiers/company/4/website"><img src="https://opencollective.com/husky/tiers/company/4/avatar.svg?avatarHeight=120"></a>
59
+ <a href="https://opencollective.com/husky/tiers/company/5/website"><img src="https://opencollective.com/husky/tiers/company/5/avatar.svg?avatarHeight=120"></a>
60
+
61
+ ## 谁在使用
62
+
63
+ Husky 在 GitHub 上用于[超过 130 万个项目](https://github.com/typicode/husky/network/dependents?package_id=UGFja2FnZS0xODQzNTgwNg%3D%3D),包括:
64
+
65
+ - [vercel/next.js](https://github.com/vercel/next.js)
66
+ - [vercel/hyper](https://github.com/vercel/hyper)
67
+ - [webpack/webpack](https://github.com/webpack/webpack)
68
+ - [angular/angular](https://github.com/angular/angular)
69
+ - [facebook/docusaurus](https://github.com/facebook/docusaurus)
70
+ - [microsoft/vscode](https://github.com/microsoft/vscode)
71
+ - [11ty/eleventy](https://github.com/11ty/eleventy)
72
+ - [stylelint/stylelint](https://github.com/stylelint/stylelint)
73
+ - [colinhacks/zod](https://github.com/colinhacks/zod)
74
+ - [rollup/rollup](https://github.com/rollup/rollup)
75
+ - [tinyhttp/tinyhttp](https://github.com/tinyhttp/tinyhttp)
76
+ - ...
77
+
78
+ ## 相关文章
79
+
80
+ - [为什么 Husky 放弃了传统的 JS 配置](https://blog.typicode.com/posts/husky-git-hooks-javascript-config/)
81
+ - [为什么 Husky 不再自动安装了](https://blog.typicode.com/posts/husky-git-hooks-autoinstall/)
@@ -0,0 +1,72 @@
1
+ # 从 v4 迁移
2
+
3
+ 如果你使用 `npm` 或 `yarn` 调用 `package.json` 脚本,**你可以简单地将命令**从配置文件复制到相应的钩子:
4
+
5
+ Husky v4
6
+
7
+ ```json
8
+ // package.json
9
+ {
10
+ "hooks": {
11
+ "pre-commit": "npm test && npm run foo" // [!code hl]
12
+ }
13
+ }
14
+ ```
15
+
16
+ Husky v9
17
+
18
+ ```shell
19
+ # .husky/pre-commit
20
+ # 提示,你现在可以在多行中输入命令
21
+ npm test # [!code hl]
22
+ npm run foo # [!code hl]
23
+ ```
24
+
25
+ 如果你想调用本地安装的二进制文件,**现在你需要通过包管理器运行它们**:
26
+
27
+ ::: code-group
28
+
29
+ ```js [.huskyrc.json (v4)]
30
+ {
31
+ "hooks": {
32
+ "pre-commit": "jest"
33
+ }
34
+ }
35
+ ```
36
+
37
+ ```shell [.husky/pre-commit (v9)]
38
+ # ...
39
+ npx --no jest
40
+ # 或者
41
+ yarn jest
42
+ ```
43
+
44
+ :::
45
+
46
+ `HUSKY_GIT_PARAMS` 环境变量现在替换成原生参数 `$1`、`$2`。
47
+
48
+ ::: code-group
49
+
50
+ ```js [.huskyrc.json (v4)]
51
+ {
52
+ "hooks": {
53
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
54
+ }
55
+ }
56
+ ```
57
+
58
+ ```shell [.husky/commit-msg (v9)]
59
+ # ...
60
+ npx --no -- commitlint --edit $1
61
+ # 或者
62
+ yarn commitlint --edit $1
63
+ ```
64
+
65
+ :::
66
+
67
+ 其他环境变量的变化:
68
+
69
+ - `HUSKY_SKIP_HOOKS` 替换成 `HUSKY`.
70
+ - `HUSKY_SKIP_INSTALL` 替换成 `HUSKY`.
71
+ - `HUSKY_GIT_PARAMS` 被移除。取而代之的是 Git 参数应该直接在脚本中使用(例如 `$1`)。
72
+ - 本地安装工具的 `PATH` 不再自动设置,你需要使用包管理器来运行它们。
@@ -0,0 +1,41 @@
1
+ # 故障排查
2
+
3
+ ## 找不到命令(Command not found)
4
+
5
+ 请参阅 [如何使用](./how-to) 获取解决方案。
6
+
7
+ ## 钩子未运行
8
+
9
+ 1. 验证文件名是否正确。例如,`precommit` 或 `pre-commit.sh` 都是无效的名称。有效名称请参考 Git 钩子[文档](https://git-scm.com/docs/githooks)。
10
+ 2. 运行 `git config core.hooksPath` 并确保它指向 `.husky/_`(或者你的自定义目录)。
11
+ 3. 确认你的 Git 版本高于 `2.9`。
12
+
13
+ ## 卸载后 `.git/hooks/` 无法正常使用
14
+
15
+ 如果卸载 `husky` 后 hooks 在 `.git/hooks/` 中无法正常使用,请执行命令 `git config --unset core.hooksPath`。
16
+
17
+ ## 在 Windows 上使用 Yarn
18
+
19
+ 在 Windows 上使用 Git Bash 时,Git 钩子可能会失败(`stdin is not a tty`)。对于 Windows 用户,通过以下解决方案来实现:
20
+
21
+ 1. 创建 `.husky/common.sh`:
22
+
23
+ ```shell
24
+ command_exists () {
25
+ command -v "$1" >/dev/null 2>&1
26
+ }
27
+
28
+ # Windows 10、Git Bash 和 Yarn 的解决方案
29
+ if command_exists winpty && test -t 1; then
30
+ exec < /dev/tty
31
+ fi
32
+ ```
33
+
34
+ 1. 在运行 Yarn 命令的地方使用它:
35
+
36
+ ```shell
37
+ # .husky/pre-commit
38
+ . "$(dirname -- "$0")/common.sh"
39
+
40
+ yarn ...
41
+ ```
package/husky ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env sh
2
+ [ "$HUSKY" = "2" ] && set -x
3
+ n=$(basename "$0")
4
+ s=$(dirname "$(dirname "$0")")/$n
5
+
6
+ [ ! -f "$s" ] && exit 0
7
+
8
+ if [ -f "$HOME/.huskyrc" ]; then
9
+ echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
10
+ fi
11
+ i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
12
+ [ -f "$i" ] && . "$i"
13
+
14
+ [ "${HUSKY-}" = "0" ] && exit 0
15
+
16
+ export PATH="node_modules/.bin:$PATH"
17
+ sh -e "$s" "$@"
18
+ c=$?
19
+
20
+ [ $c != 0 ] && echo "husky - $n script failed (code $c)"
21
+ [ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
22
+ exit $c
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function (dir?: string): string;