diff --git a/CHANGELOG.md b/CHANGELOG.md index b56b05e..a51e8c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 6.0.1 / 2018-10-17 + +- Better error handling for errors thrown by plugins ([#242](https://github.com/postcss/postcss-cli/issues/242), [#243](https://github.com/postcss/postcss-cli/pull/243)) +- Update dependencies +- Clarify docs ([#233](https://github.com/postcss/postcss-cli/issues/233)) + # 6.0.0 / 2018-07-18 - Drop support for Node 4 diff --git a/README.md b/README.md index ca0877b..372170c 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Advanced options: directory, for use with --dir [string] --poll Use polling for file watching. Can optionally pass polling interval; default 100 ms - --config Set a custom path to look for a config file [string] + --config Set a custom directory to look for a config file [string] Options: --version Show version number [boolean] @@ -67,7 +67,7 @@ If no input files are passed, it reads from stdin. If neither -o, --dir, or If there are multiple input files, the --dir or --replace option must be passed. -Input files may contain globs (ie: src/**/*.css). If you pass an input directory, it will process +Input files may contain globs (e.g. src/**/*.css). If you pass an input directory, it will process all files in the directory and any subdirectories, respecting the glob pattern. ``` diff --git a/index.js b/index.js index eed5d3e..9501e42 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,10 @@ const cliConfig = { try { return require(plugin)() } catch (e) { - return error(`Plugin Error: Cannot find module '${plugin}'`) + const msg = e.message || `Cannot find module '${plugin}'` + let prefix = msg.includes(plugin) ? '' : ` (${plugin})` + if (e.name && e.name !== 'Error') prefix += `: ${e.name}` + return error(`Plugin Error${prefix}: ${msg}'`) } }) : [] diff --git a/lib/args.js b/lib/args.js index 23979d3..1855260 100644 --- a/lib/args.js +++ b/lib/args.js @@ -118,7 +118,7 @@ Usage: implies: 'watch' }) .option('config', { - desc: 'Set a custom path to look for a config file', + desc: 'Set a custom directory to look for a config file', type: 'string' }) .version(version) @@ -134,7 +134,7 @@ Usage: If there are multiple input files, the --dir or --replace option must be passed. -Input files may contain globs (ie: src/**/*.css). If you pass an input directory, it will process all files in the directory and any subdirectories, respecting the glob pattern. +Input files may contain globs (e.g. src/**/*.css). If you pass an input directory, it will process all files in the directory and any subdirectories, respecting the glob pattern. For more details, please see https://github.com/postcss/postcss-cli` ).argv diff --git a/package.json b/package.json index df8c41d..463604c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-cli", - "version": "6.0.0", + "version": "6.0.1", "description": "CLI for PostCSS", "main": "index.js", "engines": { @@ -26,7 +26,7 @@ "globby": "^8.0.0", "postcss": "^7.0.0", "postcss-load-config": "^2.0.0", - "postcss-reporter": "^5.0.0", + "postcss-reporter": "^6.0.0", "pretty-hrtime": "^1.0.3", "read-cache": "^1.0.0", "yargs": "^12.0.1" @@ -35,11 +35,11 @@ "ava": "^0.25.0", "coveralls": "^3.0.0", "eslint": "^5.0.0", - "eslint-config-problems": "1.0.0", - "nyc": "^11.0.2", - "postcss-import": "^11.0.0", - "prettier": "~1.13.0", - "sugarss": "^1.0.0", + "eslint-config-problems": "1.1.0", + "nyc": "^13.1.0", + "postcss-import": "^12.0.0", + "prettier": "~1.14.0", + "sugarss": "^2.0.0", "uuid": "^3.0.1" }, "files": [ diff --git a/test/error.js b/test/error.js index b49781b..3d7732f 100644 --- a/test/error.js +++ b/test/error.js @@ -40,7 +40,7 @@ test.failing('invalid --config', t => { }) }) -test('PluginError', t => { +test('plugin not found', t => { return cli(['test/fixtures/a.css', '-u', 'postcss-plugin', '-o', tmp()]).then( ({ err, code }) => { t.is(code, 1, 'expected non-zero error code') @@ -52,6 +52,19 @@ test('PluginError', t => { ) }) +test('plugin throws on require', t => { + return cli([ + 'test/fixtures/a.css', + '-u', + './test/fixtures/bad-plugin', + '-o', + tmp() + ]).then(({ err, code }) => { + t.is(code, 1, 'expected non-zero error code') + t.regex(err.toString(), /Plugin Error \(.*bad-plugin\): This fails/) + }) +}) + test('CssSyntaxError', t => { return cli(['test/fixtures/a.css', '--parser', 'sugarss', '-o', tmp()]).then( ({ err, code }) => { diff --git a/test/fixtures/bad-plugin.js b/test/fixtures/bad-plugin.js new file mode 100644 index 0000000..2911e95 --- /dev/null +++ b/test/fixtures/bad-plugin.js @@ -0,0 +1 @@ +throw new Error('This fails')