@icebreakers/commitlint-config 1.2.0 → 1.2.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/README.md CHANGED
@@ -1,16 +1,20 @@
1
1
  # @icebreakers/commitlint-config
2
2
 
3
- `@icebreakers/commitlint-config` 是一个基于 `@commitlint/config-conventional` 的可配置 preset。我们在保留社区标准的基础上,提供了一套函数式 API,方便团队按需扩展类型、Scope、Subject 等规则,并同步更新 commit prompt 元数据。
3
+ - [简体中文指南](./README.zh.md)
4
4
 
5
- ## 快速开始
5
+ ## Overview
6
+
7
+ `@icebreakers/commitlint-config` wraps `@commitlint/config-conventional`, exposes a typed factory API, and keeps commit prompts in sync with any custom types you add. Use it to enforce Conventional Commits across monorepos while tailoring type, scope, and subject rules per team.
8
+
9
+ ## Installation
6
10
 
7
11
  ```bash
8
- pnpm add -D @icebreakers/commitlint-config
12
+ pnpm add -D @commitlint/cli @icebreakers/commitlint-config
9
13
  ```
10
14
 
11
- ### 使用默认配置
15
+ ## Quick Start
12
16
 
13
- `commitlint.config.ts`
17
+ Create `commitlint.config.ts` in the repository root:
14
18
 
15
19
  ```ts
16
20
  import { icebreaker } from '@icebreakers/commitlint-config'
@@ -18,50 +22,73 @@ import { icebreaker } from '@icebreakers/commitlint-config'
18
22
  export default icebreaker()
19
23
  ```
20
24
 
21
- ### 自定义选项
25
+ Add a script or Husky hook to run commitlint:
26
+
27
+ ```bash
28
+ pnpm commitlint --from=HEAD~1
29
+ ```
30
+
31
+ When you need explicit naming, use `createIcebreakerCommitlintConfig(options)`—it returns the same value as `icebreaker`.
32
+
33
+ ## Customising Rules
34
+
35
+ The factory accepts targeted option groups so you can extend the default convention without re-implementing every rule:
22
36
 
23
37
  ```ts
24
- import { icebreaker, RuleConfigSeverity } from '@icebreakers/commitlint-config'
38
+ import {
39
+ icebreaker,
40
+ RuleConfigSeverity,
41
+ } from '@icebreakers/commitlint-config'
25
42
 
26
43
  export default icebreaker({
27
44
  types: {
28
45
  definitions: [
29
- {
30
- value: 'deps',
31
- title: 'Dependencies',
32
- description: '依赖升级',
33
- emoji: '📦',
34
- },
46
+ { value: 'docs', title: 'Docs', description: '文档更新', emoji: '📝' },
47
+ { value: 'deps', title: 'Dependencies', description: 'Bump deps' },
35
48
  ],
49
+ add: ['perf'],
36
50
  },
37
51
  scopes: {
38
- values: ['core', 'docs'],
52
+ values: ['core', 'lint', 'website'],
39
53
  required: true,
54
+ case: ['kebab-case', 'lower-case'],
40
55
  },
41
56
  subject: {
42
57
  forbidden: ['sentence-case', 'start-case'],
43
58
  caseSeverity: RuleConfigSeverity.Warning,
59
+ fullStop: false,
44
60
  },
45
61
  header: {
46
62
  maxLength: 100,
47
63
  },
64
+ extends: ['@acme/commitlint-config'],
48
65
  })
49
66
  ```
50
67
 
51
- ## 导出的工具
68
+ - `types` – add new entries, merge prompt metadata, or tighten the `type-enum` rule.
69
+ - `scopes` – whitelist scope values, enforce casing, or require scopes.
70
+ - `subject` – forbid casing styles, configure punctuation, and allow empty subjects for merge commits when needed.
71
+ - `header` – override maximum length or severity.
72
+ - `extends` / `rules` – append extra commitlint configs or raw rule overrides.
73
+ - `prompt` – merge additional prompt groups for interactive commit tools.
52
74
 
