Skip to content

Commit 223d571

Browse files
committed
fix: normalize missing script paths in watch mode on Windows
1 parent 7829889 commit 223d571

4 files changed

Lines changed: 52 additions & 2 deletions

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.3 (2026-06-01)
4+
5+
- fix: normalize restored missing script paths in watch mode to prevent false `Can't resolve ...` errors on Windows.
6+
37
## 4.23.2 (2026-06-01)
48

59
- fix: restore Webpack filesystem cache builds when a cached HTML template references a script and `js.filename` is configured as a function, #190

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.2",
3+
"version": "4.23.3",
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/Snapshot.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { readDirRecursiveSync } = require('../Common/FileUtils');
2+
const { pathToPosix } = require('../Common/Helpers');
23

34
/**
45
* Snapshot of files.
@@ -138,7 +139,9 @@ class Snapshot {
138139
let files = this.missingFiles.get(issuer);
139140
if (!files) return false;
140141

141-
return !!Array.from(files).find((missingFile) => file.endsWith(missingFile));
142+
file = pathToPosix(file);
143+
144+
return !!Array.from(files).find((missingFile) => file.endsWith(pathToPosix(missingFile)));
142145
}
143146

144147
static getDiff(a, b) {

test/issue.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import os from 'os';
33
import path from 'path';
44
import webpack from 'webpack';
55
import HtmlBundlerPlugin from '../src';
6+
import Snapshot from '../src/Plugin/Snapshot';
67
import { compareFiles, compareFilesRuns } from './utils/helpers';
78

89
beforeAll(() => {
@@ -92,4 +93,46 @@ describe('issue tests', () => {
9293
fs.rmSync(context, { recursive: true, force: true });
9394
}
9495
});
96+
97+
test.each([
98+
{
99+
name: 'missing uses backslashes, restored uses slashes',
100+
issuer: 'C:\\path\\to\\index.html',
101+
missingFile: 'C:\\path\\to\\script.js',
102+
restoredFile: 'C:/path/to/script.js',
103+
},
104+
{
105+
name: 'missing uses slashes, restored uses backslashes',
106+
issuer: 'C:\\path\\to\\index.html',
107+
missingFile: 'C:/path/to/script.js',
108+
restoredFile: 'C:\\path\\to\\script.js',
109+
},
110+
{
111+
name: 'missing uses backslashes, restored uses backslashes',
112+
issuer: 'C:\\path\\to\\index.html',
113+
missingFile: 'C:\\path\\to\\script.js',
114+
restoredFile: 'C:\\path\\to\\script.js',
115+
},
116+
{
117+
name: 'missing uses slashes, restored uses slashes',
118+
issuer: 'C:/path/to/index.html',
119+
missingFile: 'C:/path/to/script.js',
120+
restoredFile: 'C:/path/to/script.js',
121+
},
122+
{
123+
name: 'missing script matches POSIX path',
124+
issuer: '/path/to/index.html',
125+
missingFile: '/path/to/script.js',
126+
restoredFile: '/path/to/script.js',
127+
},
128+
])('watch restored missing script matches Windows paths: $name', ({ issuer, missingFile, restoredFile }) => {
129+
Snapshot.missingFiles.clear();
130+
Snapshot.addMissingFile(issuer, missingFile);
131+
132+
try {
133+
expect(Snapshot.hasMissingFile(issuer, restoredFile)).toBe(true);
134+
} finally {
135+
Snapshot.missingFiles.clear();
136+
}
137+
});
95138
});

0 commit comments

Comments
 (0)