Skip to content

fix browserify transform append #1229

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ module.exports = function(grunt) {
// custom browserify transformer to re-write plugins to
// self-register with Raven via addPlugin
function AddPluginBrowserifyTransformer() {
var noop = function (chunk, _, cb) { cb(null, chunk); };
var append = function (cb) { cb(null, "\nrequire('../src/singleton').addPlugin(module.exports);"); };
return function(file) {
return through(function(buf, enc, next) {
buf = buf.toString('utf8');
if (/plugins/.test(file)) {
buf += "\nrequire('../src/singleton').addPlugin(module.exports);";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just luck that transform is getting called once with one buffer here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? It's completely valid through2 syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so is through(process.exit) doesn't mean it's a good idea.

It's currently just luck that the current code works. If browserify presented you with a stream with multiple chunks you'd intersperse it with these require calls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I completely missed the point and forgot that buffer size is limited. Good catch, thanks

}
this.push(buf);
next();
});
return through(noop, /plugins/.test(file) ? append : undefined);
};
}

Expand Down