@@ -9,7 +9,7 @@ var FileSystemLoader = require('./file-system-loader');
99var assign = require ( 'object-assign' ) ;
1010var stringHash = require ( 'string-hash' ) ;
1111var 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} ;
0 commit comments