@pubinfo-pr/commitlint 0.197.1 → 0.203.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.
package/dist/index.d.mts CHANGED
@@ -1,161 +1,5 @@
1
- import { Commit } from "conventional-commits-parser";
1
+ import { UserConfig } from "@commitlint/types";
2
2
 
3
- //#region ../../node_modules/.pnpm/@commitlint+types@20.3.1/node_modules/@commitlint/types/lib/ensure.d.ts
4
- type TargetCaseType = "camel-case" | "kebab-case" | "snake-case" | "pascal-case" | "start-case" | "upper-case" | "uppercase" | "sentence-case" | "sentencecase" | "lower-case" | "lowercase" | "lowerCase";
5
- //#endregion
6
- //#region ../../node_modules/.pnpm/@commitlint+types@20.3.1/node_modules/@commitlint/types/lib/prompt.d.ts
7
- type RuleField = "header" | "type" | "scope" | "subject" | "body" | "footer";
8
- type PromptName = RuleField | "isBreaking" | "breakingBody" | "breaking" | "isIssueAffected" | "issuesBody" | "issues";
9
- type PromptConfig = {
10
- settings: {
11
- scopeEnumSeparator: string;
12
- enableMultipleScopes: boolean;
13
- };
14
- messages: PromptMessages;
15
- questions: Partial<Record<PromptName, {
16
- description?: string;
17
- messages?: {
18
- [K: string]: string;
19
- };
20
- enum?: {
21
- [enumName: string]: {
22
- description?: string;
23
- title?: string;
24
- emoji?: string;
25
- };
26
- };
27
- emojiInHeader?: boolean;
28
- }>>;
29
- };
30
- type PromptMessages = {
31
- skip: string;
32
- max: string;
33
- min: string;
34
- emptyWarning: string;
35
- upperLimitWarning: string;
36
- lowerLimitWarning: string;
37
- [_key: string]: string;
38
- };
39
- type UserPromptConfig = DeepPartial<PromptConfig>;
40
- type DeepPartial<T> = { [P in keyof T]?: { [K in keyof T[P]]?: T[P][K] } };
41
- //#endregion
42
- //#region ../../node_modules/.pnpm/@commitlint+types@20.3.1/node_modules/@commitlint/types/lib/rules.d.ts
43
- /**
44
- * Rules match the input either as successful or failed.
45
- * For example, when `header-full-stop` detects a full stop and is set as "always"; it's true.
46
- * If the `header-full-stop` discovers a full stop but is set to "never"; it's false.
47
- */
48
- type RuleOutcome = Readonly<[boolean, string?]>;
49
- /**
50
- * Rules receive a parsed commit, condition, and possible additional settings through value.
51
- * All rules should provide the most sensible rule condition and value.
52
- */
53
- type RuleType = "async" | "sync" | "either";
54
- type BaseRule<Value = never, Type extends RuleType = "either"> = (parsed: Commit, when?: RuleConfigCondition, value?: Value) => Type extends "either" ? RuleOutcome | Promise<RuleOutcome> : Type extends "async" ? Promise<RuleOutcome> : Type extends "sync" ? RuleOutcome : never;
55
- type Rule<Value = never> = BaseRule<Value, "either">;
56
- type AsyncRule<Value = never> = BaseRule<Value, "async">;
57
- type SyncRule<Value = never> = BaseRule<Value, "sync">;
58
- /**
59
- * Rules always have a severity.
60
- * Severity indicates what to do if the rule is found to be broken
61
- * 0 - Disable this rule
62
- * 1 - Warn for violations
63
- * 2 - Error for violations
64
- */
65
- declare enum RuleConfigSeverity {
66
- Disabled = 0,
67
- Warning = 1,
68
- Error = 2,
69
- }
70
- /**
71
- * Rules always have a condition.
72
- * It can be either "always" (as tested), or "never" (as tested).
73
- * For example, `header-full-stop` can be enforced as "always" or "never".
74
- */
75
- type RuleConfigCondition = "always" | "never";
76
- type RuleConfigTuple<T> = T extends void ? Readonly<[RuleConfigSeverity.Disabled]> | Readonly<[RuleConfigSeverity, RuleConfigCondition]> : Readonly<[RuleConfigSeverity.Disabled]> | Readonly<[RuleConfigSeverity, RuleConfigCondition, T]>;
77
- declare enum RuleConfigQuality {
78
- User = 0,
79
- Qualified = 1,
80
- }
81
- type QualifiedRuleConfig<T> = (() => RuleConfigTuple<T>) | (() => Promise<RuleConfigTuple<T>>) | RuleConfigTuple<T>;
82
- type RuleConfig<V = RuleConfigQuality.Qualified, T = void> = V extends RuleConfigQuality.Qualified ? RuleConfigTuple<T> : QualifiedRuleConfig<T>;
83
- type CaseRuleConfig<V = RuleConfigQuality.User> = RuleConfig<V, TargetCaseType | TargetCaseType[]>;
84
- type LengthRuleConfig<V = RuleConfigQuality.User> = RuleConfig<V, number>;
85
- type EnumRuleConfig<V = RuleConfigQuality.User> = RuleConfig<V, string[]>;
86
- type ObjectRuleConfig<V = RuleConfigQuality.User, T = Record<string, unknown>> = RuleConfig<V, T>;
87
- type RulesConfig<V = RuleConfigQuality.User> = {
88
- "body-case": CaseRuleConfig<V>;
89
- "body-empty": RuleConfig<V>;
90
- "body-full-stop": RuleConfig<V, string>;
91
- "body-leading-blank": RuleConfig<V>;
92
- "body-max-length": LengthRuleConfig<V>;
93
- "body-max-line-length": LengthRuleConfig<V>;
94
- "body-min-length": LengthRuleConfig<V>;
95
- "breaking-change-exclamation-mark": CaseRuleConfig<V>;
96
- "footer-empty": RuleConfig<V>;
97
- "footer-leading-blank": RuleConfig<V>;
98
- "footer-max-length": LengthRuleConfig<V>;
99
- "footer-max-line-length": LengthRuleConfig<V>;
100
- "footer-min-length": LengthRuleConfig<V>;
101
- "header-case": CaseRuleConfig<V>;
102
- "header-full-stop": RuleConfig<V, string>;
103
- "header-max-length": LengthRuleConfig<V>;
104
- "header-min-length": LengthRuleConfig<V>;
105
- "header-trim": RuleConfig<V>;
106
- "references-empty": RuleConfig<V>;
107
- "scope-case": CaseRuleConfig<V> | ObjectRuleConfig<V, {
108
- cases: TargetCaseType[];
109
- delimiters?: string[];
110
- }>;
111
- "scope-delimiter-style": EnumRuleConfig<V>;
112
- "scope-empty": RuleConfig<V>;
113
- "scope-enum": EnumRuleConfig<V> | ObjectRuleConfig<V, {
114
- scopes: string[];
115
- delimiters?: string[];
116
- }>;
117
- "scope-max-length": LengthRuleConfig<V>;
118
- "scope-min-length": LengthRuleConfig<V>;
119
- "signed-off-by": RuleConfig<V, string>;
120
- "subject-case": CaseRuleConfig<V>;
121
- "subject-empty": RuleConfig<V>;
122
- "subject-full-stop": RuleConfig<V, string>;
123
- "subject-max-length": LengthRuleConfig<V>;
124
- "subject-min-length": LengthRuleConfig<V>;
125
- "trailer-exists": RuleConfig<V, string>;
126
- "type-case": CaseRuleConfig<V>;
127
- "type-empty": RuleConfig<V>;
128
- "type-enum": EnumRuleConfig<V>;
129
- "type-max-length": LengthRuleConfig<V>;
130
- "type-min-length": LengthRuleConfig<V>;
131
- [key: string]: AnyRuleConfig<V>;
132
- };
133
- type AnyRuleConfig<V> = RuleConfig<V, unknown> | RuleConfig<V, void>;
134
- //#endregion
135
- //#region ../../node_modules/.pnpm/@commitlint+types@20.3.1/node_modules/@commitlint/types/lib/load.d.ts
136
- interface Plugin {
137
- rules: {
138
- [ruleName: string]: Rule | AsyncRule | SyncRule;
139
- };
140
- }
141
- interface UserConfig {
142
- extends?: string | string[];
143
- formatter?: string;
144
- rules?: Partial<RulesConfig>;
145
- parserPreset?: string | ParserPreset | Promise<ParserPreset>;
146
- ignores?: ((commit: string) => boolean)[];
147
- defaultIgnores?: boolean;
148
- plugins?: (string | Plugin)[];
149
- helpUrl?: string;
150
- prompt?: UserPromptConfig;
151
- [key: string]: unknown;
152
- }
153
- interface ParserPreset {
154
- name?: string;
155
- path?: string;
156
- parserOpts?: unknown;
157
- }
158
- //#endregion
159
3
  //#region src/config/index.d.ts
