Skip to content

Commit c80bcc7

Browse files
committed
fix: webpack 4 compatibility
Fixes #97
1 parent ce84d42 commit c80bcc7

File tree

7 files changed

+44
-9
lines changed

7 files changed

+44
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ https://github.com/SimenB/add-asset-html-webpack-plugin/releases
88

99
## [Unreleased]
1010

11+
## [2.1.3] - 2018-03-03
12+
13+
### Fixes
14+
15+
* Webpack 4 compatibility
16+
1117
### Changed
1218

1319
* Replace Bluebird with `p-each-series`
@@ -143,7 +149,8 @@ https://github.com/SimenB/add-asset-html-webpack-plugin/releases
143149

144150
Initial release
145151

146-
[unreleased]: https://github.com/SimenB/add-asset-html-webpack-plugin/compare/v2.1.2...HEAD
152+
[unreleased]: https://github.com/SimenB/add-asset-html-webpack-plugin/compare/v2.1.3...HEAD
153+
[2.1.3]: https://github.com/SimenB/add-asset-html-webpack-plugin/compare/v2.1.2...v2.1.3
147154
[2.1.2]: https://github.com/SimenB/add-asset-html-webpack-plugin/compare/v2.1.1...v2.1.2
148155
[2.1.1]: https://github.com/SimenB/add-asset-html-webpack-plugin/compare/v2.1.0...v2.1.1
149156
[2.1.0]: https://github.com/SimenB/add-asset-html-webpack-plugin/compare/v2.0.1...v2.1.0

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Simen Bekkhus
3+
Copyright (c) 2018 Simen Bekkhus
44

55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the

__snapshots__/test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Array [
7676
]
7777
`;
7878

79+
exports[`should reject on error 1`] = `
80+
Array [
81+
[Error: No filepath defined],
82+
]
83+
`;
84+
7985
exports[`should replace compilation assets key if \`outputPath\` is set 1`] = `
8086
Object {
8187
"css": Array [],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"webpack": "^3.5.6"
5858
},
5959
"peerDependencies": {
60-
"html-webpack-plugin": "^2.10.0"
60+
"html-webpack-plugin": "^2.10.0 || ^3.0.4"
6161
},
6262
"engines": {
6363
"node": ">=4"

src/addAllAssetsToCompilation.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ export default async function(assets, compilation, htmlPluginData, callback) {
104104
await pEachSeries(handledAssets, asset =>
105105
addFileToAssets(compilation, htmlPluginData, asset),
106106
);
107-
108-
callback(null, htmlPluginData);
107+
if (callback) {
108+
return callback(null, htmlPluginData);
109+
}
110+
return htmlPluginData;
109111
} catch (e) {
110-
callback(e, htmlPluginData);
112+
if (callback) {
113+
return callback(e, htmlPluginData);
114+
}
115+
throw e;
111116
}
112117
}

src/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ export default class AddAssetHtmlPlugin {
1010
compiler.plugin('compilation', compilation => {
1111
compilation.plugin(
1212
'html-webpack-plugin-before-html-generation',
13-
(htmlPluginData, callback) => {
13+
(htmlPluginData, callback) =>
1414
addAllAssetsToCompilation(
1515
this.assets,
1616
compilation,
1717
htmlPluginData,
1818
callback,
19-
);
20-
},
19+
),
2120
);
2221
});
2322
}

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ test('should invoke callback on success', async () => {
2929
expect(callback).toHaveBeenCalledWith(null, pluginMock);
3030
});
3131

32+
test('should not reject success', async () => {
33+
expect(await addAllAssetsToCompilation([], {}, pluginMock)).toEqual(
34+
pluginMock,
35+
);
36+
});
37+
3238
test('should invoke callback on error', async () => {
3339
const callback = jest.fn();
3440
const compilation = { errors: [] };
@@ -41,6 +47,18 @@ test('should invoke callback on error', async () => {
4147
expect(callback).toHaveBeenCalledWith(compilation.errors[0], pluginMock);
4248
});
4349

50+
test('should reject on error', async () => {
51+
expect.hasAssertions();
52+
const compilation = { errors: [] };
53+
54+
try {
55+
await addAllAssetsToCompilation([{}], compilation, pluginMock);
56+
} catch (e) {
57+
expect(compilation.errors).toMatchSnapshot();
58+
expect(compilation.errors[0]).toBe(e);
59+
}
60+
});
61+
4462
test("should add file using compilation's publicPath", async () => {
4563
const callback = jest.fn();
4664
const compilation = { options: { output: { publicPath: 'vendor/' } } };

0 commit comments

Comments
 (0)