webpack-dev-middleware
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -8,2 +8,4 @@ /* | ||
var parseRange = require("range-parser"); | ||
var getFilenameFromUrl = require("./lib/GetFilenameFromUrl"); | ||
var pathJoin = require("./lib/PathJoin"); | ||
@@ -24,3 +26,3 @@ var HASH_REGEXP = /[0-9a-f]{10,}/; | ||
if(displayStats) { | ||
console.log(stats.toString(options.stats)) | ||
console.log(stats.toString(options.stats)); | ||
} | ||
@@ -33,3 +35,3 @@ if(!options.noInfo && !options.quiet) { | ||
} | ||
} | ||
}; | ||
@@ -59,3 +61,9 @@ // constructor for the middleware | ||
// store our files in memory | ||
var fs = compiler.outputFileSystem = new MemoryFileSystem(); | ||
var fs; | ||
var isMemoryFs = compiler.outputFileSystem instanceof MemoryFileSystem; | ||
if(isMemoryFs) { | ||
fs = compiler.outputFileSystem; | ||
} else { | ||
fs = compiler.outputFileSystem = new MemoryFileSystem(); | ||
} | ||
@@ -65,3 +73,3 @@ compiler.plugin("done", function(stats) { | ||
state = true; | ||
webpackStats = stats | ||
webpackStats = stats; | ||
@@ -83,3 +91,3 @@ // Do the stuff in nextTick, because bundle may be invalidated | ||
callbacks = []; | ||
cbs.forEach(function continueBecauseBundleAvailible(cb) { | ||
cbs.forEach(function continueBecauseBundleAvailable(cb) { | ||
cb(); | ||
@@ -102,3 +110,3 @@ }); | ||
options: options | ||
}) | ||
}); | ||
@@ -156,24 +164,2 @@ // We are now in invalid state | ||
function pathJoin(a, b) { | ||
return a == "/" ? "/" + b : (a || "") + "/" + b | ||
} | ||
function getFilenameFromUrl(url) { | ||
// publicPrefix is the folder our bundle should be in | ||
var localPrefix = options.publicPath || "/"; | ||
if(url.indexOf(localPrefix) !== 0) { | ||
if(/^(https?:)?\/\//.test(localPrefix)) { | ||
localPrefix = "/" + localPrefix.replace(/^(https?:)?\/\/[^\/]+\//, ""); | ||
// fast exit if another directory requested | ||
if(url.indexOf(localPrefix) !== 0) return false; | ||
} else return false; | ||
} | ||
// get filename from request | ||
var filename = url.substr(localPrefix.length); | ||
if(filename.indexOf("?") >= 0) { | ||
filename = filename.substr(0, filename.indexOf("?")); | ||
} | ||
return filename ? pathJoin(compiler.outputPath, filename) : compiler.outputPath; | ||
} | ||
function handleRangeHeaders(content, req, res) { | ||
@@ -188,3 +174,2 @@ res.setHeader('Accept-Ranges', 'bytes'); | ||
res.statusCode = 416; | ||
return content; | ||
} | ||
@@ -211,7 +196,7 @@ | ||
function goNext() { | ||
if(!options.serverSideRender) return next() | ||
if(!options.serverSideRender) return next(); | ||
ready(function() { | ||
res.locals.webpackStats = webpackStats | ||
next() | ||
}, req) | ||
res.locals.webpackStats = webpackStats; | ||
next(); | ||
}, req); | ||
} | ||
@@ -223,3 +208,3 @@ | ||
var filename = getFilenameFromUrl(req.url); | ||
var filename = getFilenameFromUrl(options.publicPath, compiler.outputPath, req.url); | ||
if(filename === false) return goNext(); | ||
@@ -239,3 +224,3 @@ | ||
} | ||
// delay the request until we have a vaild bundle | ||
// delay the request until we have a valid bundle | ||
ready(processRequest, req); | ||
@@ -248,3 +233,3 @@ | ||
if(stat.isDirectory()) { | ||
filename = pathJoin(filename, "index.html"); | ||
filename = pathJoin(filename, options.index || "index.html"); | ||
stat = fs.statSync(filename); | ||
@@ -271,3 +256,4 @@ if(!stat.isFile()) throw "next"; | ||
} | ||
res.statusCode = 200; | ||
// Express automatically sets the statusCode to 200, but not all servers do (Koa). | ||
res.statusCode = res.statusCode || 200; | ||
if(res.send) res.send(content); | ||
@@ -278,3 +264,3 @@ else res.end(content); | ||
webpackDevMiddleware.getFilenameFromUrl = getFilenameFromUrl; | ||
webpackDevMiddleware.getFilenameFromUrl = getFilenameFromUrl.bind(this, options.publicPath, compiler.outputPath); | ||
@@ -305,2 +291,2 @@ webpackDevMiddleware.waitUntilValid = function(callback) { | ||
return webpackDevMiddleware; | ||
} | ||
}; |
{ | ||
"name": "webpack-dev-middleware", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -15,10 +15,15 @@ "description": "Offers a dev middleware for webpack, which arguments a live bundle to a directory", | ||
"devDependencies": { | ||
"eslint": "^3.4.0" | ||
"codecov.io": "^0.1.6", | ||
"eslint": "^3.4.0", | ||
"express": "^4.14.0", | ||
"file-loader": "^0.9.0", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.0.2", | ||
"mocha-sinon": "^1.1.6", | ||
"should": "^11.1.0", | ||
"sinon": "^1.17.5", | ||
"supertest": "^2.0.0", | ||
"webpack": "^2.1.0-beta.22" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
} | ||
], | ||
"license": "MIT", | ||
"engines": { | ||
@@ -33,7 +38,14 @@ "node": ">=0.6" | ||
}, | ||
"files": [ | ||
"middleware.js", | ||
"lib/" | ||
], | ||
"scripts": { | ||
"lint": "eslint *.js", | ||
"lint": "eslint *.js lib test", | ||
"pretest": "npm run -s lint", | ||
"test": "mocha --full-trace --check-leaks", | ||
"beautify": "npm run lint -- --fix", | ||
"travis": "npm run lint && node middleware.js" | ||
"cover": "istanbul cover node_modules/mocha/bin/_mocha", | ||
"travis": "npm run cover -- --report lcovonly && npm run lint" | ||
} | ||
} |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
272
0
10615
11
5
1
0