@pubinfo-nightly/commitlint 2026.2.3 → 2026.2.4

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
@@ -20,9 +20,34 @@ declare function createGitMessage(rootPath?: string): boolean;
20
20
  declare function runGitMessage(rootPath?: string): boolean;
21
21
  //#endregion
22
22
  //#region src/init/simple.git.hook.d.ts
23
+ /**
24
+ * 配置 simple-git-hooks 到 package.json
25
+ * 注意:此函数只写入配置,不会删除配置
26
+ */
23
27
  declare function runSimpleGitHooks(script?: string, cwd?: string, enabled?: boolean): boolean;
28
+ /**
29
+ * 执行 npx simple-git-hooks
30
+ * 会根据 package.json 中的配置安装 hooks 到 .git/hooks/
31
+ */
24
32
  declare function runNpx(cwd?: string): boolean;
25
- declare function configureGitHooksPath(enabled?: boolean, cwd?: string): boolean;
33
+ /**
34
+ * 清理已安装的 git hooks 文件
35
+ * 只删除 .git/hooks 下的 hook 文件,不会修改 package.json
36
+ * 兼容 Windows 和 Unix 系统
37
+ */
38
+ declare function removeGitHooks(cwd?: string): boolean;
39
+ /**
40
+ * 禁用 git hooks(不修改 package.json 配置)
41
+ * 1. 设置 core.hooksPath 到一个空目录(跨平台兼容)
42
+ * 2. 清理已安装的 hooks 文件(作为备份方案)
43
+ */
44
+ declare function disableCommitlint(cwd?: string): boolean;
45
+ /**
46
+ * 启用 git hooks
47
+ * 1. 清除 core.hooksPath 配置,恢复默认 .git/hooks
48
+ * 2. 执行 npx simple-git-hooks 重新安装 hooks
49
+ */
50
+ declare function enableCommitlint(cwd?: string): boolean;
26
51
  //#endregion
27
52
  //#region src/prompt/index.d.ts
