@@ -8,7 +8,7 @@ var parseRange = require("range-parser");
8
8
9
9
var HASH_REGEXP = / [ 0 - 9 a - f ] { 10 , } / ;
10
10
11
- var defaultReporter = function ( reporterOptions ) {
11
+ var defaultReporter = function ( reporterOptions ) {
12
12
var state = reporterOptions . state ;
13
13
var stats = reporterOptions . stats ;
14
14
var options = reporterOptions . options ;
@@ -60,12 +60,16 @@ module.exports = function(compiler, options) {
60
60
// We are now on valid state
61
61
state = true ;
62
62
// Do the stuff in nextTick, because bundle may be invalidated
63
- // if a change happend while compiling
63
+ // if a change happened while compiling
64
64
process . nextTick ( function ( ) {
65
65
// check if still in valid state
66
66
if ( ! state ) return ;
67
67
// print webpack output
68
- options . reporter ( { state : true , stats : stats , options : options } ) ;
68
+ options . reporter ( {
69
+ state : true ,
70
+ stats : stats ,
71
+ options : options
72
+ } ) ;
69
73
70
74
// execute callback that are delayed
71
75
var cbs = callbacks ;
@@ -85,10 +89,15 @@ module.exports = function(compiler, options) {
85
89
// on compiling
86
90
function invalidPlugin ( ) {
87
91
if ( state && ( ! options . noInfo && ! options . quiet ) )
88
- options . reporter ( { state : false , options : options } )
92
+ options . reporter ( {
93
+ state : false ,
94
+ options : options
95
+ } )
96
+
89
97
// We are now in invalid state
90
98
state = false ;
91
99
}
100
+
92
101
function invalidAsyncPlugin ( compiler , callback ) {
93
102
invalidPlugin ( ) ;
94
103
callback ( ) ;
@@ -135,7 +144,7 @@ module.exports = function(compiler, options) {
135
144
}
136
145
137
146
function pathJoin ( a , b ) {
138
- return a == "/" ? "/" + b : ( a || "" ) + "/" + b
147
+ return a == "/" ? "/" + b : ( a || "" ) + "/" + b
139
148
}
140
149
141
150
function getFilenameFromUrl ( url ) {
@@ -157,19 +166,19 @@ module.exports = function(compiler, options) {
157
166
}
158
167
159
168
function handleRangeHeaders ( content , req , res ) {
160
- if ( req . headers [ 'Accept-Ranges' ] ) res . setHeader ( 'Accept-Ranges' , 'bytes' ) ;
161
- if ( req . headers . range ) {
169
+ if ( req . headers [ 'Accept-Ranges' ] ) res . setHeader ( 'Accept-Ranges' , 'bytes' ) ;
170
+ if ( req . headers . range ) {
162
171
var ranges = parseRange ( content . length , req . headers . range ) ;
163
172
164
173
// unsatisfiable
165
- if ( - 1 == ranges ) {
174
+ if ( - 1 == ranges ) {
166
175
res . setHeader ( 'Content-Range' , 'bytes */' + content . length ) ;
167
176
res . statusCode = 416 ;
168
177
return content ;
169
178
}
170
179
171
180
// valid (syntactically invalid/multiple ranges are treated as a regular response)
172
- if ( - 2 != ranges && ranges . length === 1 ) {
181
+ if ( - 2 != ranges && ranges . length === 1 ) {
173
182
// Content-Range
174
183
res . statusCode = 206 ;
175
184
var length = content . length ;
@@ -187,7 +196,7 @@ module.exports = function(compiler, options) {
187
196
// The middleware function
188
197
function webpackDevMiddleware ( req , res , next ) {
189
198
var filename = getFilenameFromUrl ( req . url ) ;
190
- if ( filename === false ) return next ( ) ;
199
+ if ( filename === false ) return next ( ) ;
191
200
192
201
// in lazy mode, rebuild on bundle request
193
202
if ( options . lazy && ( ! options . filename || options . filename . test ( filename ) ) )
@@ -203,11 +212,12 @@ module.exports = function(compiler, options) {
203
212
}
204
213
// delay the request until we have a vaild bundle
205
214
ready ( processRequest , req ) ;
215
+
206
216
function processRequest ( ) {
207
217
try {
208
218
var stat = fs . statSync ( filename ) ;
209
219
if ( ! stat . isFile ( ) ) {
210
- if ( stat . isDirectory ( ) ) {
220
+ if ( stat . isDirectory ( ) ) {
211
221
filename = pathJoin ( filename , "index.html" ) ;
212
222
stat = fs . statSync ( filename ) ;
213
223
if ( ! stat . isFile ( ) ) throw "next" ;
@@ -231,21 +241,21 @@ module.exports = function(compiler, options) {
231
241
}
232
242
}
233
243
res . statusCode = 200 ;
234
- if ( res . send ) res . send ( content ) ;
244
+ if ( res . send ) res . send ( content ) ;
235
245
else res . end ( content ) ;
236
246
}
237
247
}
238
248
239
249
webpackDevMiddleware . getFilenameFromUrl = getFilenameFromUrl ;
240
250
241
251
webpackDevMiddleware . waitUntilValid = function ( callback ) {
242
- callback = callback || function ( ) { } ;
243
- if ( ! watching || ! watching . running ) callback ( ) ;
252
+ callback = callback || function ( ) { } ;
253
+ if ( ! watching || ! watching . running ) callback ( ) ;
244
254
else ready ( callback , { } ) ;
245
255
} ;
246
256
247
257
webpackDevMiddleware . invalidate = function ( callback ) {
248
- callback = callback || function ( ) { } ;
258
+ callback = callback || function ( ) { } ;
249
259
if ( watching ) {
250
260
ready ( callback , { } ) ;
251
261
watching . invalidate ( ) ;
@@ -255,7 +265,7 @@ module.exports = function(compiler, options) {
255
265
} ;
256
266
257
267
webpackDevMiddleware . close = function ( callback ) {
258
- callback = callback || function ( ) { } ;
268
+ callback = callback || function ( ) { } ;
259
269
if ( watching ) watching . close ( callback ) ;
260
270
else callback ( ) ;
261
271
} ;
0 commit comments