broccoli-postcss
Advanced tools
Comparing version 1.3.0 to 1.3.1
22
index.js
@@ -23,2 +23,3 @@ var path = require('path'); | ||
this.map = map || {}; | ||
this.warningStream = process.stderr; | ||
} | ||
@@ -50,23 +51,22 @@ | ||
processor.process(css, options) | ||
var warningStream = this.warningStream; | ||
return processor.process(css, options) | ||
.then(function (result) { | ||
result.warnings().forEach(function (warn) { | ||
warningStream.write(warn.toString()); | ||
}); | ||
mkdirp.sync(path.dirname(toFilePath)); | ||
fs.writeFileSync(toFilePath, result.css); | ||
}) | ||
.then(function (result) { | ||
result.warnings().forEach(function (warn) { | ||
process.stderr.write(warn.toString()); | ||
}); | ||
}) | ||
.catch(function (error) { | ||
if ( 'CssSyntaxError' === error.name ) { | ||
process.stderr.write(error.message + error.showSourceCode()); | ||
} else { | ||
throw error; | ||
error.message += "\n" + error.showSourceCode(); | ||
} | ||
throw error; | ||
}); | ||
}; | ||
module.exports = PostcssCompiler; |
{ | ||
"name": "broccoli-postcss", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Postcss compiler for Broccoli", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
78
test.js
@@ -6,9 +6,20 @@ var assert = require('assert'); | ||
var postcssCompiler = require('./'); | ||
var pe = require('postcss-pseudoelements'); | ||
var postcss = require('postcss'); | ||
var plugins = [ | ||
var basicPluginSet = [ | ||
{ | ||
module: pe | ||
module: require('postcss-pseudoelements') | ||
} | ||
]; | ||
var testWarnPluginSet = [ | ||
{ | ||
module: postcss.plugin('postcss-test-warn', function (opts) { | ||
return function (css, result) { | ||
result.warn("This is a warning."); | ||
}; | ||
}) | ||
} | ||
]; | ||
var map = { | ||
@@ -19,9 +30,68 @@ inline: false, | ||
var outputTree = postcssCompiler(['fixture'], 'fixture.css', 'output.css', plugins, map); | ||
var warnings = []; | ||
var warningStreamStub = { | ||
write: function (warning) { | ||
warnings.push(warning); | ||
} | ||
}; | ||
beforeEach(function () { | ||
warnings = []; | ||
}); | ||
it('should process css', function () { | ||
var outputTree = postcssCompiler(['fixture'], 'fixture.css', 'output.css', basicPluginSet, map); | ||
outputTree.warningStream = warningStreamStub; | ||
return (new broccoli.Builder(outputTree)).build().then(function (dir) { | ||
var content = fs.readFileSync(path.join(dir.directory, 'output.css'), 'utf8'); | ||
assert.strictEqual(content.trim(), 'a:before { content: "test"; }'); | ||
assert.deepEqual(warnings, []); | ||
}); | ||
}); | ||
it('should expose warnings', function () { | ||
var outputTree = postcssCompiler(['fixture'], 'warning.css', 'output.css', testWarnPluginSet, map); | ||
outputTree.warningStream = warningStreamStub; | ||
return (new broccoli.Builder(outputTree)).build().then(function (dir) { | ||
var content = fs.readFileSync(path.join(dir.directory, 'output.css'), 'utf8'); | ||
assert.strictEqual(content.trim(), "a {}"); | ||
assert.deepEqual(warnings, [ "postcss-test-warn: This is a warning." ]); | ||
}); | ||
}); | ||
it('should expose syntax errors', function () { | ||
var outputTree = postcssCompiler(['fixture'], 'syntax-error.css', 'output.css', testWarnPluginSet, map); | ||
outputTree.warningStream = warningStreamStub; | ||
var count = 0; | ||
return (new broccoli.Builder(outputTree)).build() | ||
.catch(function (error) { | ||
count++; | ||
assert.strictEqual(error.name, "CssSyntaxError"); | ||
}) | ||
.then(function () { | ||
assert.strictEqual(count, 1); | ||
assert.deepEqual(warnings, []); | ||
}); | ||
}); | ||
it('should expose non-syntax errors', function () { | ||
var outputTree = postcssCompiler(['fixture'], 'missing-file.css', 'output.css', testWarnPluginSet, map); | ||
outputTree.warningStream = warningStreamStub; | ||
var count = 0; | ||
return (new broccoli.Builder(outputTree)).build() | ||
.catch(function () { | ||
count++; | ||
}) | ||
.then(function () { | ||
assert.strictEqual(count, 1); | ||
assert.deepEqual(warnings, []); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9081
137
10