Skip to content

Commit a837a85

Browse files
committed
Added more checks and release on npm
1 parent c5e8dff commit a837a85

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ var postcss = require('gulp-postcss')
1010
var gulp = require('gulp')
1111
var autoprefixer = require('autoprefixer')
1212
var mqpacker = require('css-mqpacker')
13+
var csswring = require('csswring')
1314
1415
gulp.task('css', function () {
1516
var processors = [
1617
autoprefixer('last 1 version').postcss
1718
, mqpacker.processor
19+
, csswring.postcss
1820
]
1921
return gulp.src('./src/*.css')
2022
.pipe(postcss(processors))

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ var gutil = require('gulp-util')
66

77
module.exports = function (processors, options) {
88

9+
if (!Array.isArray(processors)) {
10+
throw new gutil.PluginError('gulp-postcss', 'Please provide array of postcss processors!')
11+
}
12+
913
return through.obj(transform)
1014

1115
function transform (file, encoding, cb) {
1216

17+
if (file.isStream()) {
18+
return cb(new gutil.PluginError('gulp-postcss', 'Streams are not supported!'))
19+
}
20+
1321
// Source map is inline by default
1422
var opts = { map: 'inline' }
1523
var processor = postcss()
@@ -31,14 +39,13 @@ module.exports = function (processors, options) {
3139
opts.from = file.path
3240
}
3341

34-
processors.forEach(processor.use.bind(processor))
35-
3642
// Generate separate source map for gulp-sourcemap
3743
if (file.sourceMap) {
3844
opts.map = true
3945
}
4046

4147
try {
48+
processors.forEach(processor.use.bind(processor))
4249
result = processor.process(file.contents.toString('utf8'), opts)
4350
} catch (err) {
4451
return cb(new gutil.PluginError('gulp-postcss', err))

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-postcss",
3-
"version": "0.0.2",
3+
"version": "1.0.0",
44
"description": "PostCSS gulp plugin",
55
"main": "index.js",
66
"scripts": {
@@ -11,7 +11,7 @@
1111
"url": "https://github.com/w0rm/gulp-postcss.git"
1212
},
1313
"keywords": [
14-
"gulp",
14+
"gulpplugin",
1515
"postcss",
1616
"css"
1717
],

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ it('should correctly wrap postcss errors', function (cb) {
4646
})
4747

4848

49+
it ('should throw error if processors are not provided', function (cb) {
50+
assert.throws( function () { postcss() }, gutil.PluginError )
51+
assert.throws( function () { postcss('') }, gutil.PluginError )
52+
assert.throws( function () { postcss({}) }, gutil.PluginError )
53+
cb()
54+
})
55+
56+
4957
function doubler (css) {
5058
css.eachDecl(function (decl) {
5159
decl.parent.prepend(decl.clone())

0 commit comments

Comments
 (0)