1
1
// 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' ) ; }
3
3
4
4
var fs = require ( 'fs' ) ;
5
5
var path = require ( 'path' ) ;
@@ -145,7 +145,7 @@ module.exports = function (browserify, options) {
145
145
// get (or create) a loader for this entry file
146
146
var loader = loadersByFile [ sourceKey ] ;
147
147
if ( ! loader ) {
148
- loader = loadersByFile [ sourceKey ] = new FileSystemLoader ( rootDir , plugins ) ;
148
+ loader = loadersByFile [ sourceKey ] = new FileSystemLoader ( rootDir , plugins ) ;
149
149
}
150
150
151
151
// the compiled CSS stream needs to be avalible to the transform,
@@ -162,17 +162,15 @@ module.exports = function (browserify, options) {
162
162
163
163
// convert css to js before pushing
164
164
// reset the `tokensByFile` cache
165
- var relFilename = path . relative ( rootDir , filename )
165
+ var relFilename = path . relative ( rootDir , filename ) ;
166
166
tokensByFile [ filename ] = loader . tokensByFile [ filename ] = null ;
167
167
168
168
loader . fetch ( relFilename , '/' ) . then ( function ( tokens ) {
169
169
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 ) ) ;
176
174
177
175
var isValid = true ;
178
176
var isUndefined = / \b u n d e f i n e d \b / ;
@@ -184,18 +182,18 @@ module.exports = function (browserify, options) {
184
182
185
183
if ( ! isValid ) {
186
184
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 + '");' ) ;
189
187
}
190
188
191
189
assign ( tokensByFile , loader . tokensByFile ) ;
192
190
193
- self . push ( output ) ;
194
- return callback ( )
191
+ self . push ( output . join ( '\n' ) ) ;
192
+ return callback ( ) ;
195
193
} ) . catch ( function ( err ) {
196
194
self . push ( 'console.error("' + err + '");' ) ;
197
195
browserify . emit ( 'error' , err ) ;
198
- return callback ( )
196
+ return callback ( ) ;
199
197
} ) ;
200
198
} ;
201
199
0 commit comments