@pubinfo/commitlint 2.0.7 → 2.0.8-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.ts CHANGED
@@ -8,6 +8,9 @@ declare function loadCommitConfig(): UserConfig & {
8
8
  prompt?: any;
9
9
  };
10
10
  //#endregion
11
+ //#region src/config/commitlint.d.ts
12
+ declare function isCommitlintEnabled(): Promise<boolean>;
13
+ //#endregion
11
14
  //#region src/init/cz.config.d.ts
12
15
  declare function createCzConfig(cwd?: string): boolean;
13
16
  declare function runCzConfig(czConfigPath: string, cwd?: string): boolean;
@@ -17,7 +20,7 @@ declare function createGitMessage(rootPath?: string): boolean;
17
20
  declare function runGitMessage(rootPath?: string): boolean;
18
21
  //#endregion
19
22
  //#region src/init/simple.git.hook.d.ts
20
- declare function runSimpleGitHooks(script?: string, cwd?: string): boolean;
23
+ declare function runSimpleGitHooks(script?: string, cwd?: string, enabled?: boolean): boolean;
21
24
  declare function runNpx(cwd?: string): boolean;
22
25
  //#endregion
23
26
  //#region src/prompt/index.d.ts
@@ -36,4 +39,4 @@ declare function isInsideGitRepo(): boolean;
36
39
  declare function lintMessage(message: string): Promise<boolean>;
37
40
  declare function lintAndReturn(message: string): Promise<string>;
38
41
  //#endregion
