Skip to content

Commit

Permalink
Don't process directories or empty files (#71)
Browse files Browse the repository at this point in the history
* don't process directories or empty files

fixes #67.

* add test, bump v, misc.
  • Loading branch information
TheDancingCode authored and scniro committed Apr 23, 2019
1 parent 2c3c22f commit 341d6eb
Show file tree
Hide file tree
Showing 11 changed files with 2,053 additions and 1,931 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
node_modules
test/**/*.generated.*
test/**/*.min.css
.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018 scniro <scniro@outlook.com>
Copyright (c) 2019 scniro <scniro@outlook.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ gulp.task('minify-css',() => {

## License

[MIT](./LICENSE) © 2018 [scniro](https://github.com/scniro)
[MIT](./LICENSE) © 2019 [scniro](https://github.com/scniro)
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = (options, callback) => {

return through.obj(function (file, enc, cb) {

if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
this.emit('error', new PluginError('gulp-clean-css', 'Streaming not supported!'));
return cb(null, file);
Expand All @@ -28,6 +31,7 @@ module.exports = (options, callback) => {
}

new CleanCSS(_options).minify(content, (errors, css) => {

if (errors) {
return cb(errors.join(' '));
}
Expand Down
26 changes: 24 additions & 2 deletions index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,25 @@ describe('gulp-clean-css: base functionality', () => {
});

it('should invoke optional callback with out options object supplied: return object hash', done => {

let called = false;

gulp.src('test/fixtures/test.css')
.pipe(cleanCSS(details => {
.pipe(cleanCSS({}, details => {
called = true;
details.stats.should.exist &&
expect(details).to.have.ownProperty('stats') &&
expect(details).to.have.ownProperty('errors') &&
expect(details).to.have.ownProperty('warnings') &&
expect(details).to.not.have.ownProperty('sourceMap');
}))
.on('data', (file) => {
//
})
.once('end', () => {
expect(called).to.be.true;
done();
});
})
});

it('should invoke optional callback without options object supplied: return object hash with sourceMap: true; return correct hash', done => {
Expand Down Expand Up @@ -240,6 +248,20 @@ describe('gulp-clean-css: base functionality', () => {
done();
})
});

it('should not process empty directories or files', done => {

gulp.src('./test/fixtures/very-empty/**')
.pipe(cleanCSS({}, detail => {
expect(detail.errors).to.be.empty;
}))
.on('data', file => {
//
})
.on('end', () => {
done();
});
})
});

describe('gulp-clean-css: rebase', () => {
Expand Down

0 comments on commit 341d6eb

Please sign in to comment.