@icebreakers/commitlint-config 1.1.1 → 1.2.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/README.md +67 -0
- package/dist/index.cjs +32 -9
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +32 -9
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @icebreakers/commitlint-config
|
|
2
|
+
|
|
3
|
+
`@icebreakers/commitlint-config` 是一个基于 `@commitlint/config-conventional` 的可配置 preset。我们在保留社区标准的基础上,提供了一套函数式 API,方便团队按需扩展类型、Scope、Subject 等规则,并同步更新 commit prompt 元数据。
|
|
4
|
+
|
|
5
|
+
## 快速开始
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @icebreakers/commitlint-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### 使用默认配置
|
|
12
|
+
|
|
13
|
+
`commitlint.config.ts`
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { icebreaker } from '@icebreakers/commitlint-config'
|
|
17
|
+
|
|
18
|
+
export default icebreaker()
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 自定义选项
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { icebreaker, RuleConfigSeverity } from '@icebreakers/commitlint-config'
|
|
25
|
+
|
|
26
|
+
export default icebreaker({
|
|
27
|
+
types: {
|
|
28
|
+
definitions: [
|
|
29
|
+
{
|
|
30
|
+
value: 'deps',
|
|
31
|
+
title: 'Dependencies',
|
|
32
|
+
description: '依赖升级',
|
|
33
|
+
emoji: '📦',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
scopes: {
|
|
38
|
+
values: ['core', 'docs'],
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
subject: {
|
|
42
|
+
forbidden: ['sentence-case', 'start-case'],
|
|
43
|
+
caseSeverity: RuleConfigSeverity.Warning,
|
|
44
|
+
},
|
|
45
|
+
header: {
|
|
46
|
+
maxLength: 100,
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 导出的工具
|
|
52
|
+
|
|
53
|
+
- `icebreaker(options?)`: 推荐使用的工厂函数,合并默认规则与自定义规则。
|
|
54
|
+
- `createIcebreakerCommitlintConfig(options?)`: 与 `icebreaker` 等效的底层函数,便于需要显式命名的场景。
|
|
55
|
+
- `RuleConfigSeverity`: Enum,用于声明 commitlint 规则的严重级别。
|
|
56
|
+
- `CommitTypesOptions`、`CommitScopeOptions`、`CommitSubjectOptions`、`CommitHeaderOptions`: 细粒度配置类型。
|
|
57
|
+
- `CommitlintUserConfig`: 对应 commitlint 的最终配置类型。
|
|
58
|
+
|
|
59
|
+
## 测试
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm --filter @icebreakers/commitlint-config test
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 许可证
|
|
66
|
+
|
|
67
|
+
MIT License。
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
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
|
+
|
|
4
|
+
// src/builders.ts
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// src/types.ts
|
|
3
8
|
var _types = require('@commitlint/types');
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
|
|
10
|
+
// src/utils.ts
|
|
6
11
|
function asArray(value) {
|
|
7
12
|
if (value === void 0) {
|
|
8
13
|
return [];
|
|
@@ -23,6 +28,8 @@ function mergeUnique(values) {
|
|
|
23
28
|
}
|
|
24
29
|
return result;
|
|
25
30
|
}
|
|
31
|
+
|
|
32
|
+
// src/builders.ts
|
|
26
33
|
function resolveBaseTypeRule() {
|
|
27
34
|
const rule = _optionalChain([_configconventional2.default, 'access', _ => _.rules, 'optionalAccess', _2 => _2["type-enum"]]);
|
|
28
35
|
if (Array.isArray(rule)) {
|
|
@@ -158,6 +165,12 @@ function buildHeaderRules(options) {
|
|
|
158
165
|
}
|
|
159
166
|
return rules;
|
|
160
167
|
}
|
|
168
|
+
|
|
169
|
+
// src/constants.ts
|
|
170
|
+
var DEFAULT_EXTENDS = [];
|
|
171
|
+
var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
|
|
172
|
+
|
|
173
|
+
// src/prompt.ts
|
|
161
174
|
function mergePrompts(base, override) {
|
|
162
175
|
if (!base && !override) {
|
|
163
176
|
return void 0;
|
|
@@ -177,13 +190,19 @@ function mergePrompts(base, override) {
|
|
|
177
190
|
}
|
|
178
191
|
};
|
|
179
192
|
}
|
|
193
|
+
|
|
194
|
+
// src/index.ts
|
|
180
195
|
function createIcebreakerCommitlintConfig(options = {}) {
|
|
181
196
|
const { types, scopes, subject, header } = options;
|
|
182
197
|
const extendsList = mergeUnique([
|
|
183
198
|
...DEFAULT_EXTENDS,
|
|
184
|
-
...
|
|
199
|
+
...asArray(
|
|
200
|
+
_configconventional2.default.extends
|
|
201
|
+
),
|
|
202
|
+
...asArray(options.extends)
|
|
185
203
|
]);
|
|
186
204
|
const rules = {
|
|
205
|
+
..._nullishCoalesce(_configconventional2.default.rules, () => ( {})),
|
|
187
206
|
...buildScopeRules(scopes),
|
|
188
207
|
...buildSubjectRules(subject),
|
|
189
208
|
...buildHeaderRules(header)
|
|
@@ -196,16 +215,20 @@ function createIcebreakerCommitlintConfig(options = {}) {
|
|
|
196
215
|
...rules,
|
|
197
216
|
..._nullishCoalesce(options.rules, () => ( {}))
|
|
198
217
|
};
|
|
199
|
-
const
|
|
200
|
-
const prompt = mergePrompts(
|
|
218
|
+
const promptBase = _nullishCoalesce(typesConfig.prompt, () => ( _configconventional2.default.prompt));
|
|
219
|
+
const prompt = mergePrompts(promptBase, options.prompt);
|
|
201
220
|
return {
|
|
202
|
-
extends: extendsList,
|
|
203
|
-
parserPreset: DEFAULT_PARSER_PRESET,
|
|
204
|
-
...
|
|
221
|
+
...extendsList.length > 0 ? { extends: extendsList } : {},
|
|
222
|
+
parserPreset: _nullishCoalesce(_configconventional2.default.parserPreset, () => ( DEFAULT_PARSER_PRESET)),
|
|
223
|
+
...Object.keys(mergedRules).length > 0 ? { rules: mergedRules } : {},
|
|
205
224
|
...prompt ? { prompt } : {}
|
|
206
225
|
};
|
|
207
226
|
}
|
|
227
|
+
function icebreaker(options) {
|
|
228
|
+
return createIcebreakerCommitlintConfig(options);
|
|
229
|
+
}
|
|
230
|
+
|
|
208
231
|
|
|
209
232
|
|
|
210
233
|
|
|
211
|
-
exports.RuleConfigSeverity = _types.RuleConfigSeverity; exports.createIcebreakerCommitlintConfig = createIcebreakerCommitlintConfig;
|
|
234
|
+
exports.RuleConfigSeverity = _types.RuleConfigSeverity; exports.createIcebreakerCommitlintConfig = createIcebreakerCommitlintConfig; exports.icebreaker = icebreaker;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuleConfigCondition, RuleConfigSeverity, TargetCaseType,
|
|
1
|
+
import { RulesConfig, RuleConfigCondition, RuleConfigSeverity, TargetCaseType, UserPromptConfig, UserConfig } from '@commitlint/types';
|
|
2
2
|
export { UserConfig as CommitlintUserConfig, RuleConfigSeverity } from '@commitlint/types';
|
|
3
3
|
|
|
4
4
|
interface CommitTypeDefinition {
|
|
@@ -43,6 +43,8 @@ interface IcebreakerCommitlintOptions {
|
|
|
43
43
|
header?: CommitHeaderOptions;
|
|
44
44
|
prompt?: UserPromptConfig;
|
|
45
45
|
}
|
|
46
|
+
|
|
46
47
|
declare function createIcebreakerCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
|
|
48
|
+
declare function icebreaker(options?: IcebreakerCommitlintOptions): UserConfig;
|
|
47
49
|
|
|
48
|
-
export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig };
|
|
50
|
+
export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig, icebreaker };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuleConfigCondition, RuleConfigSeverity, TargetCaseType,
|
|
1
|
+
import { RulesConfig, RuleConfigCondition, RuleConfigSeverity, TargetCaseType, UserPromptConfig, UserConfig } from '@commitlint/types';
|
|
2
2
|
export { UserConfig as CommitlintUserConfig, RuleConfigSeverity } from '@commitlint/types';
|
|
3
3
|
|
|
4
4
|
interface CommitTypeDefinition {
|
|
@@ -43,6 +43,8 @@ interface IcebreakerCommitlintOptions {
|
|
|
43
43
|
header?: CommitHeaderOptions;
|
|
44
44
|
prompt?: UserPromptConfig;
|
|
45
45
|
}
|
|
46
|
+
|
|
46
47
|
declare function createIcebreakerCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
|
|
48
|
+
declare function icebreaker(options?: IcebreakerCommitlintOptions): UserConfig;
|
|
47
49
|
|
|
48
|
-
export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig };
|
|
50
|
+
export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig, icebreaker };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import conventionalConfig2 from "@commitlint/config-conventional";
|
|
3
|
+
|
|
4
|
+
// src/builders.ts
|
|
2
5
|
import conventionalConfig from "@commitlint/config-conventional";
|
|
6
|
+
|
|
7
|
+
// src/types.ts
|
|
3
8
|
import { RuleConfigSeverity } from "@commitlint/types";
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
|
|
10
|
+
// src/utils.ts
|
|
6
11
|
function asArray(value) {
|
|
7
12
|
if (value === void 0) {
|
|
8
13
|
return [];
|
|
@@ -23,6 +28,8 @@ function mergeUnique(values) {
|
|
|
23
28
|
}
|
|
24
29
|
return result;
|
|
25
30
|
}
|
|
31
|
+
|
|
32
|
+
// src/builders.ts
|
|
26
33
|
function resolveBaseTypeRule() {
|
|
27
34
|
const rule = conventionalConfig.rules?.["type-enum"];
|
|
28
35
|
if (Array.isArray(rule)) {
|
|
@@ -158,6 +165,12 @@ function buildHeaderRules(options) {
|
|
|
158
165
|
}
|
|
159
166
|
return rules;
|
|
160
167
|
}
|
|
168
|
+
|
|
169
|
+
// src/constants.ts
|
|
170
|
+
var DEFAULT_EXTENDS = [];
|
|
171
|
+
var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
|
|
172
|
+
|
|
173
|
+
// src/prompt.ts
|
|
161
174
|
function mergePrompts(base, override) {
|
|
162
175
|
if (!base && !override) {
|
|
163
176
|
return void 0;
|
|
@@ -177,13 +190,19 @@ function mergePrompts(base, override) {
|
|
|
177
190
|
}
|
|
178
191
|
};
|
|
179
192
|
}
|
|
193
|
+
|
|
194
|
+
// src/index.ts
|
|
180
195
|
function createIcebreakerCommitlintConfig(options = {}) {
|
|
181
196
|
const { types, scopes, subject, header } = options;
|
|
182
197
|
const extendsList = mergeUnique([
|
|
183
198
|
...DEFAULT_EXTENDS,
|
|
184
|
-
...
|
|
199
|
+
...asArray(
|
|
200
|
+
conventionalConfig2.extends
|
|
201
|
+
),
|
|
202
|
+
...asArray(options.extends)
|
|
185
203
|
]);
|
|
186
204
|
const rules = {
|
|
205
|
+
...conventionalConfig2.rules ?? {},
|
|
187
206
|
...buildScopeRules(scopes),
|
|
188
207
|
...buildSubjectRules(subject),
|
|
189
208
|
...buildHeaderRules(header)
|
|
@@ -196,16 +215,20 @@ function createIcebreakerCommitlintConfig(options = {}) {
|
|
|
196
215
|
...rules,
|
|
197
216
|
...options.rules ?? {}
|
|
198
217
|
};
|
|
199
|
-
const
|
|
200
|
-
const prompt = mergePrompts(
|
|
218
|
+
const promptBase = typesConfig.prompt ?? conventionalConfig2.prompt;
|
|
219
|
+
const prompt = mergePrompts(promptBase, options.prompt);
|
|
201
220
|
return {
|
|
202
|
-
extends: extendsList,
|
|
203
|
-
parserPreset: DEFAULT_PARSER_PRESET,
|
|
204
|
-
...
|
|
221
|
+
...extendsList.length > 0 ? { extends: extendsList } : {},
|
|
222
|
+
parserPreset: conventionalConfig2.parserPreset ?? DEFAULT_PARSER_PRESET,
|
|
223
|
+
...Object.keys(mergedRules).length > 0 ? { rules: mergedRules } : {},
|
|
205
224
|
...prompt ? { prompt } : {}
|
|
206
225
|
};
|
|
207
226
|
}
|
|
227
|
+
function icebreaker(options) {
|
|
228
|
+
return createIcebreakerCommitlintConfig(options);
|
|
229
|
+
}
|
|
208
230
|
export {
|
|
209
231
|
RuleConfigSeverity,
|
|
210
|
-
createIcebreakerCommitlintConfig
|
|
232
|
+
createIcebreakerCommitlintConfig,
|
|
233
|
+
icebreaker
|
|
211
234
|
};
|