webpack-dev-middleware
Advanced tools
Comparing version 3.7.0 to 3.7.1
@@ -5,2 +5,11 @@ # Changelog | ||
### [3.7.1](https://github.com/webpack/webpack-dev-middleware/compare/v3.7.0...v3.7.1) (2019-09-03) | ||
### Bug Fixes | ||
* directly used mkdirp instead of through Webpack ([#436](https://github.com/webpack/webpack-dev-middleware/issues/436)) ([dff39a1](https://github.com/webpack/webpack-dev-middleware/commit/dff39a1)) | ||
* displayStats only logged ([#427](https://github.com/webpack/webpack-dev-middleware/issues/427)) ([98deaf4](https://github.com/webpack/webpack-dev-middleware/commit/98deaf4)) | ||
* the `writeToFile` option has compatibility with webpack@5 ([#459](https://github.com/webpack/webpack-dev-middleware/issues/459)) ([5c90e1e](https://github.com/webpack/webpack-dev-middleware/commit/5c90e1e)) | ||
## [3.7.0](https://github.com/webpack/webpack-dev-middleware/compare/v3.6.2...v3.7.0) (2019-05-15) | ||
@@ -7,0 +16,0 @@ |
@@ -7,69 +7,72 @@ 'use strict'; | ||
const MemoryFileSystem = require('memory-fs'); | ||
const mkdirp = require('mkdirp'); | ||
const { colors } = require('webpack-log'); | ||
const NodeOutputFileSystem = require('webpack/lib/node/NodeOutputFileSystem'); | ||
const DevMiddlewareError = require('./DevMiddlewareError'); | ||
const { mkdirp } = new NodeOutputFileSystem(); | ||
module.exports = { | ||
toDisk(context) { | ||
const compilers = context.compiler.compilers || [context.compiler]; | ||
for (const compiler of compilers) { | ||
compiler.hooks.afterEmit.tap('WebpackDevMiddleware', (compilation) => { | ||
const { assets } = compilation; | ||
const { log } = context; | ||
const { writeToDisk: filter } = context.options; | ||
let { outputPath } = compiler; | ||
compiler.hooks.emit.tap('WebpackDevMiddleware', (compilation) => { | ||
compiler.hooks.assetEmitted.tapAsync( | ||
'WebpackDevMiddleware', | ||
(file, content, callback) => { | ||
let targetFile = file; | ||
if (outputPath === '/') { | ||
outputPath = compiler.context; | ||
} | ||
const queryStringIdx = targetFile.indexOf('?'); | ||
for (const assetPath of Object.keys(assets)) { | ||
let targetFile = assetPath; | ||
if (queryStringIdx >= 0) { | ||
targetFile = targetFile.substr(0, queryStringIdx); | ||
} | ||
const queryStringIdx = targetFile.indexOf('?'); | ||
let { outputPath } = compiler; | ||
if (queryStringIdx >= 0) { | ||
targetFile = targetFile.substr(0, queryStringIdx); | ||
} | ||
// TODO Why? Need remove in future major release | ||
if (outputPath === '/') { | ||
outputPath = compiler.context; | ||
} | ||
const targetPath = path.isAbsolute(targetFile) | ||
? targetFile | ||
: path.join(outputPath, targetFile); | ||
const allowWrite = | ||
filter && typeof filter === 'function' ? filter(targetPath) : true; | ||
outputPath = compilation.getPath(outputPath, {}); | ||
if (allowWrite) { | ||
const asset = assets[assetPath]; | ||
let content = asset.source(); | ||
const targetPath = path.join(outputPath, targetFile); | ||
if (!Buffer.isBuffer(content)) { | ||
// TODO need remove in next major release | ||
if (Array.isArray(content)) { | ||
content = content.join('\n'); | ||
} | ||
const { writeToDisk: filter } = context.options; | ||
const allowWrite = | ||
filter && typeof filter === 'function' | ||
? filter(targetPath) | ||
: true; | ||
content = Buffer.from(content, 'utf8'); | ||
if (!allowWrite) { | ||
return callback(); | ||
} | ||
mkdirp.sync(path.dirname(targetPath)); | ||
const { log } = context; | ||
const dir = path.dirname(targetPath); | ||
try { | ||
fs.writeFileSync(targetPath, content, 'utf-8'); | ||
return mkdirp(dir, (mkdirpError) => { | ||
if (mkdirpError) { | ||
return callback(mkdirpError); | ||
} | ||
log.debug( | ||
colors.cyan( | ||
`Asset written to disk: ${path.relative( | ||
process.cwd(), | ||
targetPath | ||
)}` | ||
) | ||
); | ||
} catch (e) { | ||
log.error(`Unable to write asset to disk:\n${e}`); | ||
} | ||
return fs.writeFile(targetPath, content, (writeFileError) => { | ||
if (writeFileError) { | ||
return callback(writeFileError); | ||
} | ||
log.debug( | ||
colors.cyan( | ||
`Asset written to disk: ${path.relative( | ||
process.cwd(), | ||
targetPath | ||
)}` | ||
) | ||
); | ||
return callback(); | ||
}); | ||
}); | ||
} | ||
} | ||
); | ||
}); | ||
@@ -76,0 +79,0 @@ } |
@@ -8,10 +8,12 @@ 'use strict'; | ||
const displayStats = middlewareOptions.stats !== false; | ||
const statsString = stats.toString(middlewareOptions.stats); | ||
if (displayStats) { | ||
// displayStats only logged | ||
if (displayStats && statsString.trim().length) { | ||
if (stats.hasErrors()) { | ||
log.error(stats.toString(middlewareOptions.stats)); | ||
log.error(statsString); | ||
} else if (stats.hasWarnings()) { | ||
log.warn(stats.toString(middlewareOptions.stats)); | ||
log.warn(statsString); | ||
} else { | ||
log.info(stats.toString(middlewareOptions.stats)); | ||
log.info(statsString); | ||
} | ||
@@ -18,0 +20,0 @@ } |
@@ -28,8 +28,7 @@ 'use strict'; | ||
if (compilerPublicPath) { | ||
if (compilerPublicPath.indexOf('/') === 0) { | ||
compilerPublicPathBase = compilerPublicPath; | ||
} else { | ||
// handle the case where compilerPublicPath is a URL with hostname | ||
compilerPublicPathBase = parse(compilerPublicPath).pathname; | ||
} | ||
compilerPublicPathBase = | ||
compilerPublicPath.indexOf('/') === 0 | ||
? compilerPublicPath // eslint-disable-next-line | ||
: // handle the case where compilerPublicPath is a URL with hostname | ||
parse(compilerPublicPath).pathname; | ||
@@ -70,2 +69,4 @@ // check the url vs the path part of the compilerPublicPath | ||
const hostNameIsTheSame = localPrefix.hostname === urlObject.hostname; | ||
// publicPath has the hostname that is not the same as request url's, should fail | ||
@@ -75,3 +76,3 @@ if ( | ||
urlObject.hostname !== null && | ||
localPrefix.hostname !== urlObject.hostname | ||
!hostNameIsTheSame | ||
) { | ||
@@ -82,7 +83,3 @@ return false; | ||
// publicPath is not in url, so it should fail | ||
if ( | ||
publicPath && | ||
localPrefix.hostname === urlObject.hostname && | ||
url.indexOf(publicPath) !== 0 | ||
) { | ||
if (publicPath && hostNameIsTheSame && url.indexOf(publicPath) !== 0) { | ||
return false; | ||
@@ -89,0 +86,0 @@ } |
{ | ||
"name": "webpack-dev-middleware", | ||
"version": "3.7.0", | ||
"version": "3.7.1", | ||
"description": "A development middleware for webpack", | ||
@@ -35,3 +35,4 @@ "license": "MIT", | ||
"memory-fs": "^0.4.1", | ||
"mime": "^2.4.2", | ||
"mime": "^2.4.4", | ||
"mkdirp": "^0.5.1", | ||
"range-parser": "^1.2.1", | ||
@@ -41,27 +42,27 @@ "webpack-log": "^2.0.0" | ||
"devDependencies": { | ||
"@babel/cli": "7.4.4", | ||
"@babel/core": "7.4.4", | ||
"@babel/preset-env": "7.4.4", | ||
"@commitlint/cli": "7.6.1", | ||
"@commitlint/config-conventional": "7.6.0", | ||
"@webpack-contrib/defaults": "4.0.1", | ||
"@webpack-contrib/eslint-config-webpack": "3.0.0", | ||
"babel-jest": "24.8.0", | ||
"commitlint-azure-pipelines-cli": "1.0.1", | ||
"cross-env": "5.2.0", | ||
"del": "4.1.1", | ||
"del-cli": "1.1.0", | ||
"eslint": "5.16.0", | ||
"eslint-plugin-import": "2.17.2", | ||
"eslint-plugin-prettier": "3.1.0", | ||
"express": "4.16.4", | ||
"file-loader": "3.0.1", | ||
"husky": "2.3.0", | ||
"jest": "24.8.0", | ||
"jest-junit": "6.4.0", | ||
"lint-staged": "8.1.7", | ||
"prettier": "1.17.1", | ||
"standard-version": "6.0.1", | ||
"supertest": "4.0.2", | ||
"webpack": "4.31.0" | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"@commitlint/cli": "^8.1.0", | ||
"@commitlint/config-conventional": "^8.1.0", | ||
"@webpack-contrib/defaults": "^5.0.2", | ||
"@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
"babel-jest": "^24.9.0", | ||
"commitlint-azure-pipelines-cli": "^1.0.2", | ||
"cross-env": "^5.2.1", | ||
"del": "^4.1.1", | ||
"del-cli": "^1.1.0", | ||
"eslint": "^6.3.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"express": "^4.17.1", | ||
"file-loader": "^4.2.0", | ||
"husky": "^3.0.5", | ||
"jest": "^24.9.0", | ||
"jest-junit": "^8.0.0", | ||
"lint-staged": "^9.2.5", | ||
"prettier": "^1.18.2", | ||
"standard-version": "^7.0.0", | ||
"supertest": "^4.0.2", | ||
"webpack": "^4.39.3" | ||
}, | ||
@@ -68,0 +69,0 @@ "keywords": [ |
@@ -417,3 +417,3 @@ <div align="center"> | ||
If you have discovered a :bug:, have a feature suggestion, of would like to see | ||
If you have discovered a :bug:, have a feature suggestion, or would like to see | ||
a modification, please feel free to create an issue on Github. _Note: The issue | ||
@@ -420,0 +420,0 @@ template isn't optional, so please be sure not to remove it, and please fill it |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39430
6
573
+ Addedmkdirp@^0.5.1
Updatedmime@^2.4.4