@kcconfigs/commitlint 0.0.1 → 0.1.0-beta.0
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/CHANGELOG.md +35 -0
- package/dist/index.cjs +216 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +210 -0
- package/dist/index.js.map +1 -0
- package/dist/lib-26NWB_Cl.cjs +142 -0
- package/dist/lib-26NWB_Cl.cjs.map +1 -0
- package/dist/lib-CzUh7oEE.cjs +31 -0
- package/dist/lib-CzUh7oEE.cjs.map +1 -0
- package/dist/lib-D5qzG1z4.js +25 -0
- package/dist/lib-D5qzG1z4.js.map +1 -0
- package/dist/lib-DPex9ONF.js +142 -0
- package/dist/lib-DPex9ONF.js.map +1 -0
- package/package.json +58 -1
- package/src/apis/projects.test.ts +344 -0
- package/src/apis/projects.ts +52 -0
- package/src/apis/scopes.test.ts +126 -0
- package/src/apis/scopes.ts +56 -0
- package/src/apis/types.test.ts +88 -0
- package/src/apis/types.ts +103 -0
- package/src/index.test.ts +497 -0
- package/src/index.ts +82 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0-beta.0 (2025-12-28)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **kcconfigs/commitlint:** add minimal type mode to only include 4 types ([181a731](https://github.com/kc-workspace/kcws/commit/181a7316219330d4107b29e29a11b6878fc3e32e))
|
|
9
|
+
* **kcconfigs/commitlint:** add new package for commitlint config ([1ce04a2](https://github.com/kc-workspace/kcws/commit/1ce04a206c2a12b930213e8b9e129e7b2874562a))
|
|
10
|
+
* **kcconfigs/commitlint:** add vitest configuration and implement tests for apis ([6f01788](https://github.com/kc-workspace/kcws/commit/6f0178871ca2d7545b5585890765e48a97a4586b))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Performance Improvements
|
|
14
|
+
|
|
15
|
+
* improve pnpm script and dependencies catalogs ([672ccc2](https://github.com/kc-workspace/kcws/commit/672ccc2bf6a14421bd0582bded85c86c7db70c82))
|
|
16
|
+
* **kcconfigs/commitlint:** remove custom commit type, and use standard instead ([f02c53a](https://github.com/kc-workspace/kcws/commit/f02c53a7a5b757fa70dfbd33010e94d063349ac0))
|
|
17
|
+
* **kcconfigs/commitlint:** use generic global types instead of union ourself ([8082837](https://github.com/kc-workspace/kcws/commit/808283791de3f291a0bac3cbc8c7a948c465e9da))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bugfixes
|
|
21
|
+
|
|
22
|
+
* homepage contains invalid url ([0ee37d6](https://github.com/kc-workspace/kcws/commit/0ee37d641fe5b04fb019099915c8aa3ddfed3be7))
|
|
23
|
+
* **kcconfigs/commitlint:** remove unused dependencies from package.json file ([3d627ee](https://github.com/kc-workspace/kcws/commit/3d627eef7b9d48da3f080a89dc796b23da2d7140))
|
|
24
|
+
* trigger re-release please ([65447a7](https://github.com/kc-workspace/kcws/commit/65447a776ed2f8638f6f35a4d00277d407143114))
|
|
25
|
+
* update all [@kcconfigs](https://github.com/kcconfigs) description so it trigger new deployment with new tag separator ([cf5be8c](https://github.com/kc-workspace/kcws/commit/cf5be8cc02fba8becb7e8f31fd6f3a741c0f0b95))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
* The following workspace dependencies were updated
|
|
31
|
+
* devDependencies
|
|
32
|
+
* @kcconfigs/biome bumped to 0.1.1
|
|
33
|
+
* @kcconfigs/tsconfig bumped to 0.1.0-beta.1
|
|
34
|
+
* @kcconfigs/tsdown bumped to 0.1.0-beta.1
|
|
35
|
+
* @kcconfigs/vitest bumped to 0.1.0-beta.0
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// @generated by tsdown, DO NOT edit it manually
|
|
2
|
+
const require_lib = require('./lib-CzUh7oEE.cjs');
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let node_process = require("node:process");
|
|
6
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
|
+
let _pnpm_workspace_find_packages = require("@pnpm/workspace.find-packages");
|
|
8
|
+
let yaml = require("yaml");
|
|
9
|
+
|
|
10
|
+
//#region src/apis/projects.ts
|
|
11
|
+
const findPackages = async (cwd, patterns, includeRoot) => {
|
|
12
|
+
return (await (0, _pnpm_workspace_find_packages.findWorkspacePackagesNoCheck)(cwd, { patterns: patterns ?? ["**"] })).filter((pkg) => (includeRoot ?? false) || pkg.rootDir !== cwd).map((pkg) => pkg.manifest.name ?? (0, node_path.basename)(pkg.rootDirRealPath)).map((name) => name.startsWith("@") ? name.slice(1) : name);
|
|
13
|
+
};
|
|
14
|
+
const findPnpmPackages = async (includeRoot) => {
|
|
15
|
+
const cwd = (0, node_process.cwd)();
|
|
16
|
+
const workspace = (0, yaml.parse)(await (0, node_fs_promises.readFile)((0, node_path.join)(cwd, "pnpm-workspace.yaml"), { encoding: "utf8" }));
|
|
17
|
+
return findPackages(cwd, workspace === null || workspace === void 0 ? void 0 : workspace.packages, includeRoot);
|
|
18
|
+
};
|
|
19
|
+
const findNpmPackages = async (includeRoot) => {
|
|
20
|
+
const cwd = (0, node_process.cwd)();
|
|
21
|
+
const { workspaces } = JSON.parse(await (0, node_fs_promises.readFile)((0, node_path.join)(cwd, "package.json"), { encoding: "utf8" }));
|
|
22
|
+
return findPackages(cwd, workspaces, includeRoot);
|
|
23
|
+
};
|
|
24
|
+
const findBunPackages = async (includeRoot) => {
|
|
25
|
+
return findNpmPackages(includeRoot);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/apis/scopes.ts
|
|
30
|
+
/**
|
|
31
|
+
* Automatically detects and retrieves project scopes based on the package manager in use.
|
|
32
|
+
*
|
|
33
|
+
* Determines the package manager by checking for workspace configuration files:
|
|
34
|
+
* - pnpm: Checks for pnpm-workspace.yaml
|
|
35
|
+
* - bun: Checks for bun.lock or bun.lockb
|
|
36
|
+
* - npm: Falls back to npm package detection
|
|
37
|
+
*
|
|
38
|
+
* @param includeRoot - Whether to include the root package in the results
|
|
39
|
+
* @returns Array of detected project scope names
|
|
40
|
+
*/
|
|
41
|
+
const getAutoScope = (includeRoot) => {
|
|
42
|
+
const cwd = (0, node_process.cwd)();
|
|
43
|
+
if ((0, node_fs.existsSync)((0, node_path.join)(cwd, "pnpm-workspace.yaml"))) return findPnpmPackages(includeRoot);
|
|
44
|
+
else if ((0, node_fs.existsSync)((0, node_path.join)(cwd, "bun.lock")) || (0, node_fs.existsSync)((0, node_path.join)(cwd, "bun.lockb"))) return findBunPackages(includeRoot);
|
|
45
|
+
return findNpmPackages(includeRoot);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves a merged list of commit scopes based on automatic detection and user input.
|
|
49
|
+
*
|
|
50
|
+
* Combines user-provided scopes with automatically detected project scopes.
|
|
51
|
+
* If no scopes are provided, returns a default set of common scope categories.
|
|
52
|
+
*
|
|
53
|
+
* @param auto - Whether to automatically detect scopes from workspace packages
|
|
54
|
+
* @param scopes - Optional user-provided scopes to include
|
|
55
|
+
* @returns Merged array of all available scopes
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
const getScopes = async (auto, scopes) => {
|
|
59
|
+
const _scopes = [];
|
|
60
|
+
if (scopes) _scopes.push(...scopes);
|
|
61
|
+
if (auto) _scopes.push(...await getAutoScope(false));
|
|
62
|
+
if (_scopes.length === 0) _scopes.push("core", "config", "script", "deps", "deps-dev");
|
|
63
|
+
return _scopes;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/apis/types.ts
|
|
68
|
+
const STANDARD_TYPES = {
|
|
69
|
+
feat: {
|
|
70
|
+
description: "A new feature",
|
|
71
|
+
title: "Features",
|
|
72
|
+
emoji: "✨"
|
|
73
|
+
},
|
|
74
|
+
perf: {
|
|
75
|
+
description: "A code change that improves performance",
|
|
76
|
+
title: "Performance Improvements",
|
|
77
|
+
emoji: "🚀"
|
|
78
|
+
},
|
|
79
|
+
fix: {
|
|
80
|
+
description: "A bug fix",
|
|
81
|
+
title: "Bugfixes",
|
|
82
|
+
emoji: "🐛"
|
|
83
|
+
},
|
|
84
|
+
docs: {
|
|
85
|
+
description: "Documentation only changes",
|
|
86
|
+
title: "Documentation",
|
|
87
|
+
emoji: "📚"
|
|
88
|
+
},
|
|
89
|
+
test: {
|
|
90
|
+
description: "Adding missing tests or correcting existing tests",
|
|
91
|
+
title: "Tests",
|
|
92
|
+
emoji: "🚨"
|
|
93
|
+
},
|
|
94
|
+
style: {
|
|
95
|
+
description: "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
|
|
96
|
+
title: "Styles",
|
|
97
|
+
emoji: "💎"
|
|
98
|
+
},
|
|
99
|
+
build: {
|
|
100
|
+
description: "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)",
|
|
101
|
+
title: "Builds",
|
|
102
|
+
emoji: "🛠"
|
|
103
|
+
},
|
|
104
|
+
refactor: {
|
|
105
|
+
description: "A code change that neither fixes a bug nor adds a feature",
|
|
106
|
+
title: "Code Refactoring",
|
|
107
|
+
emoji: "📦"
|
|
108
|
+
},
|
|
109
|
+
ci: {
|
|
110
|
+
description: "Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)",
|
|
111
|
+
title: "Continuous Integrations",
|
|
112
|
+
emoji: "⚙️"
|
|
113
|
+
},
|
|
114
|
+
chore: {
|
|
115
|
+
description: "Other changes that don't modify src or test files",
|
|
116
|
+
title: "Miscellaneous Chores",
|
|
117
|
+
emoji: "♻️"
|
|
118
|
+
},
|
|
119
|
+
revert: {
|
|
120
|
+
description: "Reverts a previous commit",
|
|
121
|
+
title: "Reverts",
|
|
122
|
+
emoji: "🗑"
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Retrieves commit types based on the specified mode.
|
|
127
|
+
*
|
|
128
|
+
* Returns a predefined list of commit types for standard or kc modes,
|
|
129
|
+
* or a custom list if an array or object is provided.
|
|
130
|
+
*
|
|
131
|
+
* @param mode - The commit type mode: "standard", "kc", or a custom object
|
|
132
|
+
* @returns Map of type object
|
|
133
|
+
*/
|
|
134
|
+
const getTypes = (mode) => {
|
|
135
|
+
if (Array.isArray(mode)) return mode.reduce((acc, type) => {
|
|
136
|
+
acc[type] = {};
|
|
137
|
+
return acc;
|
|
138
|
+
}, {});
|
|
139
|
+
if (typeof mode !== "string") return mode;
|
|
140
|
+
switch (mode) {
|
|
141
|
+
case "standard": return STANDARD_TYPES;
|
|
142
|
+
case "minimal": return {
|
|
143
|
+
feat: STANDARD_TYPES.feat,
|
|
144
|
+
perf: STANDARD_TYPES.perf,
|
|
145
|
+
fix: STANDARD_TYPES.fix,
|
|
146
|
+
chore: STANDARD_TYPES.chore
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/index.ts
|
|
153
|
+
/**
|
|
154
|
+
* Defines a commitlint configuration with automatic workspace scope detection and customizable commit types.
|
|
155
|
+
*
|
|
156
|
+
* @param params - Configuration options
|
|
157
|
+
* @returns A commitlint configuration object
|
|
158
|
+
*/
|
|
159
|
+
const defineConfig = async (params) => {
|
|
160
|
+
const { default: { parserPreset, prompt: { questions: { type, scope, ...questions }, ...prompt }, rules } } = await Promise.resolve().then(() => require("./lib-26NWB_Cl.cjs"));
|
|
161
|
+
const types = getTypes((params === null || params === void 0 ? void 0 : params.types) ?? "standard");
|
|
162
|
+
const scopes = await getScopes((params === null || params === void 0 ? void 0 : params.autoScopes) ?? true, params === null || params === void 0 ? void 0 : params.scopes);
|
|
163
|
+
return {
|
|
164
|
+
helpUrl: "use 'pnpm commit' to create commit instead",
|
|
165
|
+
parserPreset,
|
|
166
|
+
rules: {
|
|
167
|
+
...rules,
|
|
168
|
+
"type-enum": [
|
|
169
|
+
require_lib.RuleConfigSeverity.Error,
|
|
170
|
+
"always",
|
|
171
|
+
Object.keys(types)
|
|
172
|
+
],
|
|
173
|
+
"scope-enum": () => [
|
|
174
|
+
require_lib.RuleConfigSeverity.Error,
|
|
175
|
+
"always",
|
|
176
|
+
scopes
|
|
177
|
+
],
|
|
178
|
+
"subject-max-length": [
|
|
179
|
+
require_lib.RuleConfigSeverity.Warning,
|
|
180
|
+
"always",
|
|
181
|
+
80
|
|
182
|
+
],
|
|
183
|
+
"body-max-line-length": [
|
|
184
|
+
require_lib.RuleConfigSeverity.Warning,
|
|
185
|
+
"always",
|
|
186
|
+
300
|
|
187
|
+
]
|
|
188
|
+
},
|
|
189
|
+
prompt: {
|
|
190
|
+
...prompt,
|
|
191
|
+
questions: {
|
|
192
|
+
...questions,
|
|
193
|
+
type: {
|
|
194
|
+
...type,
|
|
195
|
+
enum: types
|
|
196
|
+
},
|
|
197
|
+
scope: {
|
|
198
|
+
...scope,
|
|
199
|
+
enum: Object.fromEntries(scopes.map((s) => [s, {}]))
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
settings: { enableMultipleScopes: false }
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
//#endregion
|
|
208
|
+
Object.defineProperty(exports, 'Severity', {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
get: function () {
|
|
211
|
+
return require_lib.RuleConfigSeverity;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
exports.defineConfig = defineConfig;
|
|
215
|
+
// Generated by @kcconfigs/tsdown
|
|
216
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["_scopes: string[]","Severity"],"sources":["../src/apis/projects.ts","../src/apis/scopes.ts","../src/apis/types.ts","../src/index.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport { cwd as wd } from \"node:process\";\nimport { findWorkspacePackagesNoCheck } from \"@pnpm/workspace.find-packages\";\nimport { parse } from \"yaml\";\n\nconst findPackages = async (\n\tcwd: string,\n\tpatterns: WithUndefined<string[]>,\n\tincludeRoot: WithUndefined<boolean>,\n) => {\n\tconst packages = await findWorkspacePackagesNoCheck(cwd, {\n\t\tpatterns: patterns ?? [\"**\"],\n\t});\n\n\treturn packages\n\t\t.filter((pkg) => (includeRoot ?? false) || pkg.rootDir !== cwd)\n\t\t.map((pkg) => pkg.manifest.name ?? basename(pkg.rootDirRealPath))\n\t\t.map((name) => (name.startsWith(\"@\") ? name.slice(1) : name));\n};\n\nexport const findPnpmPackages = async (\n\tincludeRoot?: boolean,\n): Promise<string[]> => {\n\tconst cwd = wd();\n\n\tconst pnpmWorkspace = await readFile(join(cwd, \"pnpm-workspace.yaml\"), {\n\t\tencoding: \"utf8\",\n\t});\n\n\tconst workspace = parse(pnpmWorkspace);\n\treturn findPackages(cwd, workspace?.packages, includeRoot);\n};\n\nexport const findNpmPackages = async (\n\tincludeRoot?: boolean,\n): Promise<string[]> => {\n\tconst cwd = wd();\n\n\tconst { workspaces } = JSON.parse(\n\t\tawait readFile(join(cwd, \"package.json\"), {\n\t\t\tencoding: \"utf8\",\n\t\t}),\n\t);\n\treturn findPackages(cwd, workspaces, includeRoot);\n};\n\nexport const findBunPackages = async (\n\tincludeRoot?: boolean,\n): Promise<string[]> => {\n\treturn findNpmPackages(includeRoot);\n};\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { cwd as wd } from \"node:process\";\nimport { findBunPackages, findNpmPackages, findPnpmPackages } from \"./projects\";\n\n/**\n * Automatically detects and retrieves project scopes based on the package manager in use.\n *\n * Determines the package manager by checking for workspace configuration files:\n * - pnpm: Checks for pnpm-workspace.yaml\n * - bun: Checks for bun.lock or bun.lockb\n * - npm: Falls back to npm package detection\n *\n * @param includeRoot - Whether to include the root package in the results\n * @returns Array of detected project scope names\n */\nconst getAutoScope = (includeRoot: boolean) => {\n\tconst cwd = wd();\n\n\tif (existsSync(join(cwd, \"pnpm-workspace.yaml\"))) {\n\t\treturn findPnpmPackages(includeRoot);\n\t} else if (\n\t\texistsSync(join(cwd, \"bun.lock\")) ||\n\t\texistsSync(join(cwd, \"bun.lockb\"))\n\t) {\n\t\treturn findBunPackages(includeRoot);\n\t}\n\n\treturn findNpmPackages(includeRoot);\n};\n\n/**\n * Retrieves a merged list of commit scopes based on automatic detection and user input.\n *\n * Combines user-provided scopes with automatically detected project scopes.\n * If no scopes are provided, returns a default set of common scope categories.\n *\n * @param auto - Whether to automatically detect scopes from workspace packages\n * @param scopes - Optional user-provided scopes to include\n * @returns Merged array of all available scopes\n *\n */\nexport const getScopes = async (\n\tauto: boolean,\n\tscopes?: string[],\n): Promise<string[]> => {\n\tconst _scopes: string[] = [];\n\n\tif (scopes) _scopes.push(...scopes);\n\tif (auto) _scopes.push(...(await getAutoScope(false)));\n\n\tif (_scopes.length === 0) {\n\t\t_scopes.push(\"core\", \"config\", \"script\", \"deps\", \"deps-dev\");\n\t}\n\treturn _scopes;\n};\n","export interface TypeEnum {\n\tdescription?: string;\n\ttitle?: string;\n\temoji?: string;\n}\n\nexport type TypeObject = Record<string, TypeEnum>;\n\nexport type TypeMode = \"standard\" | \"minimal\" | string[] | TypeObject;\n\nconst STANDARD_TYPES = {\n\tfeat: {\n\t\tdescription: \"A new feature\",\n\t\ttitle: \"Features\",\n\t\temoji: \"✨\",\n\t},\n\tperf: {\n\t\tdescription: \"A code change that improves performance\",\n\t\ttitle: \"Performance Improvements\",\n\t\temoji: \"🚀\",\n\t},\n\tfix: {\n\t\tdescription: \"A bug fix\",\n\t\ttitle: \"Bugfixes\",\n\t\temoji: \"🐛\",\n\t},\n\tdocs: {\n\t\tdescription: \"Documentation only changes\",\n\t\ttitle: \"Documentation\",\n\t\temoji: \"📚\",\n\t},\n\ttest: {\n\t\tdescription: \"Adding missing tests or correcting existing tests\",\n\t\ttitle: \"Tests\",\n\t\temoji: \"🚨\",\n\t},\n\tstyle: {\n\t\tdescription:\n\t\t\t\"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)\",\n\t\ttitle: \"Styles\",\n\t\temoji: \"💎\",\n\t},\n\tbuild: {\n\t\tdescription:\n\t\t\t\"Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)\",\n\t\ttitle: \"Builds\",\n\t\temoji: \"🛠\",\n\t},\n\trefactor: {\n\t\tdescription: \"A code change that neither fixes a bug nor adds a feature\",\n\t\ttitle: \"Code Refactoring\",\n\t\temoji: \"📦\",\n\t},\n\tci: {\n\t\tdescription:\n\t\t\t\"Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)\",\n\t\ttitle: \"Continuous Integrations\",\n\t\temoji: \"⚙️\",\n\t},\n\tchore: {\n\t\tdescription: \"Other changes that don't modify src or test files\",\n\t\ttitle: \"Miscellaneous Chores\",\n\t\temoji: \"♻️\",\n\t},\n\trevert: {\n\t\tdescription: \"Reverts a previous commit\",\n\t\ttitle: \"Reverts\",\n\t\temoji: \"🗑\",\n\t},\n} satisfies TypeObject;\n\n/**\n * Retrieves commit types based on the specified mode.\n *\n * Returns a predefined list of commit types for standard or kc modes,\n * or a custom list if an array or object is provided.\n *\n * @param mode - The commit type mode: \"standard\", \"kc\", or a custom object\n * @returns Map of type object\n */\nexport const getTypes = (mode: TypeMode): TypeObject => {\n\tif (Array.isArray(mode)) {\n\t\treturn mode.reduce((acc, type) => {\n\t\t\tacc[type] = {};\n\t\t\treturn acc;\n\t\t}, {} as TypeObject);\n\t}\n\tif (typeof mode !== \"string\") {\n\t\treturn mode;\n\t}\n\n\tswitch (mode) {\n\t\tcase \"standard\":\n\t\t\treturn STANDARD_TYPES;\n\t\tcase \"minimal\":\n\t\t\treturn {\n\t\t\t\tfeat: STANDARD_TYPES.feat,\n\t\t\t\tperf: STANDARD_TYPES.perf,\n\t\t\t\tfix: STANDARD_TYPES.fix,\n\t\t\t\tchore: STANDARD_TYPES.chore,\n\t\t\t};\n\t}\n};\n","import {\n\tRuleConfigSeverity as Severity,\n\ttype UserConfig,\n} from \"@commitlint/types\";\n\nimport { getScopes } from \"./apis/scopes\";\nimport { getTypes, type TypeMode } from \"./apis/types\";\n\nexport interface DefineConfigParams {\n\t/**\n\t * Commit types configuration\n\t * - `\"standard\"`: Use standard conventional commit types\n\t * - `string[]`: Use custom types\n\t * @default \"standard\"\n\t */\n\ttypes?: TypeMode;\n\t/**\n\t * Automatically gather scopes from pnpm workspaces\n\t * @default true\n\t */\n\tautoScopes?: boolean;\n\t/**\n\t * Provide additional scopes; or override if `autoScopes` is false\n\t */\n\tscopes?: string[];\n}\n\n/**\n * Defines a commitlint configuration with automatic workspace scope detection and customizable commit types.\n *\n * @param params - Configuration options\n * @returns A commitlint configuration object\n */\nexport const defineConfig = async (\n\tparams?: DefineConfigParams,\n): Promise<UserConfig> => {\n\tconst {\n\t\tdefault: {\n\t\t\tparserPreset,\n\t\t\tprompt: {\n\t\t\t\tquestions: { type, scope, ...questions },\n\t\t\t\t...prompt\n\t\t\t},\n\t\t\trules,\n\t\t},\n\t} = await import(\"@commitlint/config-conventional\");\n\n\tconst types = getTypes(params?.types ?? \"standard\");\n\tconst scopes = await getScopes(params?.autoScopes ?? true, params?.scopes);\n\n\treturn {\n\t\thelpUrl: \"use 'pnpm commit' to create commit instead\",\n\t\tparserPreset,\n\t\trules: {\n\t\t\t...rules,\n\t\t\t\"type-enum\": [Severity.Error, \"always\", Object.keys(types)],\n\t\t\t\"scope-enum\": () => [Severity.Error, \"always\", scopes],\n\t\t\t\"subject-max-length\": [Severity.Warning, \"always\", 80],\n\t\t\t\"body-max-line-length\": [Severity.Warning, \"always\", 300],\n\t\t},\n\t\tprompt: {\n\t\t\t...prompt,\n\t\t\tquestions: {\n\t\t\t\t...questions,\n\t\t\t\ttype: {\n\t\t\t\t\t...type,\n\t\t\t\t\tenum: types,\n\t\t\t\t},\n\t\t\t\tscope: {\n\t\t\t\t\t...scope,\n\t\t\t\t\tenum: Object.fromEntries(scopes.map((s) => [s, {}])),\n\t\t\t\t},\n\t\t\t},\n\t\t\tsettings: {\n\t\t\t\tenableMultipleScopes: false,\n\t\t\t},\n\t\t},\n\t};\n};\n\nexport { Severity };\nexport type { UserConfig };\n"],"mappings":";;;;;;;;;;AAMA,MAAM,eAAe,OACpB,KACA,UACA,gBACI;AAKJ,SAJiB,sEAAmC,KAAK,EACxD,UAAU,YAAY,CAAC,KAAK,EAC5B,CAAC,EAGA,QAAQ,SAAS,eAAe,UAAU,IAAI,YAAY,IAAI,CAC9D,KAAK,QAAQ,IAAI,SAAS,gCAAiB,IAAI,gBAAgB,CAAC,CAChE,KAAK,SAAU,KAAK,WAAW,IAAI,GAAG,KAAK,MAAM,EAAE,GAAG,KAAM;;AAG/D,MAAa,mBAAmB,OAC/B,gBACuB;CACvB,MAAM,6BAAU;CAMhB,MAAM,4BAJgB,yDAAoB,KAAK,sBAAsB,EAAE,EACtE,UAAU,QACV,CAAC,CAEoC;AACtC,QAAO,aAAa,2DAAK,UAAW,UAAU,YAAY;;AAG3D,MAAa,kBAAkB,OAC9B,gBACuB;CACvB,MAAM,6BAAU;CAEhB,MAAM,EAAE,eAAe,KAAK,MAC3B,yDAAoB,KAAK,eAAe,EAAE,EACzC,UAAU,QACV,CAAC,CACF;AACD,QAAO,aAAa,KAAK,YAAY,YAAY;;AAGlD,MAAa,kBAAkB,OAC9B,gBACuB;AACvB,QAAO,gBAAgB,YAAY;;;;;;;;;;;;;;;;AClCpC,MAAM,gBAAgB,gBAAyB;CAC9C,MAAM,6BAAU;AAEhB,iDAAoB,KAAK,sBAAsB,CAAC,CAC/C,QAAO,iBAAiB,YAAY;sDAEpB,KAAK,WAAW,CAAC,gDACjB,KAAK,YAAY,CAAC,CAElC,QAAO,gBAAgB,YAAY;AAGpC,QAAO,gBAAgB,YAAY;;;;;;;;;;;;;AAcpC,MAAa,YAAY,OACxB,MACA,WACuB;CACvB,MAAMA,UAAoB,EAAE;AAE5B,KAAI,OAAQ,SAAQ,KAAK,GAAG,OAAO;AACnC,KAAI,KAAM,SAAQ,KAAK,GAAI,MAAM,aAAa,MAAM,CAAE;AAEtD,KAAI,QAAQ,WAAW,EACtB,SAAQ,KAAK,QAAQ,UAAU,UAAU,QAAQ,WAAW;AAE7D,QAAO;;;;;AC5CR,MAAM,iBAAiB;CACtB,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,KAAK;EACJ,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,OAAO;EACN,aACC;EACD,OAAO;EACP,OAAO;EACP;CACD,OAAO;EACN,aACC;EACD,OAAO;EACP,OAAO;EACP;CACD,UAAU;EACT,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,IAAI;EACH,aACC;EACD,OAAO;EACP,OAAO;EACP;CACD,OAAO;EACN,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,QAAQ;EACP,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD;;;;;;;;;;AAWD,MAAa,YAAY,SAA+B;AACvD,KAAI,MAAM,QAAQ,KAAK,CACtB,QAAO,KAAK,QAAQ,KAAK,SAAS;AACjC,MAAI,QAAQ,EAAE;AACd,SAAO;IACL,EAAE,CAAe;AAErB,KAAI,OAAO,SAAS,SACnB,QAAO;AAGR,SAAQ,MAAR;EACC,KAAK,WACJ,QAAO;EACR,KAAK,UACJ,QAAO;GACN,MAAM,eAAe;GACrB,MAAM,eAAe;GACrB,KAAK,eAAe;GACpB,OAAO,eAAe;GACtB;;;;;;;;;;;;ACnEJ,MAAa,eAAe,OAC3B,WACyB;CACzB,MAAM,EACL,SAAS,EACR,cACA,QAAQ,EACP,WAAW,EAAE,MAAM,OAAO,GAAG,aAC7B,GAAG,UAEJ,YAEE,2CAAM;CAEV,MAAM,QAAQ,0DAAS,OAAQ,UAAS,WAAW;CACnD,MAAM,SAAS,MAAM,2DAAU,OAAQ,eAAc,sDAAM,OAAQ,OAAO;AAE1E,QAAO;EACN,SAAS;EACT;EACA,OAAO;GACN,GAAG;GACH,aAAa;IAACC,+BAAS;IAAO;IAAU,OAAO,KAAK,MAAM;IAAC;GAC3D,oBAAoB;IAACA,+BAAS;IAAO;IAAU;IAAO;GACtD,sBAAsB;IAACA,+BAAS;IAAS;IAAU;IAAG;GACtD,wBAAwB;IAACA,+BAAS;IAAS;IAAU;IAAI;GACzD;EACD,QAAQ;GACP,GAAG;GACH,WAAW;IACV,GAAG;IACH,MAAM;KACL,GAAG;KACH,MAAM;KACN;IACD,OAAO;KACN,GAAG;KACH,MAAM,OAAO,YAAY,OAAO,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;KACpD;IACD;GACD,UAAU,EACT,sBAAsB,OACtB;GACD;EACD"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @generated by tsdown, DO NOT edit it manually
|
|
2
|
+
import { RuleConfigSeverity as Severity, UserConfig } from "@commitlint/types";
|
|
3
|
+
|
|
4
|
+
//#region src/apis/types.d.ts
|
|
5
|
+
interface TypeEnum {
|
|
6
|
+
description?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
emoji?: string;
|
|
9
|
+
}
|
|
10
|
+
type TypeObject = Record<string, TypeEnum>;
|
|
11
|
+
type TypeMode = "standard" | "minimal" | string[] | TypeObject;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/index.d.ts
|
|
14
|
+
interface DefineConfigParams {
|
|
15
|
+
/**
|
|
16
|
+
* Commit types configuration
|
|
17
|
+
* - `"standard"`: Use standard conventional commit types
|
|
18
|
+
* - `string[]`: Use custom types
|
|
19
|
+
* @default "standard"
|
|
20
|
+
*/
|
|
21
|
+
types?: TypeMode;
|
|
22
|
+
/**
|
|
23
|
+
* Automatically gather scopes from pnpm workspaces
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
autoScopes?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Provide additional scopes; or override if `autoScopes` is false
|
|
29
|
+
*/
|
|
30
|
+
scopes?: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Defines a commitlint configuration with automatic workspace scope detection and customizable commit types.
|
|
34
|
+
*
|
|
35
|
+
* @param params - Configuration options
|
|
36
|
+
* @returns A commitlint configuration object
|
|
37
|
+
*/
|
|
38
|
+
declare const defineConfig: (params?: DefineConfigParams) => Promise<UserConfig>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { DefineConfigParams, Severity, type UserConfig, defineConfig };
|
|
41
|
+
// Generated by @kcconfigs/tsdown
|
|
42
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/apis/types.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;UAAiB,QAAA;;;EAAjB,KAAiB,CAAA,EAAA,MAAA;AAMjB;AAEY,KAFA,UAAA,GAAa,MAEkC,CAAA,MAAA,EAFnB,QAEmB,CAAA;KAA/C,QAAA,uCAA+C;;;UCA1C,kBAAA;EDRjB;AAMA;AAEA;;;;ECAA,KAAiB,CAAA,EAOR,QAPQ;EAyBjB;;;;EAEG,UAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;cAFU,wBACH,uBACP,QAAQ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @generated by tsdown, DO NOT edit it manually
|
|
2
|
+
import { RuleConfigSeverity as Severity, UserConfig } from "@commitlint/types";
|
|
3
|
+
|
|
4
|
+
//#region src/apis/types.d.ts
|
|
5
|
+
interface TypeEnum {
|
|
6
|
+
description?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
emoji?: string;
|
|
9
|
+
}
|
|
10
|
+
type TypeObject = Record<string, TypeEnum>;
|
|
11
|
+
type TypeMode = "standard" | "minimal" | string[] | TypeObject;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/index.d.ts
|
|
14
|
+
interface DefineConfigParams {
|
|
15
|
+
/**
|
|
16
|
+
* Commit types configuration
|
|
17
|
+
* - `"standard"`: Use standard conventional commit types
|
|
18
|
+
* - `string[]`: Use custom types
|
|
19
|
+
* @default "standard"
|
|
20
|
+
*/
|
|
21
|
+
types?: TypeMode;
|
|
22
|
+
/**
|
|
23
|
+
* Automatically gather scopes from pnpm workspaces
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
autoScopes?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Provide additional scopes; or override if `autoScopes` is false
|
|
29
|
+
*/
|
|
30
|
+
scopes?: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Defines a commitlint configuration with automatic workspace scope detection and customizable commit types.
|
|
34
|
+
*
|
|
35
|
+
* @param params - Configuration options
|
|
36
|
+
* @returns A commitlint configuration object
|
|
37
|
+
*/
|
|
38
|
+
declare const defineConfig: (params?: DefineConfigParams) => Promise<UserConfig>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { DefineConfigParams, Severity, type UserConfig, defineConfig };
|
|
41
|
+
// Generated by @kcconfigs/tsdown
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/apis/types.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;UAAiB,QAAA;;;EAAjB,KAAiB,CAAA,EAAA,MAAA;AAMjB;AAEY,KAFA,UAAA,GAAa,MAEkC,CAAA,MAAA,EAFnB,QAEmB,CAAA;KAA/C,QAAA,uCAA+C;;;UCA1C,kBAAA;EDRjB;AAMA;AAEA;;;;ECAA,KAAiB,CAAA,EAOR,QAPQ;EAyBjB;;;;EAEG,UAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;cAFU,wBACH,uBACP,QAAQ"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// @generated by tsdown, DO NOT edit it manually
|
|
2
|
+
import { t as RuleConfigSeverity } from "./lib-D5qzG1z4.js";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { basename, join } from "node:path";
|
|
5
|
+
import { cwd } from "node:process";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { findWorkspacePackagesNoCheck } from "@pnpm/workspace.find-packages";
|
|
8
|
+
import { parse } from "yaml";
|
|
9
|
+
|
|
10
|
+
//#region src/apis/projects.ts
|
|
11
|
+
const findPackages = async (cwd$1, patterns, includeRoot) => {
|
|
12
|
+
return (await findWorkspacePackagesNoCheck(cwd$1, { patterns: patterns ?? ["**"] })).filter((pkg) => (includeRoot ?? false) || pkg.rootDir !== cwd$1).map((pkg) => pkg.manifest.name ?? basename(pkg.rootDirRealPath)).map((name) => name.startsWith("@") ? name.slice(1) : name);
|
|
13
|
+
};
|
|
14
|
+
const findPnpmPackages = async (includeRoot) => {
|
|
15
|
+
const cwd$1 = cwd();
|
|
16
|
+
const workspace = parse(await readFile(join(cwd$1, "pnpm-workspace.yaml"), { encoding: "utf8" }));
|
|
17
|
+
return findPackages(cwd$1, workspace === null || workspace === void 0 ? void 0 : workspace.packages, includeRoot);
|
|
18
|
+
};
|
|
19
|
+
const findNpmPackages = async (includeRoot) => {
|
|
20
|
+
const cwd$1 = cwd();
|
|
21
|
+
const { workspaces } = JSON.parse(await readFile(join(cwd$1, "package.json"), { encoding: "utf8" }));
|
|
22
|
+
return findPackages(cwd$1, workspaces, includeRoot);
|
|
23
|
+
};
|
|
24
|
+
const findBunPackages = async (includeRoot) => {
|
|
25
|
+
return findNpmPackages(includeRoot);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/apis/scopes.ts
|
|
30
|
+
/**
|
|
31
|
+
* Automatically detects and retrieves project scopes based on the package manager in use.
|
|
32
|
+
*
|
|
33
|
+
* Determines the package manager by checking for workspace configuration files:
|
|
34
|
+
* - pnpm: Checks for pnpm-workspace.yaml
|
|
35
|
+
* - bun: Checks for bun.lock or bun.lockb
|
|
36
|
+
* - npm: Falls back to npm package detection
|
|
37
|
+
*
|
|
38
|
+
* @param includeRoot - Whether to include the root package in the results
|
|
39
|
+
* @returns Array of detected project scope names
|
|
40
|
+
*/
|
|
41
|
+
const getAutoScope = (includeRoot) => {
|
|
42
|
+
const cwd$1 = cwd();
|
|
43
|
+
if (existsSync(join(cwd$1, "pnpm-workspace.yaml"))) return findPnpmPackages(includeRoot);
|
|
44
|
+
else if (existsSync(join(cwd$1, "bun.lock")) || existsSync(join(cwd$1, "bun.lockb"))) return findBunPackages(includeRoot);
|
|
45
|
+
return findNpmPackages(includeRoot);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves a merged list of commit scopes based on automatic detection and user input.
|
|
49
|
+
*
|
|
50
|
+
* Combines user-provided scopes with automatically detected project scopes.
|
|
51
|
+
* If no scopes are provided, returns a default set of common scope categories.
|
|
52
|
+
*
|
|
53
|
+
* @param auto - Whether to automatically detect scopes from workspace packages
|
|
54
|
+
* @param scopes - Optional user-provided scopes to include
|
|
55
|
+
* @returns Merged array of all available scopes
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
const getScopes = async (auto, scopes) => {
|
|
59
|
+
const _scopes = [];
|
|
60
|
+
if (scopes) _scopes.push(...scopes);
|
|
61
|
+
if (auto) _scopes.push(...await getAutoScope(false));
|
|
62
|
+
if (_scopes.length === 0) _scopes.push("core", "config", "script", "deps", "deps-dev");
|
|
63
|
+
return _scopes;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/apis/types.ts
|
|
68
|
+
const STANDARD_TYPES = {
|
|
69
|
+
feat: {
|
|
70
|
+
description: "A new feature",
|
|
71
|
+
title: "Features",
|
|
72
|
+
emoji: "✨"
|
|
73
|
+
},
|
|
74
|
+
perf: {
|
|
75
|
+
description: "A code change that improves performance",
|
|
76
|
+
title: "Performance Improvements",
|
|
77
|
+
emoji: "🚀"
|
|
78
|
+
},
|
|
79
|
+
fix: {
|
|
80
|
+
description: "A bug fix",
|
|
81
|
+
title: "Bugfixes",
|
|
82
|
+
emoji: "🐛"
|
|
83
|
+
},
|
|
84
|
+
docs: {
|
|
85
|
+
description: "Documentation only changes",
|
|
86
|
+
title: "Documentation",
|
|
87
|
+
emoji: "📚"
|
|
88
|
+
},
|
|
89
|
+
test: {
|
|
90
|
+
description: "Adding missing tests or correcting existing tests",
|
|
91
|
+
title: "Tests",
|
|
92
|
+
emoji: "🚨"
|
|
93
|
+
},
|
|
94
|
+
style: {
|
|
95
|
+
description: "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
|
|
96
|
+
title: "Styles",
|
|
97
|
+
emoji: "💎"
|
|
98
|
+
},
|
|
99
|
+
build: {
|
|
100
|
+
description: "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)",
|
|
101
|
+
title: "Builds",
|
|
102
|
+
emoji: "🛠"
|
|
103
|
+
},
|
|
104
|
+
refactor: {
|
|
105
|
+
description: "A code change that neither fixes a bug nor adds a feature",
|
|
106
|
+
title: "Code Refactoring",
|
|
107
|
+
emoji: "📦"
|
|
108
|
+
},
|
|
109
|
+
ci: {
|
|
110
|
+
description: "Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)",
|
|
111
|
+
title: "Continuous Integrations",
|
|
112
|
+
emoji: "⚙️"
|
|
113
|
+
},
|
|
114
|
+
chore: {
|
|
115
|
+
description: "Other changes that don't modify src or test files",
|
|
116
|
+
title: "Miscellaneous Chores",
|
|
117
|
+
emoji: "♻️"
|
|
118
|
+
},
|
|
119
|
+
revert: {
|
|
120
|
+
description: "Reverts a previous commit",
|
|
121
|
+
title: "Reverts",
|
|
122
|
+
emoji: "🗑"
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Retrieves commit types based on the specified mode.
|
|
127
|
+
*
|
|
128
|
+
* Returns a predefined list of commit types for standard or kc modes,
|
|
129
|
+
* or a custom list if an array or object is provided.
|
|
130
|
+
*
|
|
131
|
+
* @param mode - The commit type mode: "standard", "kc", or a custom object
|
|
132
|
+
* @returns Map of type object
|
|
133
|
+
*/
|
|
134
|
+
const getTypes = (mode) => {
|
|
135
|
+
if (Array.isArray(mode)) return mode.reduce((acc, type) => {
|
|
136
|
+
acc[type] = {};
|
|
137
|
+
return acc;
|
|
138
|
+
}, {});
|
|
139
|
+
if (typeof mode !== "string") return mode;
|
|
140
|
+
switch (mode) {
|
|
141
|
+
case "standard": return STANDARD_TYPES;
|
|
142
|
+
case "minimal": return {
|
|
143
|
+
feat: STANDARD_TYPES.feat,
|
|
144
|
+
perf: STANDARD_TYPES.perf,
|
|
145
|
+
fix: STANDARD_TYPES.fix,
|
|
146
|
+
chore: STANDARD_TYPES.chore
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/index.ts
|
|
153
|
+
/**
|
|
154
|
+
* Defines a commitlint configuration with automatic workspace scope detection and customizable commit types.
|
|
155
|
+
*
|
|
156
|
+
* @param params - Configuration options
|
|
157
|
+
* @returns A commitlint configuration object
|
|
158
|
+
*/
|
|
159
|
+
const defineConfig = async (params) => {
|
|
160
|
+
const { default: { parserPreset, prompt: { questions: { type, scope, ...questions }, ...prompt }, rules } } = await import("./lib-DPex9ONF.js");
|
|
161
|
+
const types = getTypes((params === null || params === void 0 ? void 0 : params.types) ?? "standard");
|
|
162
|
+
const scopes = await getScopes((params === null || params === void 0 ? void 0 : params.autoScopes) ?? true, params === null || params === void 0 ? void 0 : params.scopes);
|
|
163
|
+
return {
|
|
164
|
+
helpUrl: "use 'pnpm commit' to create commit instead",
|
|
165
|
+
parserPreset,
|
|
166
|
+
rules: {
|
|
167
|
+
...rules,
|
|
168
|
+
"type-enum": [
|
|
169
|
+
RuleConfigSeverity.Error,
|
|
170
|
+
"always",
|
|
171
|
+
Object.keys(types)
|
|
172
|
+
],
|
|
173
|
+
"scope-enum": () => [
|
|
174
|
+
RuleConfigSeverity.Error,
|
|
175
|
+
"always",
|
|
176
|
+
scopes
|
|
177
|
+
],
|
|
178
|
+
"subject-max-length": [
|
|
179
|
+
RuleConfigSeverity.Warning,
|
|
180
|
+
"always",
|
|
181
|
+
80
|
|
182
|
+
],
|
|
183
|
+
"body-max-line-length": [
|
|
184
|
+
RuleConfigSeverity.Warning,
|
|
185
|
+
"always",
|
|
186
|
+
300
|
|
187
|
+
]
|
|
188
|
+
},
|
|
189
|
+
prompt: {
|
|
190
|
+
...prompt,
|
|
191
|
+
questions: {
|
|
192
|
+
...questions,
|
|
193
|
+
type: {
|
|
194
|
+
...type,
|
|
195
|
+
enum: types
|
|
196
|
+
},
|
|
197
|
+
scope: {
|
|
198
|
+
...scope,
|
|
199
|
+
enum: Object.fromEntries(scopes.map((s) => [s, {}]))
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
settings: { enableMultipleScopes: false }
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
//#endregion
|
|
208
|
+
export { RuleConfigSeverity as Severity, defineConfig };
|
|
209
|
+
// Generated by @kcconfigs/tsdown
|
|
210
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["cwd","wd","cwd","wd","_scopes: string[]","Severity"],"sources":["../src/apis/projects.ts","../src/apis/scopes.ts","../src/apis/types.ts","../src/index.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport { cwd as wd } from \"node:process\";\nimport { findWorkspacePackagesNoCheck } from \"@pnpm/workspace.find-packages\";\nimport { parse } from \"yaml\";\n\nconst findPackages = async (\n\tcwd: string,\n\tpatterns: WithUndefined<string[]>,\n\tincludeRoot: WithUndefined<boolean>,\n) => {\n\tconst packages = await findWorkspacePackagesNoCheck(cwd, {\n\t\tpatterns: patterns ?? [\"**\"],\n\t});\n\n\treturn packages\n\t\t.filter((pkg) => (includeRoot ?? false) || pkg.rootDir !== cwd)\n\t\t.map((pkg) => pkg.manifest.name ?? basename(pkg.rootDirRealPath))\n\t\t.map((name) => (name.startsWith(\"@\") ? name.slice(1) : name));\n};\n\nexport const findPnpmPackages = async (\n\tincludeRoot?: boolean,\n): Promise<string[]> => {\n\tconst cwd = wd();\n\n\tconst pnpmWorkspace = await readFile(join(cwd, \"pnpm-workspace.yaml\"), {\n\t\tencoding: \"utf8\",\n\t});\n\n\tconst workspace = parse(pnpmWorkspace);\n\treturn findPackages(cwd, workspace?.packages, includeRoot);\n};\n\nexport const findNpmPackages = async (\n\tincludeRoot?: boolean,\n): Promise<string[]> => {\n\tconst cwd = wd();\n\n\tconst { workspaces } = JSON.parse(\n\t\tawait readFile(join(cwd, \"package.json\"), {\n\t\t\tencoding: \"utf8\",\n\t\t}),\n\t);\n\treturn findPackages(cwd, workspaces, includeRoot);\n};\n\nexport const findBunPackages = async (\n\tincludeRoot?: boolean,\n): Promise<string[]> => {\n\treturn findNpmPackages(includeRoot);\n};\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { cwd as wd } from \"node:process\";\nimport { findBunPackages, findNpmPackages, findPnpmPackages } from \"./projects\";\n\n/**\n * Automatically detects and retrieves project scopes based on the package manager in use.\n *\n * Determines the package manager by checking for workspace configuration files:\n * - pnpm: Checks for pnpm-workspace.yaml\n * - bun: Checks for bun.lock or bun.lockb\n * - npm: Falls back to npm package detection\n *\n * @param includeRoot - Whether to include the root package in the results\n * @returns Array of detected project scope names\n */\nconst getAutoScope = (includeRoot: boolean) => {\n\tconst cwd = wd();\n\n\tif (existsSync(join(cwd, \"pnpm-workspace.yaml\"))) {\n\t\treturn findPnpmPackages(includeRoot);\n\t} else if (\n\t\texistsSync(join(cwd, \"bun.lock\")) ||\n\t\texistsSync(join(cwd, \"bun.lockb\"))\n\t) {\n\t\treturn findBunPackages(includeRoot);\n\t}\n\n\treturn findNpmPackages(includeRoot);\n};\n\n/**\n * Retrieves a merged list of commit scopes based on automatic detection and user input.\n *\n * Combines user-provided scopes with automatically detected project scopes.\n * If no scopes are provided, returns a default set of common scope categories.\n *\n * @param auto - Whether to automatically detect scopes from workspace packages\n * @param scopes - Optional user-provided scopes to include\n * @returns Merged array of all available scopes\n *\n */\nexport const getScopes = async (\n\tauto: boolean,\n\tscopes?: string[],\n): Promise<string[]> => {\n\tconst _scopes: string[] = [];\n\n\tif (scopes) _scopes.push(...scopes);\n\tif (auto) _scopes.push(...(await getAutoScope(false)));\n\n\tif (_scopes.length === 0) {\n\t\t_scopes.push(\"core\", \"config\", \"script\", \"deps\", \"deps-dev\");\n\t}\n\treturn _scopes;\n};\n","export interface TypeEnum {\n\tdescription?: string;\n\ttitle?: string;\n\temoji?: string;\n}\n\nexport type TypeObject = Record<string, TypeEnum>;\n\nexport type TypeMode = \"standard\" | \"minimal\" | string[] | TypeObject;\n\nconst STANDARD_TYPES = {\n\tfeat: {\n\t\tdescription: \"A new feature\",\n\t\ttitle: \"Features\",\n\t\temoji: \"✨\",\n\t},\n\tperf: {\n\t\tdescription: \"A code change that improves performance\",\n\t\ttitle: \"Performance Improvements\",\n\t\temoji: \"🚀\",\n\t},\n\tfix: {\n\t\tdescription: \"A bug fix\",\n\t\ttitle: \"Bugfixes\",\n\t\temoji: \"🐛\",\n\t},\n\tdocs: {\n\t\tdescription: \"Documentation only changes\",\n\t\ttitle: \"Documentation\",\n\t\temoji: \"📚\",\n\t},\n\ttest: {\n\t\tdescription: \"Adding missing tests or correcting existing tests\",\n\t\ttitle: \"Tests\",\n\t\temoji: \"🚨\",\n\t},\n\tstyle: {\n\t\tdescription:\n\t\t\t\"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)\",\n\t\ttitle: \"Styles\",\n\t\temoji: \"💎\",\n\t},\n\tbuild: {\n\t\tdescription:\n\t\t\t\"Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)\",\n\t\ttitle: \"Builds\",\n\t\temoji: \"🛠\",\n\t},\n\trefactor: {\n\t\tdescription: \"A code change that neither fixes a bug nor adds a feature\",\n\t\ttitle: \"Code Refactoring\",\n\t\temoji: \"📦\",\n\t},\n\tci: {\n\t\tdescription:\n\t\t\t\"Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)\",\n\t\ttitle: \"Continuous Integrations\",\n\t\temoji: \"⚙️\",\n\t},\n\tchore: {\n\t\tdescription: \"Other changes that don't modify src or test files\",\n\t\ttitle: \"Miscellaneous Chores\",\n\t\temoji: \"♻️\",\n\t},\n\trevert: {\n\t\tdescription: \"Reverts a previous commit\",\n\t\ttitle: \"Reverts\",\n\t\temoji: \"🗑\",\n\t},\n} satisfies TypeObject;\n\n/**\n * Retrieves commit types based on the specified mode.\n *\n * Returns a predefined list of commit types for standard or kc modes,\n * or a custom list if an array or object is provided.\n *\n * @param mode - The commit type mode: \"standard\", \"kc\", or a custom object\n * @returns Map of type object\n */\nexport const getTypes = (mode: TypeMode): TypeObject => {\n\tif (Array.isArray(mode)) {\n\t\treturn mode.reduce((acc, type) => {\n\t\t\tacc[type] = {};\n\t\t\treturn acc;\n\t\t}, {} as TypeObject);\n\t}\n\tif (typeof mode !== \"string\") {\n\t\treturn mode;\n\t}\n\n\tswitch (mode) {\n\t\tcase \"standard\":\n\t\t\treturn STANDARD_TYPES;\n\t\tcase \"minimal\":\n\t\t\treturn {\n\t\t\t\tfeat: STANDARD_TYPES.feat,\n\t\t\t\tperf: STANDARD_TYPES.perf,\n\t\t\t\tfix: STANDARD_TYPES.fix,\n\t\t\t\tchore: STANDARD_TYPES.chore,\n\t\t\t};\n\t}\n};\n","import {\n\tRuleConfigSeverity as Severity,\n\ttype UserConfig,\n} from \"@commitlint/types\";\n\nimport { getScopes } from \"./apis/scopes\";\nimport { getTypes, type TypeMode } from \"./apis/types\";\n\nexport interface DefineConfigParams {\n\t/**\n\t * Commit types configuration\n\t * - `\"standard\"`: Use standard conventional commit types\n\t * - `string[]`: Use custom types\n\t * @default \"standard\"\n\t */\n\ttypes?: TypeMode;\n\t/**\n\t * Automatically gather scopes from pnpm workspaces\n\t * @default true\n\t */\n\tautoScopes?: boolean;\n\t/**\n\t * Provide additional scopes; or override if `autoScopes` is false\n\t */\n\tscopes?: string[];\n}\n\n/**\n * Defines a commitlint configuration with automatic workspace scope detection and customizable commit types.\n *\n * @param params - Configuration options\n * @returns A commitlint configuration object\n */\nexport const defineConfig = async (\n\tparams?: DefineConfigParams,\n): Promise<UserConfig> => {\n\tconst {\n\t\tdefault: {\n\t\t\tparserPreset,\n\t\t\tprompt: {\n\t\t\t\tquestions: { type, scope, ...questions },\n\t\t\t\t...prompt\n\t\t\t},\n\t\t\trules,\n\t\t},\n\t} = await import(\"@commitlint/config-conventional\");\n\n\tconst types = getTypes(params?.types ?? \"standard\");\n\tconst scopes = await getScopes(params?.autoScopes ?? true, params?.scopes);\n\n\treturn {\n\t\thelpUrl: \"use 'pnpm commit' to create commit instead\",\n\t\tparserPreset,\n\t\trules: {\n\t\t\t...rules,\n\t\t\t\"type-enum\": [Severity.Error, \"always\", Object.keys(types)],\n\t\t\t\"scope-enum\": () => [Severity.Error, \"always\", scopes],\n\t\t\t\"subject-max-length\": [Severity.Warning, \"always\", 80],\n\t\t\t\"body-max-line-length\": [Severity.Warning, \"always\", 300],\n\t\t},\n\t\tprompt: {\n\t\t\t...prompt,\n\t\t\tquestions: {\n\t\t\t\t...questions,\n\t\t\t\ttype: {\n\t\t\t\t\t...type,\n\t\t\t\t\tenum: types,\n\t\t\t\t},\n\t\t\t\tscope: {\n\t\t\t\t\t...scope,\n\t\t\t\t\tenum: Object.fromEntries(scopes.map((s) => [s, {}])),\n\t\t\t\t},\n\t\t\t},\n\t\t\tsettings: {\n\t\t\t\tenableMultipleScopes: false,\n\t\t\t},\n\t\t},\n\t};\n};\n\nexport { Severity };\nexport type { UserConfig };\n"],"mappings":";;;;;;;;;;AAMA,MAAM,eAAe,OACpB,OACA,UACA,gBACI;AAKJ,SAJiB,MAAM,6BAA6BA,OAAK,EACxD,UAAU,YAAY,CAAC,KAAK,EAC5B,CAAC,EAGA,QAAQ,SAAS,eAAe,UAAU,IAAI,YAAYA,MAAI,CAC9D,KAAK,QAAQ,IAAI,SAAS,QAAQ,SAAS,IAAI,gBAAgB,CAAC,CAChE,KAAK,SAAU,KAAK,WAAW,IAAI,GAAG,KAAK,MAAM,EAAE,GAAG,KAAM;;AAG/D,MAAa,mBAAmB,OAC/B,gBACuB;CACvB,MAAMA,QAAMC,KAAI;CAMhB,MAAM,YAAY,MAJI,MAAM,SAAS,KAAKD,OAAK,sBAAsB,EAAE,EACtE,UAAU,QACV,CAAC,CAEoC;AACtC,QAAO,aAAaA,6DAAK,UAAW,UAAU,YAAY;;AAG3D,MAAa,kBAAkB,OAC9B,gBACuB;CACvB,MAAMA,QAAMC,KAAI;CAEhB,MAAM,EAAE,eAAe,KAAK,MAC3B,MAAM,SAAS,KAAKD,OAAK,eAAe,EAAE,EACzC,UAAU,QACV,CAAC,CACF;AACD,QAAO,aAAaA,OAAK,YAAY,YAAY;;AAGlD,MAAa,kBAAkB,OAC9B,gBACuB;AACvB,QAAO,gBAAgB,YAAY;;;;;;;;;;;;;;;;AClCpC,MAAM,gBAAgB,gBAAyB;CAC9C,MAAME,QAAMC,KAAI;AAEhB,KAAI,WAAW,KAAKD,OAAK,sBAAsB,CAAC,CAC/C,QAAO,iBAAiB,YAAY;UAEpC,WAAW,KAAKA,OAAK,WAAW,CAAC,IACjC,WAAW,KAAKA,OAAK,YAAY,CAAC,CAElC,QAAO,gBAAgB,YAAY;AAGpC,QAAO,gBAAgB,YAAY;;;;;;;;;;;;;AAcpC,MAAa,YAAY,OACxB,MACA,WACuB;CACvB,MAAME,UAAoB,EAAE;AAE5B,KAAI,OAAQ,SAAQ,KAAK,GAAG,OAAO;AACnC,KAAI,KAAM,SAAQ,KAAK,GAAI,MAAM,aAAa,MAAM,CAAE;AAEtD,KAAI,QAAQ,WAAW,EACtB,SAAQ,KAAK,QAAQ,UAAU,UAAU,QAAQ,WAAW;AAE7D,QAAO;;;;;AC5CR,MAAM,iBAAiB;CACtB,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,KAAK;EACJ,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,MAAM;EACL,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,OAAO;EACN,aACC;EACD,OAAO;EACP,OAAO;EACP;CACD,OAAO;EACN,aACC;EACD,OAAO;EACP,OAAO;EACP;CACD,UAAU;EACT,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,IAAI;EACH,aACC;EACD,OAAO;EACP,OAAO;EACP;CACD,OAAO;EACN,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD,QAAQ;EACP,aAAa;EACb,OAAO;EACP,OAAO;EACP;CACD;;;;;;;;;;AAWD,MAAa,YAAY,SAA+B;AACvD,KAAI,MAAM,QAAQ,KAAK,CACtB,QAAO,KAAK,QAAQ,KAAK,SAAS;AACjC,MAAI,QAAQ,EAAE;AACd,SAAO;IACL,EAAE,CAAe;AAErB,KAAI,OAAO,SAAS,SACnB,QAAO;AAGR,SAAQ,MAAR;EACC,KAAK,WACJ,QAAO;EACR,KAAK,UACJ,QAAO;GACN,MAAM,eAAe;GACrB,MAAM,eAAe;GACrB,KAAK,eAAe;GACpB,OAAO,eAAe;GACtB;;;;;;;;;;;;ACnEJ,MAAa,eAAe,OAC3B,WACyB;CACzB,MAAM,EACL,SAAS,EACR,cACA,QAAQ,EACP,WAAW,EAAE,MAAM,OAAO,GAAG,aAC7B,GAAG,UAEJ,YAEE,MAAM,OAAO;CAEjB,MAAM,QAAQ,0DAAS,OAAQ,UAAS,WAAW;CACnD,MAAM,SAAS,MAAM,2DAAU,OAAQ,eAAc,sDAAM,OAAQ,OAAO;AAE1E,QAAO;EACN,SAAS;EACT;EACA,OAAO;GACN,GAAG;GACH,aAAa;IAACC,mBAAS;IAAO;IAAU,OAAO,KAAK,MAAM;IAAC;GAC3D,oBAAoB;IAACA,mBAAS;IAAO;IAAU;IAAO;GACtD,sBAAsB;IAACA,mBAAS;IAAS;IAAU;IAAG;GACtD,wBAAwB;IAACA,mBAAS;IAAS;IAAU;IAAI;GACzD;EACD,QAAQ;GACP,GAAG;GACH,WAAW;IACV,GAAG;IACH,MAAM;KACL,GAAG;KACH,MAAM;KACN;IACD,OAAO;KACN,GAAG;KACH,MAAM,OAAO,YAAY,OAAO,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;KACpD;IACD;GACD,UAAU,EACT,sBAAsB,OACtB;GACD;EACD"}
|