Socket
Socket
Sign inDemoInstall

webpack-dev-middleware

Package Overview
Dependencies
Maintainers
4
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-dev-middleware - npm Package Compare versions

Comparing version 3.6.1 to 3.6.2

10

CHANGELOG.md

@@ -5,2 +5,12 @@ # Change Log

<a name="3.6.2"></a>
## [3.6.2](https://github.com/webpack/webpack-dev-middleware/compare/v3.6.1...v3.6.2) (2019-04-03)
### Bug Fixes
* check existence of `res.getHeader` and set the correct Content-Type ([#385](https://github.com/webpack/webpack-dev-middleware/issues/385)) ([56dc705](https://github.com/webpack/webpack-dev-middleware/commit/56dc705))
## [3.6.1](https://github.com/webpack/webpack-dev-middleware/compare/v3.6.0...v3.6.1) (2019-03-06)

@@ -7,0 +17,0 @@

26

index.js
'use strict';
const mime = require('mime');
const createContext = require('./lib/context');

@@ -18,8 +19,8 @@ const middleware = require('./lib/middleware');

colors: true,
context: process.cwd()
context: process.cwd(),
},
watchOptions: {
aggregateTimeout: 200
aggregateTimeout: 200,
},
writeToDisk: false
writeToDisk: false,
};

@@ -34,3 +35,3 @@

.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') // eslint-disable-line no-useless-escape
.replace(/\\\[[a-z]+\\\]/ig, '.+');
.replace(/\\\[[a-z]+\\\]/gi, '.+');

@@ -52,3 +53,3 @@ options.filename = new RegExp(`^[/]{0,1}${filename}$`);

if (!options.lazy) {
const watching = compiler.watch(options.watchOptions, (err) => {
context.watching = compiler.watch(options.watchOptions, (err) => {
if (err) {

@@ -61,4 +62,2 @@ context.log.error(err.stack || err);

});
context.watching = watching;
} else {

@@ -76,2 +75,3 @@ context.state = true;

close(callback) {
// eslint-disable-next-line no-param-reassign
callback = callback || noop;

@@ -90,6 +90,12 @@

getFilenameFromUrl: getFilenameFromUrl.bind(this, context.options.publicPath, context.compiler),
getFilenameFromUrl: getFilenameFromUrl.bind(
this,
context.options.publicPath,
context.compiler
),
invalidate(callback) {
// eslint-disable-next-line no-param-reassign
callback = callback || noop;
if (context.watching) {

@@ -104,6 +110,8 @@ ready(context, callback, {});

waitUntilValid(callback) {
// eslint-disable-next-line no-param-reassign
callback = callback || noop;
ready(context, callback, {});
}
},
});
};

@@ -13,3 +13,3 @@ 'use strict';

watching: null,
forceRebuild: false
forceRebuild: false,
};

@@ -23,3 +23,3 @@

name: 'wdm',
timestamp: options.logTime
timestamp: options.logTime,
});

@@ -47,3 +47,3 @@ }

state: true,
stats
stats,
});

@@ -70,3 +70,3 @@

log,
state: false
state: false,
});

@@ -102,7 +102,10 @@ }

context.compiler.hooks.done.tap('WebpackDevMiddleware', done);
context.compiler.hooks.watchRun.tap('WebpackDevMiddleware', (comp, callback) => {
invalid(callback);
});
context.compiler.hooks.watchRun.tap(
'WebpackDevMiddleware',
(comp, callback) => {
invalid(callback);
}
);
return context;
};
'use strict';
module.exports = class DevMiddlewareError extends Error {
};
module.exports = class DevMiddlewareError extends Error {};

@@ -5,5 +5,7 @@ 'use strict';

const path = require('path');
const MemoryFileSystem = require('memory-fs');
const { colors } = require('webpack-log');
const NodeOutputFileSystem = require('webpack/lib/node/NodeOutputFileSystem');
const DevMiddlewareError = require('./DevMiddlewareError');

@@ -36,4 +38,7 @@

