@itcase/config 1.6.47 → 1.6.49

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.
@@ -1,22 +1,25 @@
1
- /**
2
- * Custom Commitizen adapter: type → scope → subScope (optional) → subject.
3
- * Settings from commitlintProject.js; SCOPES from project commitlint.config.mjs.
4
- */
5
-
1
+ import fs from 'fs'
6
2
  import path from 'path'
7
3
  import { pathToFileURL } from 'url'
8
4
 
5
+ const COMMITLINT_CONFIG_FILES = [
6
+ 'commitlint.config.mjs',
7
+ 'commitlint.config.js',
8
+ 'commitlint.config.cjs',
9
+ ]
10
+
9
11
  const SUB_SCOPE_MESSAGE = 'Select sub-scope (optional):'
10
12
  const SUBJECT_REQUIRED = 'Subject is required'
11
13
 
12
- function buildScope(scope, subScope) {
13
- if (!scope) return ''
14
- if (!subScope) return scope
15
- return `${scope} / ${subScope}`
16
- }
17
-
18
- function toChoices(values) {
19
- return values.map((value) => ({ name: value, value }))
14
+ function findCommitlintConfig() {
15
+ const cwd = process.cwd()
16
+ for (const name of COMMITLINT_CONFIG_FILES) {
17
+ const filePath = path.resolve(cwd, name)
18
+ if (fs.existsSync(filePath)) return filePath
19
+ }
20
+ throw new Error(
21
+ `Commitlint config not found. Tried: ${COMMITLINT_CONFIG_FILES.join(', ')}`,
22
+ )
20
23
  }
21
24
 
22
25
  function buildTypeChoices(types, typeEnum) {
@@ -30,94 +33,96 @@ function buildTypeChoices(types, typeEnum) {
30
33
  }
31
34
 
32
35
  async function loadConfig() {
33
- const [{ default: load }, { commitlintProject }] = await Promise.all([
34
- import('@commitlint/load'),
35
- import('./commitlintProject.js'),
36
- ])
37
-
36
+ const { default: load } = await import('@commitlint/load')
38
37
  const { prompt: promptOverrides, rules } = await load()
39
38
 
40
- const configPath = path.resolve(process.cwd(), 'commitlint.config.mjs')
39
+ const configPath = findCommitlintConfig()
41
40
  const configModule = await import(pathToFileURL(configPath).href)
42
- const SCOPES = configModule.default?.SCOPES || {}
41
+ const SCOPES = configModule.default?.SCOPES ?? {}
43
42
 
44
- return { commitlintProject, promptOverrides, rules, SCOPES }
43
+ return { promptOverrides, rules, SCOPES }
45
44
  }
46
45
 
47
- function prompter(inquirer, commit) {
48
- ;(async () => {
49
- try {
50
- const { commitlintProject, promptOverrides, rules, SCOPES } =
51
- await loadConfig()
52
-
53
- const q = commitlintProject.prompt.questions
54
- const over = promptOverrides?.questions
55
-
56
- const scopeEnum = rules['scope-enum']?.[2]
57
- const types =
58
- rules['type-enum']?.[2] ?? commitlintProject.rules['type-enum'][2]
59
- const typeEnum = over?.type?.enum ?? q.type.enum
60
- const typeChoices = buildTypeChoices(types, typeEnum)
61
-
62
- const baseScopes = Array.isArray(scopeEnum)
63
- ? scopeEnum.filter((s) => !s.includes(' / '))
64
- : Object.keys(SCOPES)
65
- const scopeList = baseScopes.length > 0 ? baseScopes : Object.keys(SCOPES)
66
-
67
- const messages = {
68
- type: over?.type?.description ?? q.type.description,
69
- scope: over?.scope?.description ?? q.scope.description,
70
- subject: over?.subject?.description ?? q.subject.description,
71
- }
46
+ async function prompter(inquirer, commit) {
47
+ try {
48
+ const { promptOverrides, rules, SCOPES } = await loadConfig()
49
+
50
+ const questions = promptOverrides?.questions ?? {}
51
+ const scopeEnum = rules['scope-enum']?.[2]
52
+ const types = rules['type-enum']?.[2]
53
+ if (!types?.length) {
54
+ throw new Error(
55
+ 'Commitlint config must set rules["type-enum"][2] (list of types)',
56
+ )
57
+ }
58
+ const typeEnum = questions.type?.enum ?? {}
59
+ const typeChoices = buildTypeChoices(types, typeEnum)
60
+
61
+ const isScopesArray = Array.isArray(SCOPES)
62
+ const scopesFromConfig = isScopesArray ? SCOPES : Object.keys(SCOPES)
63
+ const baseScopes = Array.isArray(scopeEnum)
64
+ ? scopeEnum.filter((s) => !s.includes(' / '))
65
+ : scopesFromConfig
66
+ const scopeList = baseScopes.length > 0 ? baseScopes : scopesFromConfig
67
+
68
+ const messages = {
69
+ type: questions.type?.description ?? 'Select the type of change',
70
+ scope: questions.scope?.description ?? 'What is the scope of this change',
71
+ subject: questions.subject?.description ?? 'Write a short description',
72
+ }
72
73
 
73
- const answers = await inquirer.prompt([
74
- {
75
- type: 'list',
76
- name: 'type',
77
- message: messages.type,
78
- choices: typeChoices,
79
- },
80
- {
81
- type: 'list',
82
- name: 'scope',
83
- message: messages.scope,
84
- choices: toChoices(scopeList),
74
+ const answers = await inquirer.prompt([
75
+ {
76
+ type: 'list',
77
+ name: 'type',
78
+ message: messages.type,
79
+ choices: typeChoices,
80
+ },
81
+ {
82
+ type: 'list',
83
+ name: 'scope',
84
+ message: messages.scope,
85
+ choices: scopeList.map((value) => ({ name: value, value: value })),
86
+ },
87
+ {
88
+ type: 'list',
89
+ name: 'subScope',
90
+ message: SUB_SCOPE_MESSAGE,
91
+ choices: function (answers) {
92
+ const subs = isScopesArray ? [] : SCOPES[answers.scope] || []
93
+ return [
94
+ ...subs.map((value) => ({ name: value, value: value })),
95
+ new inquirer.Separator(),
96
+ { name: 'none', value: '' },
97
+ ]
85
98
  },
86
- {
87
- type: 'list',
88
- name: 'subScope',
89
- message: SUB_SCOPE_MESSAGE,
90
- choices: function (answers) {
91
- const subs = SCOPES[answers.scope] || []
92
- return [
93
- ...toChoices(subs),
94
- new inquirer.Separator(),
95
- { name: 'None', value: '' },
96
- ]
97
- },
98
- when: function (answers) {
99
- const subs = SCOPES[answers.scope]
100
- return answers.scope && subs?.length > 0
101
- },
99
+ when: function (answers) {
100
+ if (isScopesArray) return false
101
+ const subs = SCOPES[answers.scope]
102
+ return answers.scope && subs?.length > 0
102
103
  },
103
- {
104
- type: 'input',
105
- name: 'subject',
106
- message: messages.subject,
107
- validate: (input) => (input?.trim() ? true : SUBJECT_REQUIRED),
108
- },
109
- ])
110
-
111
- const scope = buildScope(answers.scope, answers.subScope)
112
- const header = scope
113
- ? `${answers.type}(${scope}): ${answers.subject.trim()}`
114
- : `${answers.type}: ${answers.subject.trim()}`
115
- commit(header)
116
- } catch (err) {
117
- console.error(err)
118
- process.exit(1)
119
- }
120
- })()
104
+ },
105
+ {
106
+ type: 'input',
107
+ name: 'subject',
108
+ message: messages.subject,
109
+ validate: (input) => (input?.trim() ? true : SUBJECT_REQUIRED),
110
+ },
111
+ ])
112
+
113
+ const scope = answers.scope
114
+ ? answers.subScope
115
+ ? `${answers.scope} / ${answers.subScope}`
116
+ : answers.scope
117
+ : ''
118
+ const header = scope
119
+ ? `${answers.type}(${scope}): ${answers.subject.trim()}`
120
+ : `${answers.type}: ${answers.subject.trim()}`
121
+ commit(header)
122
+ } catch (err) {
123
+ console.error(err)
124
+ process.exit(1)
125
+ }
121
126
  }
122
127
 
123
128
  export { prompter }
@@ -19,11 +19,16 @@ export const promptSubjectDescription =
19
19
  'Write a short, imperative tense description of the change'
20
20
 
21
21
  /**
22
- * Builds flat scope-enum list from SCOPES: base scopes + "scope / subScope".
23
- * @param {Record<string, string[]>} scopeSubscopes
22
+ * Builds flat scope-enum list from SCOPES.
23
+ * - If SCOPES is string[]: returns it as-is (no sub-scopes).
24
+ * - If SCOPES is Record<string, string[]>: base scopes + "scope / subScope".
25
+ * @param {string[] | Record<string, string[]>} scopeSubscopes
24
26
  * @returns {string[]}
25
27
  */
26
28
  export function buildScopeEnum(scopeSubscopes) {
29
+ if (Array.isArray(scopeSubscopes)) {
30
+ return [...scopeSubscopes]
31
+ }
27
32
  const base = Object.keys(scopeSubscopes)
28
33
  return [
29
34
  ...base,
@@ -8,7 +8,7 @@ import { commitlintRelease } from './commitlintRelease.js'
8
8
 
9
9
  /**
10
10
  * @param {object} baseConfig
11
- * @param {Record<string, string[]>} scopes
11
+ * @param {string[] | Record<string, string[]>} scopes
12
12
  * @returns {object}
13
13
  */
14
14
  function createConfig(baseConfig, scopes) {
@@ -24,7 +24,7 @@ function createConfig(baseConfig, scopes) {
24
24
  }
25
25
 
26
26
  /**
27
- * @param {Record<string, string[]>} scopes
27
+ * @param {string[] | Record<string, string[]>} scopes
28
28
  * @returns {object}
29
29
  */
30
30
  export function createCommitlintProjectConfig(scopes) {
@@ -32,7 +32,7 @@ export function createCommitlintProjectConfig(scopes) {
32
32
  }
33
33
 
34
34
  /**
35
- * @param {Record<string, string[]>} scopes
35
+ * @param {string[] | Record<string, string[]>} scopes
36
36
  * @returns {object}
37
37
  */
38
38
  export function createCommitlintReleaseConfig(scopes) {
@@ -8,7 +8,7 @@ import {
8
8
  } from './commitlintCommon.js'
9
9
 
10
10
  const commitlintProject = {
11
- parserPreset,
11
+ parserPreset: parserPreset,
12
12
  ignores: [
13
13
  (commit) => /^Merge branch/.test(commit),
14
14
  (commit) => /^Merge pull request/.test(commit),
@@ -33,7 +33,7 @@ const commitlintProject = {
33
33
  ],
34
34
  'scope-enum': [2, 'always', ['PLEASE', 'SET', 'SCOPE-ENUM']],
35
35
  },
36
- defaultIgnores,
36
+ defaultIgnores: defaultIgnores,
37
37
  prompt: {
38
38
  settings: {
39
39
  enableMultipleScopes: true,
@@ -8,14 +8,14 @@ import {
8
8
  } from './commitlintCommon.js'
9
9
 
10
10
  const commitlintRelease = {
11
- parserPreset,
11
+ parserPreset: parserPreset,
12
12
  extends: ['@commitlint/config-conventional'],
13
13
  rules: {
14
14
  ...commonRules,
15
15
  'type-case': [0],
16
16
  'type-enum': [2, 'always', ['patch', 'minor', 'major']],
17
17
  },
18
- defaultIgnores,
18
+ defaultIgnores: defaultIgnores,
19
19
  prompt: {
20
20
  settings: {},
21
21
  questions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/config",
3
- "version": "1.6.47",
3
+ "version": "1.6.49",
4
4
  "author": "ITCase",
5
5
  "description": "ITCase Config",
6
6
  "engines": {
@@ -31,11 +31,11 @@
31
31
  "registry": "https://registry.npmjs.org/"
32
32
  },
33
33
  "dependencies": {
34
- "@lerna-lite/cli": "^4.11.0",
35
- "@lerna-lite/exec": "^4.11.1",
36
- "@lerna-lite/list": "^4.11.0",
37
- "@lerna-lite/run": "^4.11.1",
38
- "@lerna-lite/watch": "^4.11.0",
34
+ "@lerna-lite/cli": "^4.11.2",
35
+ "@lerna-lite/exec": "^4.11.2",
36
+ "@lerna-lite/list": "^4.11.2",
37
+ "@lerna-lite/run": "^4.11.2",
38
+ "@lerna-lite/watch": "^4.11.2",
39
39
  "semantic-release-lerna": "^2.17.0",
40
40
  "chokidar-cli": "^3.0.0",
41
41
  "@commitlint/cli": "^20.4.1",
@@ -95,12 +95,12 @@
95
95
  "rollup-plugin-dts": "^6.3.0",
96
96
  "rollup-plugin-peer-deps-external": "^2.2.4",
97
97
  "rollup-preserve-directives": "^1.1.3",
98
- "semantic-release": "^25.0.2",
98
+ "semantic-release": "^25.0.3",
99
99
  "postcss-urlrewrite": "^0.3.0"
100
100
  },
101
101
  "devDependencies": {
102
- "@itcase/lint": "^1.1.95",
103
- "eslint": "^9.39.2",
102
+ "@itcase/lint": "^1.1.96",
103
+ "eslint": "^10.0.0",
104
104
  "husky": "^9.1.7",
105
105
  "inquirer": "^13.2.2",
106
106
  "lint-staged": "^16.2.7",