11// Some css-modules-loader-code dependencies use Promise so we'll provide it for older node versions
2- if ( ! global . Promise ) { global . Promise = require ( 'promise-polyfill' ) }
2+ if ( ! global . Promise ) { global . Promise = require ( 'promise-polyfill' ) ; }
33
44var fs = require ( 'fs' ) ;
55var path = require ( 'path' ) ;
@@ -145,7 +145,7 @@ module.exports = function (browserify, options) {
145145 // get (or create) a loader for this entry file
146146 var loader = loadersByFile [ sourceKey ] ;
147147 if ( ! loader ) {
148- loader = loadersByFile [ sourceKey ] = new FileSystemLoader ( rootDir , plugins ) ;
148+ loader = loadersByFile [ sourceKey ] = new FileSystemLoader ( rootDir , plugins ) ;
149149 }
150150
151151 // the compiled CSS stream needs to be avalible to the transform,
@@ -162,17 +162,15 @@ module.exports = function (browserify, options) {
162162
163163 // convert css to js before pushing
164164 // reset the `tokensByFile` cache
165- var relFilename = path . relative ( rootDir , filename )
165+ var relFilename = path . relative ( rootDir , filename ) ;
166166 tokensByFile [ filename ] = loader . tokensByFile [ filename ] = null ;
167167
168168 loader . fetch ( relFilename , '/' ) . then ( function ( tokens ) {
169169 var deps = loader . deps . dependenciesOf ( filename ) ;
170- var output = [
171- deps . map ( function ( f ) {
172- return "require('" + f + "')"
173- } ) . join ( '\n' ) ,
174- 'module.exports = ' + JSON . stringify ( tokens )
175- ] . join ( '\n' ) ;
170+ var output = deps . map ( function ( f ) {
171+ return 'require("' + f + '")' ;
172+ } ) ;
173+ output . push ( 'module.exports = ' + JSON . stringify ( tokens ) ) ;
176174
177175 var isValid = true ;
178176 var isUndefined = / \b u n d e f i n e d \b / ;
@@ -184,18 +182,18 @@ module.exports = function (browserify, options) {
184182
185183 if ( ! isValid ) {
186184 var err = 'Composition in ' + filename + ' contains an undefined reference' ;
187- console . error ( err )
188- output += '\nconsole .error("' + err + '");' ;
185+ console . error ( err ) ;
186+ output . push ( 'console .error("' + err + '");' ) ;
189187 }
190188
191189 assign ( tokensByFile , loader . tokensByFile ) ;
192190
193- self . push ( output ) ;
194- return callback ( )
191+ self . push ( output . join ( '\n' ) ) ;
192+ return callback ( ) ;
195193 } ) . catch ( function ( err ) {
196194 self . push ( 'console.error("' + err + '");' ) ;
197195 browserify . emit ( 'error' , err ) ;
198- return callback ( )
196+ return callback ( ) ;
199197 } ) ;
200198 } ;
201199
0 commit comments