Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail silently when config not found #471

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -178,7 +178,8 @@ 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') || cliConfigPath) throw err
})
}

Expand All @@ -202,6 +203,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),
Expand All @@ -221,7 +224,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 }
Expand Down
17 changes: 17 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@

t.is(await read(output), await read('test/fixtures/a.css'))
})

test('fails on invalid explicit config', async (t) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be moved to test/error.js

const output = tmp('output-ignore.css')

const { error, stderr } = await cli([

Check failure on line 25 in test/cli.js

View workflow job for this annotation

GitHub Actions / test (18, ubuntu-latest)

'error' is assigned a value but never used

Check failure on line 25 in test/cli.js

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest)

'error' is assigned a value but never used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should verify that there's a non-zero exit code

'test/fixtures/a.css',
'-o',
output,
'--config',
'/foo/bar',
])

t.regex(
stderr,
/No PostCSS Config found/,
)
})
Loading