Skip to content

Commit 934de27

Browse files
committed
fix: prevent watcher crash in multi-compiler mode after deleting a watched source file, #191
1 parent f467e86 commit 934de27

5 files changed

Lines changed: 66 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 4.23.1 (2026-05-31)
4+
5+
- fix: prevent watcher crash in multi-compiler mode when Webpack invalidates a compilation with a `null` filename after deleting a watched source file, #191
6+
37
## 4.23.0 (2026-03-09)
48

59
- feat: add per-entry override support for `js.inline`, `css.inline`, and HTML `minify` options

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "4.23.0",
3+
"version": "4.23.1",
44
"description": "Generates complete single-page or multi-page website from source assets. Built-in support for Markdown, Eta, EJS, Handlebars, Nunjucks, Pug. Alternative to html-webpack-plugin.",
55
"keywords": [
66
"html",

src/Plugin/AssetCompiler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ class AssetCompiler {
609609
const isEntry = this.assetEntry.isEntryResource(fileName);
610610

611611
if (!isEntry) {
612+
if (!this.compilation) return;
613+
612614
const dependency = PluginService.getDependencyInstance(this.compilation.compiler);
613615

614616
// dependency is null when no html entry defined and a style in entry was changed

src/Plugin/AssetEntry.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ class AssetEntry {
243243
* @return {boolean}
244244
*/
245245
isEntryResource(resource) {
246+
if (!resource) return false;
247+
246248
const [resourceFile] = resource.split('?', 1);
247249
for (let { isTemplate, sourceFile } of this.entriesByName.values()) {
248250
if (isTemplate && sourceFile === resourceFile) return true;

test/issue.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import fs from 'fs';
2+
import os from 'os';
3+
import path from 'path';
4+
import webpack from 'webpack';
5+
import HtmlBundlerPlugin from '../src';
16
import { compareFiles } from './utils/helpers';
27

38
beforeAll(() => {
@@ -19,4 +24,56 @@ describe('issue tests', () => {
1924
test('issue advanced template', () => compareFiles('issue-0-advanced-template'));
2025

2126
test('issue infinity walk by circular dependency', () => compareFiles('issue-mui-css'));
27+
28+
test('multi compiler invalid hook handles null filename, issue #191', () => {
29+
const context = fs.mkdtempSync(path.join(os.tmpdir(), 'html-bundler-webpack-plugin-'));
30+
const sourcePath = path.join(context, 'src');
31+
32+
fs.mkdirSync(sourcePath, { recursive: true });
33+
fs.writeFileSync(path.join(sourcePath, 'home.html'), '<!doctype html><script src="./home.js"></script>');
34+
fs.writeFileSync(path.join(sourcePath, 'home.js'), 'console.log("home");');
35+
fs.writeFileSync(path.join(sourcePath, 'about.html'), '<!doctype html><script src="./about.js"></script>');
36+
fs.writeFileSync(path.join(sourcePath, 'about.js'), 'console.log("about");');
37+
38+
try {
39+
const compiler = webpack([
40+
{
41+
name: 'home',
42+
mode: 'development',
43+
context,
44+
output: {
45+
path: path.join(context, 'dist/home'),
46+
},
47+
plugins: [
48+
new HtmlBundlerPlugin({
49+
entry: {
50+
home: './src/home.html',
51+
},
52+
}),
53+
],
54+
},
55+
{
56+
name: 'about',
57+
mode: 'development',
58+
context,
59+
output: {
60+
path: path.join(context, 'dist/about'),
61+
},
62+
plugins: [
63+
new HtmlBundlerPlugin({
64+
entry: {
65+
about: './src/about.html',
66+
},
67+
}),
68+
],
69+
},
70+
]);
71+
72+
for (const childCompiler of compiler.compilers) {
73+
expect(() => childCompiler.hooks.invalid.call(null, null)).not.toThrow();
74+
}
75+
} finally {
76+
fs.rmSync(context, { recursive: true, force: true });
77+
}
78+
});
2279
});

0 commit comments

Comments
 (0)