Skip to content

Commit 074fc05

Browse files
committed
Update index.js
Two things: 1) Reverting back to browserify's original bundle method. This method is only intended to take a singular callback argument. 2) stream.on('end', function () {}) creates a race condition. Using a callback in the bundle method instead to resolve this.
1 parent 6b1a8dd commit 074fc05

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,20 @@ module.exports = function (browserify, options) {
108108

109109
// wrap the `bundle` function
110110
var bundle = browserify.bundle;
111-
browserify.bundle = function (opts, cb) {
111+
browserify.bundle = function (cb) {
112112
// reset the `tokensByFile` cache
113113
tokensByFile = {};
114114

115115
// call the original
116-
var stream = bundle.apply(browserify, arguments);
117-
118-
// close the css stream
119-
stream.on('end', function () {
116+
var stream = bundle.call(browserify, function () {
120117
// Combine the collected sources into a single CSS file
121118
var css = Object.keys(sourceByFile).map(function(file) {
122119
return sourceByFile[file];
123120
}).join('\n');
121+
var args = arguments;
124122

125-
fs.writeFile(cssOutFilename, css, function(err) {
126-
if (err) console.error(err);
123+
fs.writeFile(cssOutFilename, css, function () {
124+
if (typeof cb === 'function') cb.apply(null, args);
127125
});
128126
});
129127

0 commit comments

Comments
 (0)