53
- - `icebreaker(options?)`: 推荐使用的工厂函数,合并默认规则与自定义规则。
54
- - `createIcebreakerCommitlintConfig(options?)`: 与 `icebreaker` 等效的底层函数,便于需要显式命名的场景。
55
- - `RuleConfigSeverity`: Enum,用于声明 commitlint 规则的严重级别。
56
- - `CommitTypesOptions`、`CommitScopeOptions`、`CommitSubjectOptions`、`CommitHeaderOptions`: 细粒度配置类型。
57
- - `CommitlintUserConfig`: 对应 commitlint 的最终配置类型。
75
+ All rule severities use `RuleConfigSeverity` from `@commitlint/types`.
58
76
 
59
- ## 测试
77
+ ## Prompt Synchronisation
60
78
 
61
- ```bash
62
- pnpm --filter @icebreakers/commitlint-config test
63
- ```
79
+ The factory keeps commit prompts in sync with any custom type definitions. If you pass a `prompt` block, it deep merges with the conventional preset, so your CLI prompt automatically reflects newly added types or scopes.
80
+
81
+ ## Suggested Workflow
82
+
83
+ 1. Install Husky and configure a `commit-msg` hook:
84
+ ```bash
85
+ pnpm husky add .husky/commit-msg "pnpm commitlint --edit \"$1\""
86
+ ```
87
+ 2. Use `pnpm commit` (Changeset prompt) or your own CLI for guided commits.
88
+ 3. Add `pnpm lint` and `pnpm test` to CI so commits fail fast when rules change.
64
89
 
65
- ## 许可证
90
+ ## Troubleshooting
66
91
 
