Skip to content

Commit

Permalink
feat: add possibility to extend from string (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
onrige committed Feb 3, 2020
1 parent 3476234 commit 056c6fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions @commitlint/resolve-extends/src/index.test.ts
Expand Up @@ -30,6 +30,17 @@ test('fails for missing extends', async () => {
);
});

test('resolves extends for single config', () => {
const input = {extends: 'extender-name'};
const ctx = {
resolve: id,
require: jest.fn(() => ({}))
} as ResolveExtendsContext;
resolveExtends(input, ctx);

expect(ctx.require).toHaveBeenCalledWith('extender-name');
});

test('uses empty prefix by default', () => {
const input = {extends: ['extender-name']};
const ctx = {
Expand Down
7 changes: 5 additions & 2 deletions @commitlint/resolve-extends/src/index.ts
Expand Up @@ -13,7 +13,7 @@ export interface ResolvedConfig {

export interface ResolveExtendsConfig {
parserPreset?: unknown;
extends?: string[];
extends?: string | string[];
[key: string]: unknown;
}

Expand Down Expand Up @@ -48,7 +48,10 @@ function loadExtends(
config: ResolveExtendsConfig = {},
context: ResolveExtendsContext = {}
): ResolvedConfig[] {
return (config.extends || []).reduce<ResolvedConfig[]>((configs, raw) => {
const {extends: e} = config;
const ext = e ? (Array.isArray(e) ? e : [e]) : [];

return ext.reduce<ResolvedConfig[]>((configs, raw) => {
const load = context.require || require;
const resolved = resolveConfig(raw, context);
const c = load(resolved);
Expand Down

0 comments on commit 056c6fe

Please sign in to comment.