39
- export { commitPreset, createCzConfig, createGitMessage, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
42
+ export { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { commitPreset, createCzConfig, createGitMessage, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-CZXQspF4.js";
1
+ import { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-qcqvSiOT.js";
2
2
 
3
- export { commitPreset, createCzConfig, createGitMessage, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
3
+ export { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { execSync, spawn } from "node:child_process";
3
+ import { loadConfig } from "unconfig";
3
4
  import { resolve } from "node:path";
4
5
  import process$1 from "node:process";
5
6
  import CZGPackage from "czg/package.json" with { type: "json" };
@@ -254,6 +255,31 @@ function loadCommitConfig() {
254
255
  return commitPreset;
255
256
  }
256
257
 
258
+ //#endregion
259
+ //#region src/config/commitlint.ts
260
+ let cachedState;
261
+ function resolveCommitlintEnabled(value) {
262
+ if (typeof value === "boolean") return value;
263
+ if (value && typeof value === "object") {
264
+ if (typeof value.enabled === "boolean") return value.enabled;
265
+ if (typeof value.disable === "boolean") return !value.disable;
266
+ }
267
+ }
268
+ async function isCommitlintEnabled() {
269
+ if (typeof cachedState === "boolean") return cachedState;
270
+ try {
271
+ const result = await loadConfig({
272
+ sources: [{ files: "pubinfo.config" }],
273
+ merge: false
274
+ });
275
+ const resolved = resolveCommitlintEnabled(result?.config?.commitlint);
276
+ cachedState = typeof resolved === "boolean" ? resolved : true;
277
+ } catch {
278
+ cachedState = true;
279
+ }
280
+ return cachedState;
281
+ }
282
+
257
283
  //#endregion
258
284
  //#region ../../node_modules/.pnpm/universalify@2.0.1/node_modules/universalify/index.js
259
285
  var require_universalify = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/universalify@2.0.1/node_modules/universalify/index.js": ((exports) => {
@@ -2260,17 +2286,36 @@ function runGitMessage(rootPath = process$1.cwd()) {
2260
2286
  //#endregion
2261
2287
  //#region src/init/simple.git.hook.ts
2262
2288
  var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
2263
- function runSimpleGitHooks(script = "pubinfo-commit", cwd$1 = process$1.cwd()) {
2289
+ function runSimpleGitHooks(script = "pubinfo-commit", cwd$1 = process$1.cwd(), enabled = true) {
2264
2290
  const pkgPath = resolve(cwd$1, "package.json");
2265
2291
  if (!import_lib.default.existsSync(pkgPath)) return false;
2266
2292
  try {
2267
2293
  const raw = import_lib.default.readFileSync(pkgPath, "utf8");
2268
2294
  const json = JSON.parse(raw);
2269
- json["simple-git-hooks"] = json["simple-git-hooks"] || {};
2295
+ const hooks = json["simple-git-hooks"] || {};
2270
2296
  const desiredPre = "pnpm lint-staged";
2271
- if (json["simple-git-hooks"]["pre-commit"] !== desiredPre) json["simple-git-hooks"]["pre-commit"] = desiredPre;
2272
2297
  const desiredCommitMsg = `pnpm exec ${script} --edit $1`;
2273
- if (json["simple-git-hooks"]["commit-msg"] !== desiredCommitMsg) json["simple-git-hooks"]["commit-msg"] = desiredCommitMsg;
2298
+ if (!enabled) {
2299
+ let changed = false;
2300
+ if (hooks["pre-commit"] === desiredPre) {
2301
+ delete hooks["pre-commit"];
2302
+ changed = true;
2303
+ }
2304
+ if (hooks["commit-msg"] === desiredCommitMsg) {
2305
+ delete hooks["commit-msg"];
2306
+ changed = true;
2307
+ }
2308
+ if (!Object.keys(hooks).length && json["simple-git-hooks"]) {
2309
+ delete json["simple-git-hooks"];
2310
+ changed = true;
2311
+ } else if (changed) json["simple-git-hooks"] = hooks;
2312
+ if (changed) import_lib.default.writeFileSync(pkgPath, `${JSON.stringify(json, null, 2)}\n`, "utf8");
2313
+ return changed;
2314
+ }
2315
+ json["simple-git-hooks"] = hooks;
2316
+ if (hooks["pre-commit"] !== desiredPre) hooks["pre-commit"] = desiredPre;
2317
+ if (hooks["commit-msg"] !== desiredCommitMsg) hooks["commit-msg"] = desiredCommitMsg;
2318
+ json["simple-git-hooks"] = hooks;
2274
2319
  import_lib.default.writeFileSync(pkgPath, `${JSON.stringify(json, null, 2)}\n`, "utf8");
2275
2320
  return true;
2276
2321
  } catch {
@@ -2338,6 +2383,7 @@ function isInsideGitRepo() {
2338
2383
  //#endregion
2339
2384
  //#region src/utils/lint.message.ts
2340
2385
  async function lintMessage(message) {
2386
+ if (!await isCommitlintEnabled()) return true;
2341
2387
  try {
2342
2388
  const result = await (await import("@commitlint/lint")).default(message, commitPreset.rules, commitPreset);
2343
2389
  if (!result.valid) {
@@ -2356,4 +2402,4 @@ async function lintAndReturn(message) {
2356
2402
  }
2357
2403
 
2358
2404
  //#endregion
2359
- export { commitPreset, createCzConfig, createGitMessage, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
2405
+ export { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
package/dist/run.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createCzConfig, createGitMessage, isInsideGitRepo, lintMessage, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-CZXQspF4.js";
1
+ import { createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintMessage, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-qcqvSiOT.js";
2
2
  import process from "node:process";
3
3
  import fs from "node:fs";
4
4
  import { defineCommand, runMain as runMain$1 } from "citty";
@@ -6,7 +6,7 @@ import { defineCommand, runMain as runMain$1 } from "citty";
6
6
  //#region package.json
7
7
  var name = "@pubinfo/commitlint";
8
8
  var type = "module";
9
- var version = "2.0.7";
9
+ var version = "2.0.8-beta.2";
10
10
  var description = "commitlint config for Pubinfo projects";
11
11
  var exports = { ".": "./dist/index.js" };
12
12
  var main$1 = "./dist/index.js";
@@ -25,7 +25,8 @@ var dependencies = {
25
25
  "@commitlint/lint": "catalog:commit",
26
26
  "@commitlint/load": "catalog:commit",
27
27
  "citty": "catalog:node",
28
- "czg": "catalog:commit"
28
+ "czg": "catalog:commit",
29
+ "unconfig": "catalog:node"
29
30
  };
30
31
  var package_default = {
31
32
  name,
@@ -73,12 +74,23 @@ const main = defineCommand({
73
74
  },
74
75
  run: async ({ args }) => {
75
76
  const { edit, init } = args;
77
+ const enabled = await isCommitlintEnabled();
76
78
  if (!isInsideGitRepo()) {
77
79
  console.error("[pubinfo-commit] 未检测到 Git 仓库。请在已初始化的 Git 项目中运行,或执行 `git init` 后重试。");
78
80
  return;
79
81
  }
80
82
  if (init) {
81
- const pubinfoDir = `${process.cwd()}/.pubinfo`;
83
+ const cwd = process.cwd();
84
+ if (!enabled) {
85
+ const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd, false);
86
+ const removedCli = runSimpleGitHooks("pubinfo commit", cwd, false);
87
+ if (removedDefault || removedCli) {
88
+ runNpx(cwd);
89
+ console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已清理 simple-git-hooks 配置。");
90
+ } else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
91
+ return;
92
+ }
93
+ const pubinfoDir = `${cwd}/.pubinfo`;
82
94
  if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
83
95
  const gitMessageStatus = createGitMessage();
84
96
  const czConfigStatus = createCzConfig(pubinfoDir);
@@ -96,6 +108,7 @@ const main = defineCommand({
96
108
  return;
97
109
  }
98
110
  if (edit) {
111
+ if (!enabled) return;
99
112
  try {
100
113
  const raw = fs.readFileSync(String(edit), "utf8").trim();
101
114
  if (!raw) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo/commitlint",
3
3
  "type": "module",
4
- "version": "2.0.7",
4
+ "version": "2.0.8-beta.2",
5
5
  "description": "commitlint config for Pubinfo projects",
6
6
  "exports": {
7
7
  ".": "./dist/index.js"
@@ -32,7 +32,8 @@
32
32
  "@commitlint/lint": "^19.8.1",
33
33
  "@commitlint/load": "^19.8.1",
34
34
  "citty": "^0.1.6",
35
- "czg": "^1.12.0"
35
+ "czg": "^1.12.0",
36
+ "unconfig": "^7.3.2"
36
37
  },
37
38
  "scripts": {
38
39
  "build": "tsdown",