From bf586c92a7e8ad75e00bc3c255c366fc2dbd73b0 Mon Sep 17 00:00:00 2001 From: wtgtybhertgeghgtwtg Date: Mon, 3 Sep 2018 01:32:42 -0700 Subject: [PATCH 1/3] refactor(package): remove `path-is-absolute` dependency (`dependencies`) (#335) --- lib/fs.js | 5 ++--- lib/util.js | 6 +++--- package-lock.json | 3 ++- package.json | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 47f1e40ca..1823b67a3 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -3,7 +3,6 @@ const fs = require('fs'); const path = require('path'); const MemoryFileSystem = require('memory-fs'); -const pathabs = require('path-is-absolute'); const { colors } = require('webpack-log'); const NodeOutputFileSystem = require('webpack/lib/node/NodeOutputFileSystem'); const DevMiddlewareError = require('./DevMiddlewareError'); @@ -27,7 +26,7 @@ module.exports = { for (const assetPath of Object.keys(assets)) { const asset = assets[assetPath]; const source = asset.source(); - const isAbsolute = pathabs(assetPath); + const isAbsolute = path.isAbsolute(assetPath); const writePath = isAbsolute ? assetPath : path.join(outputPath, assetPath); const relativePath = path.relative(process.cwd(), writePath); const allowWrite = filter && typeof filter === 'function' ? filter(writePath) : true; @@ -54,7 +53,7 @@ module.exports = { }, setFs(context, compiler) { - if (typeof compiler.outputPath === 'string' && !pathabs.posix(compiler.outputPath) && !pathabs.win32(compiler.outputPath)) { + 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 `/`.'); } diff --git a/lib/util.js b/lib/util.js index 1ca5437ee..bce5f9f5c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,8 +1,8 @@ 'use strict'; +const path = require('path'); const { parse } = require('url'); const querystring = require('querystring'); -const pathabs = require('path-is-absolute'); const parseRange = require('range-parser'); const urlJoin = require('url-join'); @@ -94,7 +94,7 @@ module.exports = { if (filename) { uri = urlJoin((outputPath || ''), querystring.unescape(filename)); - if (!pathabs.win32(uri)) { + if (!path.win32.isAbsolute(uri)) { uri = `/${uri}`; } } @@ -106,7 +106,7 @@ module.exports = { if (filename) { uri = urlJoin((outputPath || ''), filename); - if (!pathabs.posix(uri)) { + if (!path.posix.isAbsolute(uri)) { uri = `/${uri}`; } } diff --git a/package-lock.json b/package-lock.json index 6bf7a8cad..e18e0d3ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7234,7 +7234,8 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true }, "path-is-inside": { "version": "1.0.2", diff --git a/package.json b/package.json index cedf34803..aab87f7a3 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "loud-rejection": "^1.6.0", "memory-fs": "~0.4.1", "mime": "^2.3.1", - "path-is-absolute": "^1.0.0", "range-parser": "^1.0.3", "url-join": "^4.0.0", "webpack-log": "^2.0.0" From f9a138e9e39d52333b3c9883467feeb82a2e2eb4 Mon Sep 17 00:00:00 2001 From: ferdinando-ferreira Date: Fri, 7 Sep 2018 11:56:12 +0100 Subject: [PATCH 2/3] feat(middleware): expose the memory filesystem (`response.locals.fs`) (#337) --- README.md | 8 ++++++-- lib/middleware.js | 1 + test/tests/server.js | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 321cc1b81..91a9cf060 100644 --- a/README.md +++ b/README.md @@ -309,7 +309,7 @@ In order to develop an app using server-side rendering, we need access to the generated with each build. With server-side rendering enabled, `webpack-dev-middleware` sets the `stat` to -`res.locals.webpackStats` before invoking the next middleware, allowing a +`res.locals.webpackStats` and the memory filesystem to `res.locals.fs` before invoking the next middleware, allowing a developer to render the page body and manage the response to clients. _Note: Requests for bundle files will still be handled by @@ -337,6 +337,8 @@ 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 // then use `assetsByChunkName` for server-sider rendering // For example, if you have only one main chunk: @@ -344,10 +346,12 @@ app.use((req, res) => { My App +
diff --git a/lib/middleware.js b/lib/middleware.js index 23e2220cf..2813bd6ab 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -19,6 +19,7 @@ module.exports = function wrapper(context) { return new Promise(((resolve) => { ready(context, () => { res.locals.webpackStats = context.webpackStats; + res.locals.fs = context.fs; resolve(next()); }, req); })); diff --git a/test/tests/server.js b/test/tests/server.js index 5d7419665..ceb685c8d 100644 --- a/test/tests/server.js +++ b/test/tests/server.js @@ -339,6 +339,7 @@ describe('Server', () => { request(app).get('/foo/bar') .expect(200, () => { assert(locals.webpackStats); + assert(locals.fs); done(); }); }); From 0f9e2e71f2e97842cb2249b1b51f3df9def98ed5 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Mon, 10 Sep 2018 13:55:47 +0200 Subject: [PATCH 3/3] chore(release): 3.3.0 --- CHANGELOG.md | 10 ++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccac2f8de..e75a0b1fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +# [3.3.0](https://github.com/webpack/webpack-dev-middleware/compare/v3.2.0...v3.3.0) (2018-09-10) + + +### Features + +* **middleware:** expose the memory filesystem (`response.locals.fs`) ([#337](https://github.com/webpack/webpack-dev-middleware/issues/337)) ([f9a138e](https://github.com/webpack/webpack-dev-middleware/commit/f9a138e)) + + + # [3.2.0](https://github.com/webpack/webpack-dev-middleware/compare/v3.1.3...v3.2.0) (2018-08-23) diff --git a/package-lock.json b/package-lock.json index e18e0d3ad..d4f2be387 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "webpack-dev-middleware", - "version": "3.2.0", + "version": "3.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index aab87f7a3..c523cc42d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpack-dev-middleware", - "version": "3.2.0", + "version": "3.3.0", "description": "A development middleware for webpack", "main": "index.js", "files": [