Skip to content

Commit 67102c1

Browse files
refactor: code
1 parent fb8c246 commit 67102c1

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ function wdm(compiler, options = {}, isPlugin = false) {
474474
}
475475

476476
// Modify output file system
477+
/** @type {OutputFileSystem} */
477478
let outputFileSystem;
478479

479480
if (context.options.outputFileSystem) {
@@ -482,22 +483,24 @@ function wdm(compiler, options = {}, isPlugin = false) {
482483
outputFileSystem = outputFileSystemFromOptions;
483484
}
484485
// Don't use `memfs` when developer wants to write everything to a disk, because it doesn't make sense.
485-
else if (context.options.writeToDisk !== true) {
486-
outputFileSystem = memfs.createFsFromVolume(new memfs.Volume());
487-
} else if (isMultipleCompiler(compiler)) {
488-
// TODO refactor me, when true we should not do something, we already have the right output file system
489-
// Prefer compiler with `devServer` option or fallback on the first
490-
const [foundCompiler] = compilersToModify;
491-
492-
({ outputFileSystem } = foundCompiler || compiler.compilers[0]);
486+
else if (context.options.writeToDisk === true) {
487+
// Prefer compiler with `devServer` option or fallback to the first one
488+
({ outputFileSystem } =
489+
/** @type {Compiler & { outputFileSystem: OutputFileSystem }} */
490+
(
491+
isMultipleCompiler(compiler)
492+
? compilersToModify[0] || compiler.compilers[0]
493+
: compiler
494+
));
493495
} else {
494-
({ outputFileSystem } = context.compiler);
496+
outputFileSystem =
497+
/** @type {OutputFileSystem} */
498+
(/** @type {unknown} */ (memfs.createFsFromVolume(new memfs.Volume())));
495499
}
496500

497-
context.outputFileSystem = /** @type {OutputFileSystem} */ (outputFileSystem);
501+
context.outputFileSystem = outputFileSystem;
498502

499503
for (const compiler of compilersToModify) {
500-
// @ts-expect-error wrong ts types
501504
compiler.outputFileSystem = outputFileSystem;
502505
}
503506

0 commit comments

Comments
 (0)