@pubinfo/commitlint 2.1.10-beta.1 → 2.1.10-beta.2

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.
package/dist/index.d.mts CHANGED
@@ -33,17 +33,18 @@ declare function runNpx(cwd?: string): boolean;
33
33
  /**
34
34
  * 清理已安装的 git hooks 文件
35
35
  * 只删除 .git/hooks 下的 hook 文件,不会修改 package.json
36
+ * 兼容 Windows 和 Unix 系统
36
37
  */
37
38
  declare function removeGitHooks(cwd?: string): boolean;
38
39
  /**
39
40
  * 禁用 git hooks(不修改 package.json 配置)
40
- * 1. 清理已安装的 hooks 文件
41
- * 2. 清除 core.hooksPath 配置(如果有)
41
+ * 1. 设置 core.hooksPath 到一个空目录(跨平台兼容)
42
+ * 2. 清理已安装的 hooks 文件(作为备份方案)
42
43
  */
43
44
  declare function disableCommitlint(cwd?: string): boolean;
44
45
  /**
45
46
  * 启用 git hooks
46
- * 1. 清除残留的 hooksPath 配置
47
+ * 1. 清除 core.hooksPath 配置,恢复默认 .git/hooks
47
48
  * 2. 执行 npx simple-git-hooks 重新安装 hooks
48
49
  */
49
50
  declare function enableCommitlint(cwd?: string): boolean;
@@ -378,14 +378,21 @@ function runNpx(cwd = process.cwd()) {
378
378
  /**
379
379
  * 清理已安装的 git hooks 文件
380
380
  * 只删除 .git/hooks 下的 hook 文件,不会修改 package.json
381
+ * 兼容 Windows 和 Unix 系统
381
382
  */
382
383
  function removeGitHooks(cwd = process.cwd()) {
383
384
  try {
384
385
  const hooksDir = resolve(cwd, ".git", "hooks");
385
- const preCommit = resolve(hooksDir, "pre-commit");
386
- const commitMsg = resolve(hooksDir, "commit-msg");
387
- if (fs.existsSync(preCommit)) fs.removeSync(preCommit);
388
- if (fs.existsSync(commitMsg)) fs.removeSync(commitMsg);
386
+ for (const hookName of ["pre-commit", "commit-msg"]) {
387
+ const hookPath = resolve(hooksDir, hookName);
388
+ try {
389
+ if (fs.existsSync(hookPath)) fs.removeSync(hookPath);
390
+ } catch {
391
+ try {
392
+ fs.writeFileSync(hookPath, "#!/bin/sh\nexit 0\n", { mode: 493 });
393
+ } catch {}
394
+ }
395
+ }
389
396
  return true;
390
397
  } catch {
391
398
  return false;
@@ -393,26 +400,26 @@ function removeGitHooks(cwd = process.cwd()) {
393
400
  }
394
401
  /**
395
402
  * 禁用 git hooks(不修改 package.json 配置)
396
- * 1. 清理已安装的 hooks 文件
397
- * 2. 清除 core.hooksPath 配置(如果有)
403
+ * 1. 设置 core.hooksPath 到一个空目录(跨平台兼容)
404
+ * 2. 清理已安装的 hooks 文件(作为备份方案)
398
405
  */
399
406
  function disableCommitlint(cwd = process.cwd()) {
400
407
  try {
408
+ const emptyHooksDir = resolve(cwd, ".git", "hooks-disabled");
409
+ fs.ensureDirSync(emptyHooksDir);
410
+ execSync(`git config core.hooksPath "${emptyHooksDir.replace(/\\/g, "/")}"`, {
411
+ cwd,
412
+ stdio: "ignore"
413
+ });
401
414
  removeGitHooks(cwd);
402
- try {
403
- execSync("git config --unset core.hooksPath", {
404
- cwd,
405
- stdio: "ignore"
406
- });
407
- } catch {}
408
415
  return true;
409
416
  } catch {
410
- return false;
417
+ return removeGitHooks(cwd);
411
418
  }
412
419
  }
413
420
  /**
414
421
  * 启用 git hooks
415
- * 1. 清除残留的 hooksPath 配置
422
+ * 1. 清除 core.hooksPath 配置,恢复默认 .git/hooks
416
423
  * 2. 执行 npx simple-git-hooks 重新安装 hooks
417
424
  */
418
425
  function enableCommitlint(cwd = process.cwd()) {
package/dist/run.mjs CHANGED
@@ -6,7 +6,7 @@ import { defineCommand, runMain as runMain$1 } from "citty";
6
6
 
7
7
  //#region package.json
8
8
  var name = "@pubinfo/commitlint";
9
- var version = "2.1.10-beta.1";
9
+ var version = "2.1.10-beta.2";
10
10
  var description = "commitlint config for Pubinfo projects";
11
11
 
12
12
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo/commitlint",
3
3
  "type": "module",
4
- "version": "2.1.10-beta.1",
4
+ "version": "2.1.10-beta.2",
5
5
  "description": "commitlint config for Pubinfo projects",
6
6
  "exports": {
7
7
  ".": "./dist/index.mjs"