-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update plugin example #596
Conversation
@@ -86,13 +86,11 @@ function gulpPrefixer(prefixText) { | |||
file.contents = file.contents.pipe(prefixStream(prefixText)); | |||
} | |||
|
|||
this.push(file); | |||
return callback(); | |||
callback(null, file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use this.push(file);
putting the chunk in the callback isn't documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sindresorhus just put in a PR to document it on through2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@contra the callback function is from the core Streams API proxied through through2. It's not even documented in the core Streams docs. I don't have the time to look into this. But it should be documented in Node core docs before we do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sindresorhus I agree - I raised that complaint in the issue on through2, I'll PR node core as well when I have a minute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@contra did you ever PR node core?
add support for arbitrary node-flags
This was merged into through2 quite awhile ago. @stevelacy can you rebase for a clean merge? |
👍 I'm using it in all my plugins and seems fine :) |
@@ -74,7 +74,7 @@ function gulpPrefixer(prefixText) { | |||
prefixText = new Buffer(prefixText); // allocate ahead of time | |||
|
|||
// Creating a stream through which each file will pass | |||
var stream = through.obj(function(file, enc, callback) { | |||
return through.obj(function(file, enc, callback) { | |||
if (file.isNull()) { | |||
// Do nothing if no contents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be an early callback and return here to make it more clear that you should push the file even if it's null. It's also a better practise in general.
Sexier option parsing example
@phated I updated it. |
Going to merge this today unless someone has issues with it. |
// creating a stream through which each file will pass | ||
var stream = through.obj(function(file, enc, cb) { | ||
// Creating a stream through which each file will pass | ||
return through.obj(function(file, enc, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cb not callback
added some comments |
// creating a stream through which each file will pass | ||
var stream = through.obj(function(file, enc, cb) { | ||
// Creating a stream through which each file will pass | ||
return through.obj(function(file, enc, cb) { | ||
if (file.isNull()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we just skip this whole block?
through.obj