Skip to content

Commit ecac29f

Browse files
merceyzbyCedric
authored andcommitted
feat(resolve-extends): accept absolute path in extends (#825)
1 parent 25714e4 commit ecac29f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

@commitlint/resolve-extends/src/index.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ test('ignores prefix for relative extends', () => {
101101
expect(ctx.require).toHaveBeenCalledWith('./extender');
102102
});
103103

104+
test('ignores prefix for absolute extends', () => {
105+
const absolutePath = require.resolve('@commitlint/config-angular');
106+
const input = {extends: [absolutePath]};
107+
const ctx = {
108+
resolve: id,
109+
require: jest.fn(() => ({}))
110+
} as ResolveExtendsContext;
111+
112+
resolveExtends(input, {
113+
...ctx,
114+
prefix: 'prefix'
115+
});
116+
117+
expect(ctx.require).toHaveBeenCalledWith(absolutePath);
118+
});
119+
104120
test('propagates return value of require function', () => {
105121
const input = {extends: ['extender-name']};
106122
const propagated = {foo: 'bar'};

@commitlint/resolve-extends/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ function getId(raw: string = '', prefix: string = ''): string {
8282
const first = raw.charAt(0);
8383
const scoped = first === '@';
8484
const relative = first === '.';
85+
const absolute = path.isAbsolute(raw);
8586

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

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

9394
function resolveConfig<T>(

0 commit comments

Comments
 (0)