Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/output-report-without-a-file-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"diagnostics-webpack-plugin": patch
---

End the build rather than hanging it where an `outputReport` has no file system to be written to.
8 changes: 7 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ const jsonStringifyReplacerSortKeys = (_, value) => {
function writeOutputFile(compiler, name, content) {
return /** @type {Promise<void>} */ (
new Promise((finish, bail) => {
if (!compiler.outputFileSystem) return;
// Nothing to write it to. Answering rather than returning: what awaits
// this is the compilation's own callback, so a promise left unsettled
// is a build that never ends.
if (!compiler.outputFileSystem) {
finish();
return;
}

const { mkdir, writeFile } = compiler.outputFileSystem;

Expand Down
22 changes: 22 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
parseFiles,
parseFoldersToGlobs,
toPosixPath,
writeOutputFile,
} from "../src/utils.js";

// `parseFoldersToGlobs` reads what it is given, so the fixtures have to exist.
Expand Down Expand Up @@ -85,6 +86,27 @@ describe("utils", () => {
]);
});

it("writeOutputFile should answer where there is nothing to write to", async () => {
// What awaits this is the compilation's own callback, so a promise left
// unsettled is a build that never ends rather than one that reports.
/** @type {NodeJS.Timeout} */
let waiting;
const answered = await Promise.race([
writeOutputFile(
/** @type {EXPECTED_ANY} */ ({}),
join(directory, "report.json"),
"{}",
).then(() => "answered"),
new Promise((done) => {
waiting = setTimeout(() => done("never answered"), 1000);
}),
]);

clearTimeout(waiting);

assert.strictEqual(answered, "answered");
});

it("parseFoldersToGlobs should cover a path that is not there yet both ways", async () => {
const absent = join(directory, "not-written-yet");

Expand Down