Skip to content

Commit c80766b

Browse files
committed
feat(core): support conventional-changelog-lint-config-*
1 parent bfeb653 commit c80766b

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

@commitlint/core/src/library/resolve-extends.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ export default function resolveExtends(config = {}, context = {}) {
1919
// (any, string, string, Function) => any[];
2020
function loadExtends(config = {}, context = {}) {
2121
return (config.extends || []).reduce((configs, raw) => {
22-
const id = getId(raw, context.prefix);
23-
const resolve = context.resolve || resolveId;
24-
const resolved = resolve(id, context);
2522
const load = context.require || require;
23+
const resolved = resolveConfig(raw, context);
2624
const c = load(resolved);
2725

2826
// Remove deprecation warning in version 3
2927
if (typeof c === 'object' && 'wildcards' in c) {
30-
console.warn(`'wildcards' found in '${id}' ignored. Raise an issue at 'npm repo ${id}' to remove the wildcards and silence this warning.`);
28+
console.warn(`'wildcards' found in '${raw}' ignored. To silence this warning raise an issue at 'npm repo ${raw}' to remove the wildcards.`);
3129
}
3230

3331
const ctx = merge({}, context, {
@@ -45,6 +43,20 @@ function getId(raw = '', prefix = '') {
4543
return (scoped || relative) ? raw : [prefix, raw].filter(String).join('-');
4644
}
4745

46+
function resolveConfig(raw, context = {}) {
47+
const resolve = context.resolve || resolveId;
48+
const id = getId(raw, context.prefix);
49+
50+
try {
51+
return resolve(id, context);
52+
} catch (err) {
53+
const legacy = getId(raw, 'conventional-changelog-lint-config');
54+
const resolved = resolve(legacy, context);
55+
console.warn(`Resolving ${raw} to legacy config ${legacy}. To silence this warning raise an issue at 'npm repo ${legacy}' to rename to ${id}.`);
56+
return resolved;
57+
}
58+
}
59+
4860
function resolveId(id, context = {}) {
4961
return from(context.cwd || process.cwd(), id);
5062
}

@commitlint/core/src/library/resolve-extends.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,33 @@ test('extending contents should take precedence', t => {
168168

169169
t.deepEqual(actual, expected);
170170
});
171+
172+
test('should fall back to conventional-changelog-lint-config prefix', t => {
173+
const input = {extends: ['extender-name']};
174+
175+
const actual = resolveExtends(input, {
176+
prefix: 'prefix',
177+
resolve(id) {
178+
if (id === 'conventional-changelog-lint-config-extender-name') {
179+
return 'conventional-changelog-lint-config-extender-name';
180+
}
181+
throw new Error(`Could not find module "*${id}"`);
182+
},
183+
require(id) {
184+
if (id === 'conventional-changelog-lint-config-extender-name') {
185+
return {
186+
rules: {
187+
fallback: true
188+
}
189+
};
190+
}
191+
}
192+
});
193+
194+
t.deepEqual(actual, {
195+
extends: ['extender-name'],
196+
rules: {
197+
fallback: true
198+
}
199+
});
200+
});

0 commit comments

Comments
 (0)