From 49b3a7797e42a5ba9304d518299446491720117d Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Thu, 9 May 2019 12:06:26 +0000 Subject: [PATCH] fix: handle absolute config paths correctly #647 --- @commitlint/load/src/index.js | 2 +- @commitlint/load/src/index.test.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/@commitlint/load/src/index.js b/@commitlint/load/src/index.js index d617be64d5..14eff90489 100644 --- a/@commitlint/load/src/index.js +++ b/@commitlint/load/src/index.js @@ -106,7 +106,7 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => { async function loadConfig(cwd, configPath) { const explorer = cosmiconfig('commitlint'); - const explicitPath = configPath ? path.join(cwd, configPath) : undefined; + const explicitPath = configPath ? path.resolve(cwd, configPath) : undefined; const explore = explicitPath ? explorer.load : explorer.search; const searchPath = explicitPath ? explicitPath : cwd; const local = await explore(searchPath); diff --git a/@commitlint/load/src/index.test.js b/@commitlint/load/src/index.test.js index e1e97d7456..3a2bfe5701 100644 --- a/@commitlint/load/src/index.test.js +++ b/@commitlint/load/src/index.test.js @@ -21,13 +21,20 @@ test('uses seed as configured', async t => { t.is(actual.rules.foo, 'bar'); }); -test('rules should be loaded from specify config file', async t => { +test('rules should be loaded from relative config file', async t => { const file = 'config/commitlint.config.js'; const cwd = await git.bootstrap('fixtures/specify-config-file'); const actual = await load({}, {cwd, file}); t.is(actual.rules.foo, 'bar'); }); +test('rules should be loaded from absolute config file', async t => { + const cwd = await git.bootstrap('fixtures/specify-config-file'); + const file = path.join(cwd, 'config/commitlint.config.js'); + const actual = await load({}, {cwd: process.cwd(), file}); + t.is(actual.rules.foo, 'bar'); +}); + test('plugins should be loaded from seed', async t => { const plugin = {'@global': true}; const scopedPlugin = {'@global': true};