diff --git a/index.js b/index.js index 7cca0e5..7294893 100755 --- a/index.js +++ b/index.js @@ -57,9 +57,13 @@ async function buildCliConfig() { } let configFile +let argvConfigSet = false if (argv.env) process.env.NODE_ENV = argv.env -if (argv.config) argv.config = path.resolve(argv.config) +if (argv.config) { + argvConfigSet = true + argv.config = path.resolve(argv.config) +} let { isTTY } = process.stdin @@ -178,7 +182,10 @@ function rc(ctx, path) { return rc }) .catch((err) => { - if (!err.message.includes('No PostCSS Config found')) throw err + // if a config path is passed explicitly in CLI do not ignore the error + if (!err.message.includes('No PostCSS Config found') || argvConfigSet) { + throw err + } }) } diff --git a/test/error.js b/test/error.js index 5ff67ef..8c76a47 100644 --- a/test/error.js +++ b/test/error.js @@ -63,3 +63,17 @@ test('CssSyntaxError', (t) => { }, ) }) + +test('fails on invalid explicit config', async (t) => { + const output = tmp('output-ignore.css') + + const { stderr, code } = await cli([ + 'test/fixtures/a.css', + '-o', + output, + '--config', + '/foo/bar', + ]) + t.is(code, 1, 'expected non-zero error code') + t.regex(stderr, /No PostCSS Config found/) +})