const targetPath = path.isAbsolute(targetFile) ? targetFile : path.join(outputPath, targetFile);
const allowWrite = filter && typeof filter === 'function' ? filter(targetPath) : true;
const targetPath = path.isAbsolute(targetFile)
? targetFile
: path.join(outputPath, targetFile);
const allowWrite =
filter && typeof filter === 'function' ? filter(targetPath) : true;

@@ -58,3 +63,10 @@ if (allowWrite) {

log.debug(colors.cyan(`Asset written to disk: ${path.relative(process.cwd(), targetPath)}`));
log.debug(
colors.cyan(
`Asset written to disk: ${path.relative(
process.cwd(),
targetPath
)}`
)
);
} catch (e) {

@@ -70,4 +82,10 @@ log.error(`Unable to write asset to disk:\n${e}`);

setFs(context, compiler) {
if (typeof compiler.outputPath === 'string' && !path.posix.isAbsolute(compiler.outputPath) && !path.win32.isAbsolute(compiler.outputPath)) {
throw new DevMiddlewareError('`output.path` needs to be an absolute path or `/`.');
if (
typeof compiler.outputPath === 'string' &&
!path.posix.isAbsolute(compiler.outputPath) &&
!path.win32.isAbsolute(compiler.outputPath)
) {
throw new DevMiddlewareError(
'`output.path` needs to be an absolute path or `/`.'
);
}

@@ -79,5 +97,6 @@

const isConfiguredFs = context.options.fs;
const isMemoryFs = !isConfiguredFs
&& !compiler.compilers
&& compiler.outputFileSystem instanceof MemoryFileSystem;
const isMemoryFs =
!isConfiguredFs &&
!compiler.compilers &&
compiler.outputFileSystem instanceof MemoryFileSystem;

@@ -90,5 +109,8 @@ if (isConfiguredFs) {

// very shallow check
throw new Error('Invalid options: options.fs.join() method is expected');
throw new Error(
'Invalid options: options.fs.join() method is expected'
);
}
// eslint-disable-next-line no-param-reassign
compiler.outputFileSystem = fs;

@@ -100,7 +122,10 @@ fileSystem = fs;

fileSystem = new MemoryFileSystem();
// eslint-disable-next-line no-param-reassign
compiler.outputFileSystem = fileSystem;
}
// eslint-disable-next-line no-param-reassign
context.fs = fileSystem;
}
},
};
'use strict';
const path = require('path');
const mime = require('mime');
const DevMiddlewareError = require('./DevMiddlewareError');
const { getFilenameFromUrl, handleRangeHeaders, handleRequest, ready } = require('./util');
const {
getFilenameFromUrl,
handleRangeHeaders,
handleRequest,
ready,
} = require('./util');

@@ -16,2 +23,3 @@ // Do not add a charset to the Content-Type header of these file types

// undefined.
// eslint-disable-next-line no-param-reassign
res.locals = res.locals || {};

@@ -24,12 +32,20 @@