160
4
  declare const commitPreset: UserConfig & {
161
5
  prompt?: any;
@@ -176,9 +20,34 @@ declare function createGitMessage(rootPath?: string): boolean;
176
20
  declare function runGitMessage(rootPath?: string): boolean;
177
21
  //#endregion
178
22
  //#region src/init/simple.git.hook.d.ts
23
+ /**
24
+ * 配置 simple-git-hooks 到 package.json
25
+ * 注意:此函数只写入配置,不会删除配置
26
+ */
179
27
  declare function runSimpleGitHooks(script?: string, cwd?: string, enabled?: boolean): boolean;
28
+ /**
29
+ * 执行 npx simple-git-hooks
30
+ * 会根据 package.json 中的配置安装 hooks 到 .git/hooks/
31
+ */
180
32
  declare function runNpx(cwd?: string): boolean;
181
- 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;
182
51
  //#endregion
183
52
  //#region src/prompt/index.d.ts
184
53
  interface PromptResult {
@@ -196,4 +65,4 @@ declare function isInsideGitRepo(): boolean;
196
65
  declare function lintMessage(message: string): Promise<boolean>;
197
66
  declare function lintAndReturn(message: string): Promise<string>;
198
67
  //#endregion
199
- 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-pr/commitlint";
9
- var version = "2.1.8";
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-pr 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-pr/commitlint",
3
3
  "type": "module",
4
- "version": "0.197.1",
4
+ "version": "0.203.1",
5
5
  "description": "commitlint config for Pubinfo projects",
6
6
  "exports": {
7
7
  ".": "./dist/index.mjs"
@@ -28,13 +28,13 @@
28
28
  "node": "^20.19.0 || >=22.12.0"
29
29
  },
30
30
  "dependencies": {
31
- "@commitlint/config-conventional": "^20.3.1",
32
- "@commitlint/lint": "^20.3.1",
33
- "@commitlint/load": "^20.3.1",
31
+ "@commitlint/config-conventional": "^19.8.1",
32
+ "@commitlint/lint": "^19.8.1",
33
+ "@commitlint/load": "^19.8.1",
34
34
  "citty": "^0.1.6",
35
35
  "czg": "^1.12.0",
36
- "fs-extra": "^11.3.3",
37
- "unconfig": "^7.4.2"
36
+ "fs-extra": "^11.3.0",
37
+ "unconfig": "^7.3.3"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsdown",