standards-cli 1.0.8 → 1.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "standards-cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "一键初始化前端项目提交规范链路(cz-git + commitlint + husky + lint-staged)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -47,11 +47,6 @@
47
47
  "path": "cz-git"
48
48
  }
49
49
  },
50
- "pnpm": {
51
- "overrides": {
52
- "string-width": "^7.0.0"
53
- }
54
- },
55
50
  "devDependencies": {
56
51
  "@commitlint/cli": "^20.3.1",
57
52
  "@commitlint/config-conventional": "^20.3.1",
@@ -199,7 +199,10 @@ async function updatePackageJson() {
199
199
  pkg.scripts.prepare = "husky";
200
200
  console.log(' ✔ 添加 scripts.prepare = "husky"');
201
201
  modified = true;
202
- } else if (pkg.scripts.prepare === "husky install" || pkg.scripts.prepare === "husky init") {
202
+ } else if (
203
+ pkg.scripts.prepare === "husky install" ||
204
+ pkg.scripts.prepare === "husky init"
205
+ ) {
203
206
  pkg.scripts.prepare = "husky";
204
207
  console.log(' ✔ 更新 scripts.prepare = "husky"');
205
208
  modified = true;
@@ -242,21 +245,29 @@ async function updatePackageJson() {
242
245
  console.log(" ⚠ config.commitizen.path (已存在,跳过)");
243
246
  }
244
247
 
245
- // 添加 pnpm overrides 来降级 string-width(兼容 Node.js 18)
246
- if (!pkg.pnpm) {
247
- pkg.pnpm = {};
248
- }
249
- if (!pkg.pnpm.overrides) {
250
- pkg.pnpm.overrides = {};
251
- }
252
- if (pkg.pnpm.overrides["string-width"] !== "^7.0.0") {
253
- pkg.pnpm.overrides["string-width"] = "^7.0.0";
254
- console.log(
255
- ' ✔ 添加 pnpm.overrides.string-width = "^7.0.0" (兼容 Node.js 18)'
256
- );
257
- modified = true;
248
+ // 智能处理 string-width 版本兼容性
249
+ // string-width v5+ 是 ESM 模块,可能导致某些工具在低版本 Node.js 或 CommonJS 环境下报错
250
+ // 检测 Node.js 版本,< 18 时降级到 v4
251
+ const nodeVersion = process.version.slice(1).split(".").map(Number);
252
+ const needOverride = nodeVersion[0] < 18;
253
+
254
+ if (needOverride) {
255
+ if (!pkg.pnpm) {
256
+ pkg.pnpm = {};
257
+ }
258
+ if (!pkg.pnpm.overrides) {
259
+ pkg.pnpm.overrides = {};
260
+ }
261
+ if (!pkg.pnpm.overrides["string-width"]) {
262
+ pkg.pnpm.overrides["string-width"] = "^4.2.3";
263
+ console.log(
264
+ ' ✔ 添加 pnpm.overrides["string-width"] = "^4.2.3" (Node.js < 18 兼容)'
265
+ );
266
+ modified = true;
267
+ }
258
268
  } else {
259
- console.log(" ⚠ pnpm.overrides.string-width (已存在,跳过)");
269
+ // Node.js >= 18,不添加 override,让 pnpm 自动处理
270
+ console.log(" ℹ Node.js >= 18,跳过 string-width override");
260
271
  }
261
272
 
262
273
  if (modified) {
@@ -1,17 +1,31 @@
1
1
  module.exports = {
2
2
  extends: ["@commitlint/config-conventional"],
3
3
  rules: {
4
- "scope-enum": [0],
5
- "type-enum": [2, "always", ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"]],
6
- "scope-empty": [2, "never"],
4
+ "type-enum": [
5
+ 2,
6
+ "always",
7
+ [
8
+ "feat",
9
+ "fix",
10
+ "docs",
11
+ "style",
12
+ "refactor",
13
+ "perf",
14
+ "test",
15
+ "build",
16
+ "ci",
17
+ "chore",
18
+ "revert",
19
+ ],
20
+ ],
7
21
  "subject-empty": [2, "never"],
8
22
  "subject-max-length": [2, "always", 72],
9
23
  },
10
24
  prompt: {
11
25
  messages: {
12
26
  type: "选择你要提交的类型:",
13
- scope: "填写 scope (必填,如: auth, login, user):",
14
- subject: "填写简短描述 (必填,最多 72 字符):",
27
+ customScope: "输入 scope (可选,如: login, auth):",
28
+ subject: "输入简短描述:",
15
29
  confirmCommit: "确认提交?",
16
30
  },
17
31
  types: [
@@ -22,16 +36,20 @@ module.exports = {
22
36
  { value: "refactor", name: "refactor: 重构" },
23
37
  { value: "perf", name: "perf: 性能优化" },
24
38
  { value: "test", name: "test: 测试相关" },
25
- { value: "build", name: "build: 构建系统或外部依赖变动" },
26
- { value: "ci", name: "ci: CI 配置变动" },
39
+ { value: "build", name: "build: 构建系统" },
40
+ { value: "ci", name: "ci: CI 配置" },
27
41
  { value: "chore", name: "chore: 其他杂项" },
28
42
  { value: "revert", name: "revert: 回滚提交" },
29
43
  ],
30
44
  useEmoji: false,
31
- scopes: [],
32
- enableMultipleScopes: false,
33
- scopeEnumSeparator: ",",
34
- allowCustomScopes: true,
35
- allowEmptyScopes: false,
45
+ skipQuestions: [
46
+ "scope",
47
+ "body",
48
+ "breaking",
49
+ "breakingBody",
50
+ "footer",
51
+ "footerPrefix",
52
+ ],
53
+ defaultScope: "___CUSTOM___:",
36
54
  },
37
55
  };