28
53
  interface PromptResult {
@@ -40,4 +65,4 @@ declare function isInsideGitRepo(): boolean;
40
65
  declare function lintMessage(message: string): Promise<boolean>;
41
66
  declare function lintAndReturn(message: string): Promise<string>;
42
67
  //#endregion
43
- export { commitPreset, configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
68
+ export { commitPreset, createCzConfig, createGitMessage, disableCommitlint, enableCommitlint, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, removeGitHooks, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as configureGitHooksPath, c as createGitMessage, d as runCzConfig, f as isCommitlintEnabled, i as runPrompt, l as runGitMessage, m as loadCommitConfig, n as lintMessage, o as runNpx, p as commitPreset, r as isInsideGitRepo, s as runSimpleGitHooks, t as lintAndReturn, u as createCzConfig } from "./lint.message.mjs";
1
+ import { a as disableCommitlint, c as runNpx, d as runGitMessage, f as createCzConfig, g as loadCommitConfig, h as commitPreset, i as runPrompt, l as runSimpleGitHooks, m as isCommitlintEnabled, n as lintMessage, o as enableCommitlint, p as runCzConfig, r as isInsideGitRepo, s as removeGitHooks, t as lintAndReturn, u as createGitMessage } from "./lint.message.mjs";
2
2
 
3
- export { commitPreset, configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
3
+ export { commitPreset, createCzConfig, createGitMessage, disableCommitlint, enableCommitlint, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, removeGitHooks, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
@@ -337,6 +337,10 @@ function runGitMessage(rootPath = process.cwd()) {
337
337
 
338
338
  //#endregion
339
339
  //#region src/init/simple.git.hook.ts
340
+ /**
341
+ * 配置 simple-git-hooks 到 package.json
342
+ * 注意:此函数只写入配置,不会删除配置
343
+ */
340
344
  function runSimpleGitHooks(script = "pubinfo-commit", cwd = process.cwd(), enabled = true) {
341
345
  if (!enabled) return false;
342
346
  const pkgPath = resolve(cwd, "package.json");
@@ -347,7 +351,6 @@ function runSimpleGitHooks(script = "pubinfo-commit", cwd = process.cwd(), enabl
347
351
  const hooks = json["simple-git-hooks"] || {};
348
352
  const desiredPre = "pnpm lint-staged";
349
353
  const desiredCommitMsg = `pnpm exec ${script} --edit $1`;
350
- json["simple-git-hooks"] = hooks;
351
354
  if (hooks["pre-commit"] !== desiredPre) hooks["pre-commit"] = desiredPre;
352
355
  if (hooks["commit-msg"] !== desiredCommitMsg) hooks["commit-msg"] = desiredCommitMsg;
353
356
  json["simple-git-hooks"] = hooks;
@@ -357,6 +360,10 @@ function runSimpleGitHooks(script = "pubinfo-commit", cwd = process.cwd(), enabl
357
360
  return false;
358
361
  }
359
362
  }
363
+ /**
364
+ * 执行 npx simple-git-hooks
365
+ * 会根据 package.json 中的配置安装 hooks 到 .git/hooks/
366
+ */
360
367
  function runNpx(cwd = process.cwd()) {
361
368
  try {
362
369
  execSync("npx simple-git-hooks", {
@@ -368,22 +375,65 @@ function runNpx(cwd = process.cwd()) {
368
375
  return false;
369
376
  }
370
377
  }
371
- function configureGitHooksPath(enabled = true, cwd = process.cwd()) {
378
+ /**
379
+ * 清理已安装的 git hooks 文件
380
+ * 只删除 .git/hooks 下的 hook 文件,不会修改 package.json
381
+ * 兼容 Windows 和 Unix 系统
382
+ */
383
+ function removeGitHooks(cwd = process.cwd()) {
372
384
  try {
373
- if (enabled) {
374
- execSync("git config --unset core.hooksPath", {
375
- cwd,
376
- stdio: "ignore"
377
- });
378
- return true;
385
+ const hooksDir = resolve(cwd, ".git", "hooks");
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
+ }
379
395
  }
380
- execSync("git config core.hooksPath /dev/null", {
396
+ return true;
397
+ } catch {
398
+ return false;
399
+ }
400
+ }
401
+ /**
402
+ * 禁用 git hooks(不修改 package.json 配置)
403
+ * 1. 设置 core.hooksPath 到一个空目录(跨平台兼容)
404
+ * 2. 清理已安装的 hooks 文件(作为备份方案)
405
+ */
406
+ function disableCommitlint(cwd = process.cwd()) {
407
+ try {
408
+ const emptyHooksDir = resolve(cwd, ".git", "hooks-disabled");
409
+ fs.ensureDirSync(emptyHooksDir);
410
+ execSync(`git config core.hooksPath "${emptyHooksDir.replace(/\\/g, "/")}"`, {
381
411
  cwd,
382
412
  stdio: "ignore"
383
413
  });
414
+ removeGitHooks(cwd);
415
+ return true;
416
+ } catch {
417
+ return removeGitHooks(cwd);
418
+ }
419
+ }
420
+ /**
421
+ * 启用 git hooks
422
+ * 1. 清除 core.hooksPath 配置,恢复默认 .git/hooks
423
+ * 2. 执行 npx simple-git-hooks 重新安装 hooks
424
+ */
425
+ function enableCommitlint(cwd = process.cwd()) {
426
+ try {
427
+ try {
428
+ execSync("git config --unset core.hooksPath", {
429
+ cwd,
430
+ stdio: "ignore"
431
+ });
432
+ } catch {}
433
+ runNpx(cwd);
384
434
  return true;
385
435
  } catch {
386
- return enabled;
436
+ return false;
387
437
  }
388
438
  }
389
439
 
@@ -464,4 +514,4 @@ async function lintAndReturn(message) {
464
514
  }
465
515
 
466
516
  //#endregion
467
- export { configureGitHooksPath as a, createGitMessage as c, runCzConfig as d, isCommitlintEnabled as f, runPrompt as i, runGitMessage as l, loadCommitConfig as m, lintMessage as n, runNpx as o, commitPreset as p, isInsideGitRepo as r, runSimpleGitHooks as s, lintAndReturn as t, createCzConfig as u };
517
+ export { disableCommitlint as a, runNpx as c, runGitMessage as d, createCzConfig as f, loadCommitConfig as g, commitPreset as h, runPrompt as i, runSimpleGitHooks as l, isCommitlintEnabled as m, lintMessage as n, enableCommitlint as o, runCzConfig as p, isInsideGitRepo as r, removeGitHooks as s, lintAndReturn as t, createGitMessage as u };
package/dist/run.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as configureGitHooksPath, c as createGitMessage, d as runCzConfig, f as isCommitlintEnabled, i as runPrompt, l as runGitMessage, n as lintMessage, o as runNpx, r as isInsideGitRepo, s as runSimpleGitHooks, u as createCzConfig } from "./lint.message.mjs";
1
+ import { a as disableCommitlint, c as runNpx, d as runGitMessage, f as createCzConfig, i as runPrompt, l as runSimpleGitHooks, m as isCommitlintEnabled, n as lintMessage, p as runCzConfig, r as isInsideGitRepo, u as createGitMessage } from "./lint.message.mjs";
2
2
  import { spawnSync } from "node:child_process";
3
3
  import process from "node:process";
4
4
  import fs from "node:fs";
@@ -6,7 +6,7 @@ import { defineCommand, runMain as runMain$1 } from "citty";
6
6
 
7
7
  //#region package.json
8
8
  var name = "@pubinfo-nightly/commitlint";
9
- var version = "2.1.9";
9
+ var version = "2.1.10-beta.2";
10
10
  var description = "commitlint config for Pubinfo projects";
11
11
 
12
12
  //#endregion
@@ -51,14 +51,10 @@ const main = defineCommand({
51
51
  if (init) {
52
52
  const cwd = process.cwd();
53
53
  if (!enabled) {
54
- const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd, false);
55
- const removedCli = runSimpleGitHooks("pubinfo-nightly commit", cwd, false);
56
- const disabledHooks = configureGitHooksPath(false, cwd);
57
- if (removedDefault || removedCli || disabledHooks) console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
54
+ if (disableCommitlint(cwd)) console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
58
55
  else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
59
56
  return;
60
57
  }
61
- configureGitHooksPath(true, cwd);
62
58
  const pubinfoDir = `${cwd}/.pubinfo`;
63
59
  if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
64
60
  const gitMessageStatus = createGitMessage();
@@ -78,7 +74,7 @@ const main = defineCommand({
78
74
  }
79
75
  if (edit) {
80
76
  if (!enabled) {
81
- configureGitHooksPath(false, process.cwd());
77
+ disableCommitlint(process.cwd());
82
78
  return;
83
79
  }
84
80
  try {
@@ -95,7 +91,7 @@ const main = defineCommand({
95
91
  }
96
92
  if (!enabled) {
97
93
  console.log("[pubinfo-commit] commitlint 已关闭,交互模式不可用。");
98
- configureGitHooksPath(false, process.cwd());
94
+ disableCommitlint(process.cwd());
99
95
  return;
100
96
  }
101
97
  const result = await runPrompt();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo-nightly/commitlint",
3
3
  "type": "module",
4
- "version": "2026.02.03",
4
+ "version": "2026.02.04",
5
5
  "description": "commitlint config for Pubinfo projects",
6
6
  "exports": {
7
7
  ".": "./dist/index.mjs"