Skip to content

Commit 0f6ebdf

Browse files
committed
fix: error when integrity option is enabled but no template defined in entry, #107
1 parent 9f8a7c5 commit 0f6ebdf

8 files changed

Lines changed: 37 additions & 8 deletions

File tree

CHANGELOG.md

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

3+
## 3.17.2 (2024-08-08)
4+
5+
- fix: error when `integrity` option is enabled but no template defined in entry, #107
6+
37
## 3.17.1 (2024-08-01)
48

59
- fix: when using the integrity option, leaves the original attributes in the script tag as is

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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": "3.17.1",
3+
"version": "3.17.2",
44
"description": "HTML bundler plugin for webpack handles a template as an entry point, extracts CSS and JS from their sources referenced in HTML, supports template engines like Eta, EJS, Handlebars, Nunjucks.",
55
"keywords": [
66
"html",

src/Plugin/Extras/Integrity.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,11 @@ class Integrity {
299299
this.assetHashes.set(compilation, assetHashes);
300300
const hashes = this.hashes.get(compilation);
301301

302-
for (const [hash, value] of hashes) {
303-
const assetFile = value.next().value;
304-
assetHashes.set(assetFile, hash);
302+
if (hashes) {
303+
for (const [hash, value] of hashes) {
304+
const assetFile = value.next().value;
305+
assetHashes.set(assetFile, hash);
306+
}
305307
}
306308
}
307309

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(">> main");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('>> main');
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path');
2+
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
3+
4+
module.exports = {
5+
mode: 'production',
6+
7+
output: {
8+
path: path.join(__dirname, 'dist/'),
9+
crossOriginLoading: 'anonymous', // required for test Subresource Integrity
10+
},
11+
12+
// test enabled integrity option, but no template is defined, see #107
13+
entry: './src/main.js', // this file should exist, contents don't matter
14+
15+
plugins: [
16+
new HtmlBundlerPlugin({
17+
integrity: true,
18+
}),
19+
],
20+
};

test/integration.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ describe('integrity, common use cases', () => {
468468
test('script, link, publicPath="auto"', () => compareFiles('integrity-publicPath-auto'));
469469
test('script, link, publicPath=""', () => compareFiles('integrity-publicPath-empty'));
470470
test('script, link, publicPath="/"', () => compareFiles('integrity-publicPath-root'));
471-
472-
471+
473472
test('script async, prod', () => compareFiles('integrity-script-async-prod'));
474473

475474
test('split chunks', () => compareFiles('integrity-split-chunks'));
@@ -478,6 +477,8 @@ describe('integrity, common use cases', () => {
478477

479478
test('hook-done', () => compareFiles('integrity-hook-done'));
480479
test('hook-integrityHashes', () => compareFiles('integrity-hook-integrityHashes'));
480+
481+
test('integrity enabled w/o using template in entry', () => compareFiles('integrity-enabled-wo-template'));
481482
});
482483

483484
describe('integrity, dynamic chunks', () => {

0 commit comments

Comments
 (0)