From 7f1725b67a7e48ac997b73d1743b290abb65e207 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Tue, 16 Jan 2024 08:42:11 +0100 Subject: [PATCH 1/2] Fix https://github.com/postcss/postcss-cli/issues/467 --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f77bf04..4cc4bc5 100755 --- a/index.js +++ b/index.js @@ -164,7 +164,7 @@ buildCliConfig() process.exit(1) }) -function rc(ctx, path) { +function rc(ctx, path, cliConfigPath) { if (argv.use) return Promise.resolve(cliConfig) return postcssrc(ctx, path) @@ -178,7 +178,7 @@ function rc(ctx, path) { return rc }) .catch((err) => { - if (!err.message.includes('No PostCSS Config found')) throw err + if (!err.message.includes('No PostCSS Config found') || cliConfigPath) throw err }) } @@ -202,6 +202,8 @@ function files(files) { function css(css, file) { const ctx = { options: cliConfig.options } + const origArgvConfig = argv.config + if (file !== 'stdin') { ctx.file = { dirname: path.dirname(file), @@ -221,7 +223,7 @@ function css(css, file) { printVerbose(pc.cyan(`Processing ${pc.bold(relativePath)}...`)) - return rc(ctx, argv.config) + return rc(ctx, argv.config, origArgvConfig) .then((config) => { config = config || cliConfig const options = { ...config.options } From 5e48352d0045dd5bfb3cedd920fff6eeb04f1228 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Wed, 17 Jan 2024 13:02:50 +0100 Subject: [PATCH 2/2] add test & docs --- index.js | 1 + test/cli.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/index.js b/index.js index 4cc4bc5..15bc039 100755 --- a/index.js +++ b/index.js @@ -178,6 +178,7 @@ function rc(ctx, path, cliConfigPath) { return rc }) .catch((err) => { + // if a config path is passed explicitly in CLI do not ignore the error if (!err.message.includes('No PostCSS Config found') || cliConfigPath) throw err }) } diff --git a/test/cli.js b/test/cli.js index 3adab9b..366e4d3 100644 --- a/test/cli.js +++ b/test/cli.js @@ -18,3 +18,20 @@ test('works with defaults', async (t) => { t.is(await read(output), await read('test/fixtures/a.css')) }) + +test('fails on invalid explicit config', async (t) => { + const output = tmp('output-ignore.css') + + const { error, stderr } = await cli([ + 'test/fixtures/a.css', + '-o', + output, + '--config', + '/foo/bar', + ]) + + t.regex( + stderr, + /No PostCSS Config found/, + ) +})