67
- MIT License。
92
+ - If commitlint cannot find the config file, ensure it is named `commitlint.config.ts` (or `.cjs`) at the repository root.
93
+ - For workspaces that ship custom prompts, pass a `prompt` object instead of re-building the schema by hand.
94
+ - To disable commits in scripts (e.g. release bots), set `COMMITLINT_DISABLED=true` and skip the hook execution.
package/README.zh.md ADDED
@@ -0,0 +1,92 @@
1
+ # @icebreakers/commitlint-config
2
+
3
+ ## 概览
4
+
5
+ `@icebreakers/commitlint-config` 在保留 `@commitlint/config-conventional` 的基础上提供了类型完备的工厂 API,可以按团队需求扩展类型、Scope、Subject 等规则,并自动同步 Commit Prompt 的选项。它非常适合在 Monorepo 中统一 Conventional Commits。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add -D @commitlint/cli @icebreakers/commitlint-config
11
+ ```
12
+
13
+ ## 快速开始
14
+
15
+ 在仓库根目录创建 `commitlint.config.ts`:
16
+
17
+ ```ts
18
+ import { icebreaker } from '@icebreakers/commitlint-config'
19
+
20
+ export default icebreaker()
21
+ ```
22
+
23
+ 在脚本或 Husky 钩子中调用:
24
+
25
+ ```bash
26
+ pnpm commitlint --from=HEAD~1
27
+ ```
28
+
29
+ 如果需要显式函数名,也可以使用 `createIcebreakerCommitlintConfig(options)`,返回值与 `icebreaker` 完全一致。
30
+
31
+ ## 自定义规则
32
+
33
+ 工厂函数按类别接收配置,方便针对性地覆盖默认约束:
34
+
35
+ ```ts
36
+ import {
37
+ icebreaker,
38
+ RuleConfigSeverity,
39
+ } from '@icebreakers/commitlint-config'
40
+
41
+ export default icebreaker({
42
+ types: {
43
+ definitions: [
44
+ { value: 'docs', title: 'Docs', description: '文档更新', emoji: '📝' },
45
+ { value: 'deps', title: 'Dependencies', description: '依赖升级' },
46
+ ],
47
+ add: ['perf'],
48
+ },
49
+ scopes: {
50
+ values: ['core', 'lint', 'website'],
51
+ required: true,
52
+ case: ['kebab-case', 'lower-case'],
53
+ },
54
+ subject: {
55
+ forbidden: ['sentence-case', 'start-case'],
56
+ caseSeverity: RuleConfigSeverity.Warning,
57
+ fullStop: false,
58
+ },
59
+ header: {
60
+ maxLength: 100,
61
+ },
62
+ extends: ['@acme/commitlint-config'],
63
+ })
64
+ ```
65
+
66
+ - `types`:新增类型、补充 Prompt 元数据或强化 `type-enum` 规则。
67
+ - `scopes`:限定 Scope 值、设置大小写规则或强制 Scope 必填。
68
+ - `subject`:限制 Subject 大小写、控制末尾标点、允许空 Subject。
69
+ - `header`:修改头部长度或告警级别。
70
+ - `extends` / `rules`:叠加额外的 commitlint 配置或自定义规则。
71
+ - `prompt`:在保留原有交互式提示的前提下合并自定义菜单。
72
+
73
+ 所有严重级别均使用 `@commitlint/types` 暴露的 `RuleConfigSeverity`。
74
+
75
+ ## Prompt 同步
76
+
77
+ 工厂函数会将自定义类型合并进 commit Prompt。若传入 `prompt` 字段,会与默认配置深度合并,确保交互式命令自动展示新增的类型、Scope 或描述信息。
78
+
79
+ ## 推荐流程
80
+
81
+ 1. 安装 Husky 并配置 `commit-msg` 钩子:
82
+ ```bash
83
+ pnpm husky add .husky/commit-msg "pnpm commitlint --edit \"$1\""
84
+ ```
85
+ 2. 通过 `pnpm commit`(Changeset)或自定义的 CLI 引导书写 Commit。
86
+ 3. 在 CI 中运行 `pnpm lint`、`pnpm test`,并在发布脚本中保留 commitlint 校验。
87
+
88
+ ## 常见问题
89
+
90
+ - commitlint 找不到配置时,请确认文件名为 `commitlint.config.ts`(或 `.cjs`),且位于仓库根目录。
91
+ - 如需扩展交互式提示,直接传入 `prompt` 即可,无需手动拼装 Schema。
92
+ - 若需在某些脚本中临时关闭校验,可在环境变量中设置 `COMMITLINT_DISABLED=true` 并跳过钩子。
package/dist/index.cjs CHANGED
@@ -1,6 +1,9 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/builders.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
2
  var _configconventional = require('@commitlint/config-conventional'); var _configconventional2 = _interopRequireDefault(_configconventional);
3
3
 
4
+ // src/builders.ts
5
+
6
+
4
7
  // src/types.ts
5
8
  var _types = require('@commitlint/types');
6
9
 
@@ -164,7 +167,7 @@ function buildHeaderRules(options) {
164
167
  }
165
168
 
166
169
  // src/constants.ts
167
- var DEFAULT_EXTENDS = ["@commitlint/config-conventional"];
170
+ var DEFAULT_EXTENDS = [];
168
171
  var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
169
172
 
170
173
  // src/prompt.ts
@@ -193,9 +196,13 @@ function createIcebreakerCommitlintConfig(options = {}) {
193
196
  const { types, scopes, subject, header } = options;
194
197
  const extendsList = mergeUnique([
195
198
  ...DEFAULT_EXTENDS,
196
- ...mergeUnique(_nullishCoalesce(options.extends, () => ( [])))
199
+ ...asArray(
200
+ _configconventional2.default.extends
201
+ ),
202
+ ...asArray(options.extends)
197
203
  ]);
198
204
  const rules = {
205
+ ..._nullishCoalesce(_configconventional2.default.rules, () => ( {})),
199
206
  ...buildScopeRules(scopes),
200
207
  ...buildSubjectRules(subject),
201
208
  ...buildHeaderRules(header)
@@ -208,10 +215,11 @@ function createIcebreakerCommitlintConfig(options = {}) {
208
215
  ...rules,
209
216
  ..._nullishCoalesce(options.rules, () => ( {}))
210
217
  };
211
- const prompt = mergePrompts(typesConfig.prompt, options.prompt);
218
+ const promptBase = _nullishCoalesce(typesConfig.prompt, () => ( _configconventional2.default.prompt));
219
+ const prompt = mergePrompts(promptBase, options.prompt);
212
220
  return {
213
- extends: extendsList,
214
- parserPreset: DEFAULT_PARSER_PRESET,
221
+ ...extendsList.length > 0 ? { extends: extendsList } : {},
222
+ parserPreset: _nullishCoalesce(_configconventional2.default.parserPreset, () => ( DEFAULT_PARSER_PRESET)),
215
223
  ...Object.keys(mergedRules).length > 0 ? { rules: mergedRules } : {},
216
224
  ...prompt ? { prompt } : {}
217
225
  };
package/dist/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ // src/index.ts
2
+ import conventionalConfig2 from "@commitlint/config-conventional";
3
+
1
4
  // src/builders.ts
2
5
  import conventionalConfig from "@commitlint/config-conventional";
3
6
 
@@ -164,7 +167,7 @@ function buildHeaderRules(options) {
164
167
  }
165
168
 
166
169
  // src/constants.ts
167
- var DEFAULT_EXTENDS = ["@commitlint/config-conventional"];
170
+ var DEFAULT_EXTENDS = [];
168
171
  var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
169
172
 
170
173
  // src/prompt.ts
@@ -193,9 +196,13 @@ function createIcebreakerCommitlintConfig(options = {}) {
193
196
  const { types, scopes, subject, header } = options;
194
197
  const extendsList = mergeUnique([
195
198
  ...DEFAULT_EXTENDS,
196
- ...mergeUnique(options.extends ?? [])
199
+ ...asArray(
200
+ conventionalConfig2.extends
201
+ ),
202
+ ...asArray(options.extends)
197
203
  ]);
198
204
  const rules = {
205
+ ...conventionalConfig2.rules ?? {},
199
206
  ...buildScopeRules(scopes),
200
207
  ...buildSubjectRules(subject),
201
208
  ...buildHeaderRules(header)
@@ -208,10 +215,11 @@ function createIcebreakerCommitlintConfig(options = {}) {
208
215
  ...rules,
209
216
  ...options.rules ?? {}
210
217
  };
211
- const prompt = mergePrompts(typesConfig.prompt, options.prompt);
218
+ const promptBase = typesConfig.prompt ?? conventionalConfig2.prompt;
219
+ const prompt = mergePrompts(promptBase, options.prompt);
212
220
  return {
213
- extends: extendsList,
214
- parserPreset: DEFAULT_PARSER_PRESET,
221
+ ...extendsList.length > 0 ? { extends: extendsList } : {},
222
+ parserPreset: conventionalConfig2.parserPreset ?? DEFAULT_PARSER_PRESET,
215
223
  ...Object.keys(mergedRules).length > 0 ? { rules: mergedRules } : {},
216
224
  ...prompt ? { prompt } : {}
217
225
  };
package/package.json CHANGED
@@ -1,19 +1,23 @@
1
1
  {
2
2
  "name": "@icebreakers/commitlint-config",
3
3
  "type": "module",
4
- "version": "1.2.0",
5
- "description": "icebreaker's commitlint config",
4
+ "version": "1.2.2",
5
+ "description": "Commitlint preset from Icebreaker's dev-configs",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/sonofmagic/eslint-config.git",
10
+ "url": "git+https://github.com/sonofmagic/dev-configs.git",
11
11
  "directory": "packages/commitlint"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/sonofmagic/eslint-config/issues"
14
+ "url": "https://github.com/sonofmagic/dev-configs/issues"
15
15
  },
16
- "keywords": [],
16
+ "keywords": [
17
+ "commitlint",
18
+ "dev-configs",
19
+ "icebreakers"
20
+ ],
17
21
  "sideEffects": false,
18
22
  "exports": {
19
23
  ".": {