fix: detect memfs used by webpack-dev-server 4+#712
fix: detect memfs used by webpack-dev-server 4+#712Br1an67 wants to merge 1 commit intowebpack:mainfrom
Conversation
|
|
|
Please sign the CLA. Using |
|
@valscion we should just use |
9671d6e to
ec825e0
Compare
|
Thanks for the review! I’ve updated the implementation to avoid the |
|
Yeah I'm not against AI generated code but the repository PR template does need to be followed and code changes should be minimal and understood well. |
src/BundleAnalyzerPlugin.js
Outdated
|
|
||
| if (!outputFs || outputFs === fs) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
This check is useless, remove it
|
|
||
| if (typeof outputFs.readFileSync !== "function") { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
This check is useless, remove it
src/analyzer.js
Outdated
| * @property {Logger} logger logger | ||
| * @property {CompressionAlgorithm} compressionAlgorithm compression algorithm | ||
| * @property {ExcludeAssets} excludeAssets exclude assets | ||
| * @property {{ readFileSync: (path: string, encoding: string) => string } | null} bundleDirFs filesystem for reading bundle files |
There was a problem hiding this comment.
Please use type from webpack
Instead of detecting memfs by constructor name, use the compiler's outputFileSystem directly to read bundle files when it supports readFileSync (e.g. memfs from webpack-dev-server 4+). Falls back to native fs for webpack 4's NodeOutputFileSystem which lacks readFileSync. Fixes webpack#471 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ec825e0 to
8360d05
Compare
|
@Br1an67 I need to know the steps you've taken to verify this code works. Reply with the details, don't change code. Be explicit, list the steps out in numbered order. Assume the steps follow red-green TDD passes so that we can first verify the original issue existed. Then we apply your change. Then we verify the original issue has been fixed. Ideally these steps would be encoded as a unit test directly in this repository. But it might be difficult so we do the reproduction steps first. |
Fixes #471
Summary
When using webpack-dev-server 4+, the bundle analyzer was throwing "no such file" errors because it tried to read bundle files from disk, but webpack-dev-server 4+ uses
memfsto store files in memory instead of writing them to disk.This fix detects when
memfsis being used by checking for the__volproperty (which is specific to memfs's filesystem objects) and returnsnullfor the bundle directory. This tells the analyzer to skip reading bundle files from disk and instead rely on the stats data.Changes
getBundleDirFromCompiler()insrc/BundleAnalyzerPlugin.jsto detectmemfsby checking for the__volpropertymemfsis detected, returnsnullforbundleDirto prevent disk read attemptsTesting
test/dev-server.jstest verifies that the report file is saved correctly when using webpack-dev-servermemfswith the__volpropertyDiff Stats