Skip to content

Commit 341d6eb

Browse files
TheDancingCodescniro
authored andcommitted
Don't process directories or empty files (#71)
* don't process directories or empty files fixes #67. * add test, bump v, misc.
1 parent 2c3c22f commit 341d6eb

File tree

11 files changed

+2053
-1931
lines changed

11 files changed

+2053
-1931
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
node_modules
44
test/**/*.generated.*
55
test/**/*.min.css
6+
.DS_Store

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018 scniro <[email protected]>
1+
Copyright (c) 2019 scniro <[email protected]>
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ gulp.task('minify-css',() => {
7676

7777
## License
7878

79-
[MIT](./LICENSE) © 2018 [scniro](https://github.com/scniro)
79+
[MIT](./LICENSE) © 2019 [scniro](https://github.com/scniro)

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ module.exports = (options, callback) => {
1111

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

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

3033
new CleanCSS(_options).minify(content, (errors, css) => {
34+
3135
if (errors) {
3236
return cb(errors.join(' '));
3337
}

index.spec.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,25 @@ describe('gulp-clean-css: base functionality', () => {
138138
});
139139

140140
it('should invoke optional callback with out options object supplied: return object hash', done => {
141+
142+
let called = false;
143+
141144
gulp.src('test/fixtures/test.css')
142-
.pipe(cleanCSS(details => {
145+
.pipe(cleanCSS({}, details => {
146+
called = true;
143147
details.stats.should.exist &&
144148
expect(details).to.have.ownProperty('stats') &&
145149
expect(details).to.have.ownProperty('errors') &&
146150
expect(details).to.have.ownProperty('warnings') &&
147151
expect(details).to.not.have.ownProperty('sourceMap');
148152
}))
149153
.on('data', (file) => {
154+
//
155+
})
156+
.once('end', () => {
157+
expect(called).to.be.true;
150158
done();
151-
});
159+
})
152160
});
153161

154162
it('should invoke optional callback without options object supplied: return object hash with sourceMap: true; return correct hash', done => {
@@ -240,6 +248,20 @@ describe('gulp-clean-css: base functionality', () => {
240248
done();
241249
})
242250
});
251+
252+
it('should not process empty directories or files', done => {
253+
254+
gulp.src('./test/fixtures/very-empty/**')
255+
.pipe(cleanCSS({}, detail => {
256+
expect(detail.errors).to.be.empty;
257+
}))
258+
.on('data', file => {
259+
//
260+
})
261+
.on('end', () => {
262+
done();
263+
});
264+
})
243265
});
244266

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

0 commit comments

Comments
 (0)