Skip to content

Commit

Permalink
feat(resolve-extends): accept absolute path in extends (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz authored and byCedric committed Oct 16, 2019
1 parent 25714e4 commit ecac29f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions @commitlint/resolve-extends/src/index.test.ts
Expand Up @@ -101,6 +101,22 @@ test('ignores prefix for relative extends', () => {
expect(ctx.require).toHaveBeenCalledWith('./extender');
});

test('ignores prefix for absolute extends', () => {
const absolutePath = require.resolve('@commitlint/config-angular');
const input = {extends: [absolutePath]};
const ctx = {
resolve: id,
require: jest.fn(() => ({}))
} as ResolveExtendsContext;

resolveExtends(input, {
...ctx,
prefix: 'prefix'
});

expect(ctx.require).toHaveBeenCalledWith(absolutePath);
});

test('propagates return value of require function', () => {
const input = {extends: ['extender-name']};
const propagated = {foo: 'bar'};
Expand Down
3 changes: 2 additions & 1 deletion @commitlint/resolve-extends/src/index.ts
Expand Up @@ -82,12 +82,13 @@ function getId(raw: string = '', prefix: string = ''): string {
const first = raw.charAt(0);
const scoped = first === '@';
const relative = first === '.';
const absolute = path.isAbsolute(raw);

if (scoped) {
return raw.includes('/') ? raw : [raw, prefix].filter(String).join('/');
}

return relative ? raw : [prefix, raw].filter(String).join('-');
return relative || absolute ? raw : [prefix, raw].filter(String).join('-');
}

function resolveConfig<T>(
Expand Down

0 comments on commit ecac29f

Please sign in to comment.