return new Promise(((resolve) => {
ready(context, () => {
res.locals.webpackStats = context.webpackStats;
res.locals.fs = context.fs;
resolve(next());
}, req);
}));
return new Promise((resolve) => {
ready(
context,
() => {
// eslint-disable-next-line no-param-reassign
res.locals.webpackStats = context.webpackStats;
// eslint-disable-next-line no-param-reassign
res.locals.fs = context.fs;
resolve(next());
},
req
);
});
}
const acceptedMethods = context.options.methods || ['GET'];
if (acceptedMethods.indexOf(req.method) === -1) {

@@ -39,3 +55,7 @@ return goNext();

let filename = getFilenameFromUrl(context.options.publicPath, context.compiler, req.url);
let filename = getFilenameFromUrl(
context.options.publicPath,
context.compiler,
req.url
);

@@ -46,4 +66,5 @@ if (filename === false) {

return new Promise(((resolve) => {
return new Promise((resolve) => {
handleRequest(context, filename, processRequest, req);
// eslint-disable-next-line consistent-return
function processRequest() {

@@ -57,2 +78,3 @@ try {

// eslint-disable-next-line no-undefined
if (index === undefined || index === true) {

@@ -66,2 +88,3 @@ index = 'index.html';

stat = context.fs.statSync(filename);
if (!stat.isFile()) {

@@ -80,2 +103,3 @@ throw new DevMiddlewareError('next');

let content = context.fs.readFileSync(filename);
content = handleRangeHeaders(content, req, res);

@@ -89,8 +113,10 @@

if (!res.getHeader('Content-Type')) {
if (!res.getHeader || !res.getHeader('Content-Type')) {
res.setHeader('Content-Type', contentType);
}
res.setHeader('Content-Length', content.length);
const { headers } = context.options;
if (headers) {

@@ -103,10 +129,17 @@ for (const name in headers) {

}
// Express automatically sets the statusCode to 200, but not all servers do (Koa).
// eslint-disable-next-line no-param-reassign
res.statusCode = res.statusCode || 200;
if (res.send) res.send(content);
else res.end(content);
if (res.send) {
res.send(content);
} else {
res.end(content);
}
resolve();
}
}));
});
};
};

@@ -7,3 +7,3 @@ 'use strict';

if (state) {
const displayStats = (middlewareOptions.stats !== false);
const displayStats = middlewareOptions.stats !== false;

@@ -10,0 +10,0 @@ if (displayStats) {

@@ -6,2 +6,3 @@ 'use strict';

const querystring = require('querystring');
const parseRange = require('range-parser');

@@ -22,5 +23,6 @@

for (let i = 0; i < compilers.length; i++) {
compilerPublicPath = compilers[i].options
&& compilers[i].options.output
&& compilers[i].options.output.publicPath;
compilerPublicPath =
compilers[i].options &&
compilers[i].options.output &&
compilers[i].options.output.publicPath;

@@ -39,3 +41,3 @@ if (compilerPublicPath) {

publicPath: compilerPublicPath,
outputPath: compilers[i].outputPath
outputPath: compilers[i].outputPath,
};

@@ -48,6 +50,7 @@ }

publicPath,
outputPath: compiler.outputPath
outputPath: compiler.outputPath,
};
}
// eslint-disable-next-line consistent-return
function ready(context, fn, req) {

@@ -71,4 +74,7 @@ if (context.state) {

// publicPath has the hostname that is not the same as request url's, should fail
if (localPrefix.hostname !== null && urlObject.hostname !== null &&
localPrefix.hostname !== urlObject.hostname) {
if (
localPrefix.hostname !== null &&
urlObject.hostname !== null &&
localPrefix.hostname !== urlObject.hostname
) {
return false;

@@ -78,4 +84,7 @@ }

// publicPath is not in url, so it should fail
if (publicPath && localPrefix.hostname === urlObject.hostname &&
url.indexOf(publicPath) !== 0) {
if (
publicPath &&
localPrefix.hostname === urlObject.hostname &&
url.indexOf(publicPath) !== 0
) {
return false;

@@ -89,4 +98,7 @@ }

if (!urlObject.hostname && localPrefix.hostname &&
url.indexOf(localPrefix.path) !== 0) {
if (
!urlObject.hostname &&
localPrefix.hostname &&
url.indexOf(localPrefix.path) !== 0
) {
return false;

@@ -101,3 +113,3 @@ }

if (filename) {
uri = path.posix.join((outputPath || ''), querystring.unescape(filename));
uri = path.posix.join(outputPath || '', querystring.unescape(filename));

@@ -114,3 +126,3 @@ if (!path.win32.isAbsolute(uri)) {

if (filename) {
uri = path.posix.join((outputPath || ''), filename);
uri = path.posix.join(outputPath || '', filename);

@@ -137,2 +149,3 @@ if (!path.posix.isAbsolute(uri)) {

res.setHeader('Content-Range', `bytes */${content.length}`);
// eslint-disable-next-line no-param-reassign
res.statusCode = 416;

@@ -147,2 +160,3 @@ }

// Content-Range
// eslint-disable-next-line no-param-reassign
res.statusCode = 206;

@@ -154,2 +168,3 @@ res.setHeader(

// eslint-disable-next-line no-param-reassign
content = content.slice(ranges[0].start, ranges[0].end + 1);

@@ -164,3 +179,6 @@ }

// in lazy mode, rebuild on bundle request
if (context.options.lazy && (!context.options.filename || context.options.filename.test(filename))) {
if (
context.options.lazy &&
(!context.options.filename || context.options.filename.test(filename))
) {
context.rebuild();

@@ -185,3 +203,3 @@ }

ready
ready,
};
{
"name": "webpack-dev-middleware",
"version": "3.6.1",
"version": "3.6.2",
"description": "A development middleware for webpack",
"license": "MIT",
"repository": "https://github.com/webpack/webpack-dev-middleware.git",
"author": "Tobias Koppers @sokra",
"homepage": "https://github.com/webpack/webpack-dev-middleware",
"bugs": "https://github.com/webpack/webpack-dev-middleware/issues",
"main": "index.js",
"files": [
"lib",
"index.js"
],
"engines": {

@@ -15,5 +16,12 @@ "node": ">= 6"

"lint": "eslint index.js lib test",
"test": "nyc --reporter lcovonly mocha --full-trace --check-leaks --exit",
"pretest": "npm run lint",
"test:only": "jest",
"test:coverage": "jest --coverage",
"test": "jest",
"release": "standard-version"
},
"files": [
"lib",
"index.js"
],
"dependencies": {

@@ -25,24 +33,50 @@ "memory-fs": "^0.4.1",

},
"peerDependencies": {
"webpack": "^4.0.0"
},
"keywords": [
"webpack",
"middleware",
"develompent"
],
"devDependencies": {
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"assert": "^1.4.1",
"eslint": "^5.4.0",
"eslint-config-webpack": "^1.2.5",
"eslint": "^5.15.3",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.0.0",
"express": "^4.14.0",
"file-loader": "^3.0.1",
"mocha": "^6.0.0",
"nyc": "^13.1.0",
"sinon": "^7.2.2",
"standard-version": "^5.0.0",
"supertest": "^3.1.0",
"webpack": "^4.17.1"
"husky": "^1.2.0",
"jest": "^24.5.0",
"lint-staged": "^8.1.0",
"prettier": "^1.16.4",
"standard-version": "^5.0.2",
"supertest": "^4.0.2",
"webpack": "^4.29.6"
},
"peerDependencies": {
"webpack": "^4.0.0"
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"author": "Tobias Koppers @sokra",
"bugs": "https://github.com/webpack/webpack-dev-middleware/issues",
"homepage": "https://github.com/webpack/webpack-dev-middleware",
"repository": "https://github.com/webpack/webpack-dev-middleware.git",
"license": "MIT"
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"prettier": {
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
}

@@ -24,3 +24,3 @@ <div align="center">

- If files changed in watch mode, the middleware delays requests until compiling
has completed.
has completed.
- Supports hot module reload (HMR).

@@ -48,11 +48,15 @@

const middleware = require('webpack-dev-middleware');
const compiler = webpack({ .. webpack options .. });
const compiler = webpack({
// webpack options
});
const express = require('express');
const app = express();
app.use(middleware(compiler, {
// webpack-dev-middleware options
}));
app.use(
middleware(compiler, {
// webpack-dev-middleware options
})
);
app.listen(3000, () => console.log('Example app listening on port 3000!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'));
```

@@ -72,3 +76,3 @@

This property allows a user to pass the list of HTTP request methods accepted by the server.
This property allows a user to pass the list of HTTP request methods accepted by the server.

@@ -92,3 +96,2 @@ ### headers

### lazy

@@ -157,8 +160,8 @@

This property allows a user to register custom mime types or extension mappings.
eg. `mimeTypes: { 'text/html': [ 'phtml' ] }`.
eg. `mimeTypes: { 'text/html': [ 'phtml' ] }`.
By default node-mime will throw an error if you try to map a type to an extension
that is already assigned to another type. Passing `force: true` will suppress this behavior
By default node-mime will throw an error if you try to map a type to an extension
that is already assigned to another type. Passing `force: true` will suppress this behavior
(overriding any previous mapping).
eg. `mimeTypes: { typeMap: { 'text/html': [ 'phtml' ] } }, force: true }`.
eg. `mimeTypes: { typeMap: { 'text/html': [ 'phtml' ] } }, force: true }`.

@@ -235,3 +238,3 @@ Please see the documentation for

return /superman\.css$/.test(filePath);
}
};
}

@@ -241,2 +244,3 @@ ```

### fs
Type: `Object`

@@ -248,4 +252,5 @@ Default: `MemoryFileSystem`

**Note:** As of 3.5.x version of the middleware you have to provide `.join()` method to the `fs` instance manually. This can be done simply by using `path.join`:
```js
fs.join = path.join // no need to bind
fs.join = path.join; // no need to bind
```

@@ -319,2 +324,3 @@

```
## Known Issues

@@ -350,3 +356,5 @@

const webpack = require('webpack');
const compiler = webpack({ ... });
const compiler = webpack({
// webpack options
});
const isObject = require('is-object');

@@ -358,14 +366,15 @@ const middleware = require('webpack-dev-middleware');

if (isObject(assets)) {
return Object.values(assets)
return Object.values(assets);
}
return Array.isArray(assets) ? assets : [assets]
return Array.isArray(assets) ? assets : [assets];
}
app.use(middleware(compiler, { serverSideRender: true }))
app.use(middleware(compiler, { serverSideRender: true }));
// The following middleware would not be invoked until the latest build is finished.
app.use((req, res) => {
const assetsByChunkName = res.locals.webpackStats.toJson().assetsByChunkName
const fs = res.locals.fs
const outputPath = res.locals.webpackStats.toJson().outputPath
const assetsByChunkName = res.locals.webpackStats.toJson().assetsByChunkName;
const fs = res.locals.fs;
const outputPath = res.locals.webpackStats.toJson().outputPath;

@@ -379,6 +388,6 @@ // then use `assetsByChunkName` for server-sider rendering

<style>
${normalizeAssets(assetsByChunkName.main)
.filter(path => path.endsWith('.css'))
.map(path => fs.readFileSync(outputPath + '/' + path))
.join('\n')}
${normalizeAssets(assetsByChunkName.main)
.filter((path) => path.endsWith('.css'))
.map((path) => fs.readFileSync(outputPath + '/' + path))
.join('\n')}
</style>

@@ -388,11 +397,10 @@ </head>

<div id="root"></div>
${normalizeAssets(assetsByChunkName.main)
.filter(path => path.endsWith('.js'))
.map(path => `<script src="${path}"></script>`)
.join('\n')}
${normalizeAssets(assetsByChunkName.main)
.filter((path) => path.endsWith('.js'))
.map((path) => `<script src="${path}"></script>`)
.join('\n')}
</body>
</html>
`)
})
`);
});
```

@@ -428,45 +436,22 @@

We welcome your contributions! Please have a read of [CONTRIBUTING.md](CONTRIBUTING.md) for more information on how to get involved.
Please take a moment to read our contributing guidelines if you haven't yet done so.
## Maintainers
[CONTRIBUTING.md](CONTRIBUTING.md)
<table>
<tbody>
<tr>
<td align="center">
<img src="https://avatars.githubusercontent.com/SpaceK33z?v=4&s=150">
<br />
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
</td>
<td align="center">
<img src="https://i.imgur.com/4v6pgxh.png">
<br />
<a href="https://github.com/shellscape">Andrew Powell</a>
</td>
</tr>
</tbody>
</table>
## License
#### [MIT](./LICENSE)
[MIT](./LICENSE)
[npm]: https://img.shields.io/npm/v/webpack-dev-middleware.svg
[npm-url]: https://npmjs.com/package/webpack-dev-middleware
[node]: https://img.shields.io/node/v/webpack-dev-middleware.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack/webpack-dev-middleware.svg
[deps-url]: https://david-dm.org/webpack/webpack-dev-middleware
[tests]: http://img.shields.io/travis/webpack/webpack-dev-middleware.svg
[tests-url]: https://travis-ci.org/webpack/webpack-dev-middleware
[cover]: https://codecov.io/gh/webpack/webpack-dev-middleware/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack/webpack-dev-middleware
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
[docs-url]: https://webpack.js.org/guides/development/#using-webpack-dev-middleware

@@ -473,0 +458,0 @@ [hash-url]: https://twitter.com/search?q=webpack

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc