Skip to content

Commit

Permalink
Fix error message when resolving relative and module is not found (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored and ben-eb committed Jun 22, 2016
1 parent 12dbde8 commit 79d096a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fixtures/error.css
@@ -0,0 +1,3 @@
@use postcss-fourohfour;

.foo {background: blue;color: red;}
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -85,6 +85,10 @@ module.exports = postcss.plugin('postcss-use', function (opts) {
pluginPath = resolveFrom(path.dirname(rule.source.input.file), plugin);
}

if (!pluginPath) {
throw new Error('Cannot find module \'' + plugin + '\'');
}

var instance = require(pluginPath)(pluginOpts);
if (instance.plugins) {
instance.plugins.forEach(function (p) {
Expand Down
15 changes: 15 additions & 0 deletions test.js
Expand Up @@ -115,6 +115,21 @@ tape('should use plugins relative to CSS file when using resolveFromFile', funct
}).catch(t.ifError);
});

tape('should give meaningful error when module is not found', function (t) {
var inputFile = path.join(__dirname, 'fixtures', 'error.css');
var outputFile = path.join(__dirname, 'fixtures', 'error.out.css');
var inputCss = fs.readFileSync(inputFile);
postcss(plugin({modules: '*', resolveFromFile: true})).process(inputCss, {
from: inputFile,
to: outputFile
}).then(function () {
t.fail('Should fail when referencing plugin that is not installed');
}).catch(function (err) {
t.equal(err.message, 'Cannot find module \'postcss-fourohfour\'');
t.end();
});
});

tape('should not resolve plugins relative to CSS file by default', function (t) {
var inputFile = path.join(__dirname, 'fixtures', 'test.css');
var outputFile = path.join(__dirname, 'fixtures', 'test.out.css');
Expand Down

0 comments on commit 79d096a

Please sign in to comment.