Skip to content

Commit c0196fd

Browse files
committed
fixed stream issue
1 parent fc65803 commit c0196fd

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

index.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var FileSystemLoader = require('./file-system-loader');
99
var assign = require('object-assign');
1010
var stringHash = require('string-hash');
1111
var ReadableStream = require('stream').Readable;
12-
var through = require('through');
12+
var through = require('through2');
1313

1414
/*
1515
Custom `generateScopedName` function for `postcss-modules-scope`.
@@ -201,14 +201,17 @@ module.exports = function (browserify, options) {
201201

202202
// ----
203203

204-
browserify.on('bundle', function (bundle) {
205-
// on each bundle, create a new stream b/c the old one might have ended
206-
var compiledCssStream = new ReadableStream();
207-
compiledCssStream._read = function () {};
204+
function addHooks () {
205+
browserify.pipeline.get('pack').push(through(function write (row, enc, next) {
206+
next(null, row)
207+
}, function end (cb) {
208208

209-
browserify.emit('css stream', compiledCssStream);
209+
// on each bundle, create a new stream b/c the old one might have ended
210+
var compiledCssStream = new ReadableStream();
211+
compiledCssStream._read = function () {};
212+
213+
browserify.emit('css stream', compiledCssStream);
210214

211-
browserify.pipeline.get('pack').push(through(null, function () {
212215
// Combine the collected sources for a single bundle into a single CSS file
213216
var self = this;
214217
var loader = loadersByFile[cssOutFilename];
@@ -229,13 +232,14 @@ module.exports = function (browserify, options) {
229232
if (jsonOutFilename) {
230233
writes.push(writeFile(jsonOutFilename, JSON.stringify(normalizeManifestPaths(tokensByFile, rootDir))));
231234
}
232-
233235
Promise.all(writes)
234-
.then(function () { self.queue(null); })
235-
.catch(function (err) { self.emit('error', err); })
236+
.then(function () { cb(); })
237+
.catch(function (err) { self.emit('error', err); cb() })
236238
}));
237-
});
239+
}
238240

241+
browserify.on('reset', addHooks);
242+
addHooks();
239243

240244
return browserify;
241245
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"promise-polyfill": "^2.1.0",
1111
"resolve": "^1.1.7",
1212
"string-hash": "^1.1.0",
13-
"through": "^2.3.7"
13+
"through2": "^2.0.1"
1414
},
1515
"devDependencies": {
1616
"browserify": "^11.0.1",

tests/stream-output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tape('stream output', function (t) {
2525
fs: fakeFs
2626
});
2727

28-
t.plan(cssFilesTotal * 2 + 1);
28+
t.plan(cssFilesTotal * 2 + 2);
2929

3030
var cssFilesCount = 0;
3131
var b = browserify(path.join(simpleCaseDir, 'main.js'));

0 commit comments

Comments
 (0)