Skip to content

Commit 36cd304

Browse files
committed
Upgrade all deps
1 parent 6b3e068 commit 36cd304

5 files changed

Lines changed: 556 additions & 412 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
"babel-preset-env": "^1.4.0",
5050
"classnames": "^2.2.5",
5151
"del-cli": "^1.0.0",
52-
"eslint": "^3.19.0",
53-
"eslint-config-simenb-base": "^12.1.3",
54-
"eslint_d": "^4.2.5",
52+
"eslint": "^4.3.0",
53+
"eslint-config-simenb-base": "^13.0.0",
54+
"eslint_d": "^5.0.0",
5555
"html-webpack-plugin": "^2.10.0",
5656
"husky": "^0.14.0",
5757
"in-publish": "^2.0.0",

src/addAllAssetsToCompilation.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,36 @@ function ensureTrailingSlash(string) {
1414
// Copied from html-webpack-plugin
1515
function resolvePublicPath(compilation, filename) {
1616
/* istanbul ignore else */
17-
const publicPath = typeof compilation.options.output.publicPath !== 'undefined'
18-
? compilation.options.output.publicPath
19-
: path.relative(path.dirname(filename), '.'); // TODO: How to test this? I haven't written this logic, unsure what it does
17+
const publicPath =
18+
typeof compilation.options.output.publicPath !== 'undefined'
19+
? compilation.options.output.publicPath
20+
: path.relative(path.dirname(filename), '.'); // TODO: How to test this? I haven't written this logic, unsure what it does
2021

2122
return ensureTrailingSlash(publicPath);
2223
}
2324

2425
function resolveOutput(compilation, addedFilename, outputPath) {
2526
if (outputPath && outputPath.length) {
26-
compilation.assets[`${outputPath}/${addedFilename}`] = compilation.assets[addedFilename]; // eslint-disable-line no-param-reassign
27-
delete compilation.assets[addedFilename]; // eslint-disable-line no-param-reassign
27+
/* eslint-disable no-param-reassign */
28+
compilation.assets[`${outputPath}/${addedFilename}`] =
29+
compilation.assets[addedFilename];
30+
delete compilation.assets[addedFilename];
31+
/* eslint-enable */
2832
}
2933
}
3034

3135
async function addFileToAssets(
3236
compilation,
3337
htmlPluginData,
34-
{ filepath, typeOfAsset = 'js', includeSourcemap = true, hash = false, publicPath, outputPath, files = [] }
38+
{
39+
filepath,
40+
typeOfAsset = 'js',
41+
includeSourcemap = true,
42+
hash = false,
43+
publicPath,
44+
outputPath,
45+
files = [],
46+
}
3547
) {
3648
if (!filepath) {
3749
const error = new Error('No filepath defined');
@@ -42,14 +54,19 @@ async function addFileToAssets(
4254
const fileFilters = Array.isArray(files) ? files : [files];
4355

4456
if (fileFilters.length > 0) {
45-
const shouldSkip = !fileFilters.some(file => minimatch(htmlPluginData.outputName, file));
57+
const shouldSkip = !fileFilters.some(file =>
58+
minimatch(htmlPluginData.outputName, file)
59+
);
4660

4761
if (shouldSkip) {
4862
return Promise.resolve(null);
4963
}
5064
}
5165

52-
const addedFilename = await htmlPluginData.plugin.addFileToAssets(filepath, compilation);
66+
const addedFilename = await htmlPluginData.plugin.addFileToAssets(
67+
filepath,
68+
compilation
69+
);
5370

5471
let suffix = '';
5572
if (hash) {
@@ -58,17 +75,21 @@ async function addFileToAssets(
5875
suffix = `?${md5.digest('hex').substr(0, 20)}`;
5976
}
6077

61-
const resolvedPublicPath = typeof publicPath === 'undefined'
62-
? resolvePublicPath(compilation, addedFilename)
63-
: ensureTrailingSlash(publicPath);
78+
const resolvedPublicPath =
79+
typeof publicPath === 'undefined'
80+
? resolvePublicPath(compilation, addedFilename)
81+
: ensureTrailingSlash(publicPath);
6482
const resolvedPath = `${resolvedPublicPath}${addedFilename}${suffix}`;
6583

6684
htmlPluginData.assets[typeOfAsset].unshift(resolvedPath);
6785

6886
resolveOutput(compilation, addedFilename, outputPath);
6987

7088
if (includeSourcemap) {
71-
const addedMapFilename = await htmlPluginData.plugin.addFileToAssets(`${filepath}.map`, compilation);
89+
const addedMapFilename = await htmlPluginData.plugin.addFileToAssets(
90+
`${filepath}.map`,
91+
compilation
92+
);
7293
resolveOutput(compilation, addedMapFilename, outputPath);
7394
}
7495

@@ -78,7 +99,9 @@ async function addFileToAssets(
7899
// Visible for testing
79100
export default async function(assets, compilation, htmlPluginData, callback) {
80101
try {
81-
await Promise.mapSeries(assets, asset => addFileToAssets(compilation, htmlPluginData, asset));
102+
await Promise.mapSeries(assets, asset =>
103+
addFileToAssets(compilation, htmlPluginData, asset)
104+
);
82105

83106
callback(null, htmlPluginData);
84107
} catch (e) {

src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ export default class AddAssetHtmlPlugin {
88
/* istanbul ignore next: this would be integration tests */
99
apply(compiler) {
1010
compiler.plugin('compilation', compilation => {
11-
compilation.plugin('html-webpack-plugin-before-html-generation', (htmlPluginData, callback) => {
12-
addAllAssetsToCompilation(this.assets, compilation, htmlPluginData, callback);
13-
});
11+
compilation.plugin(
12+
'html-webpack-plugin-before-html-generation',
13+
(htmlPluginData, callback) => {
14+
addAllAssetsToCompilation(
15+
this.assets,
16+
compilation,
17+
htmlPluginData,
18+
callback
19+
);
20+
}
21+
);
1422
});
1523
}
1624
}

test.js

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ test('should used passed in publicPath', async () => {
6666
const compilation = { options: { output: { publicPath: 'vendor/' } } };
6767
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
6868

69-
await addAllAssetsToCompilation([{ filepath: 'my-file.js', publicPath: 'pp' }], compilation, pluginData, callback);
69+
await addAllAssetsToCompilation(
70+
[{ filepath: 'my-file.js', publicPath: 'pp' }],
71+
compilation,
72+
pluginData,
73+
callback
74+
);
7075

7176
expect(pluginData.assets).toMatchSnapshot();
7277

@@ -82,7 +87,12 @@ test('should add file missing "/" to public path', async () => {
8287
const compilation = { options: { output: { publicPath: 'vendor' } } };
8388
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
8489

85-
await addAllAssetsToCompilation([{ filepath: 'my-file.js' }], compilation, pluginData, callback);
90+
await addAllAssetsToCompilation(
91+
[{ filepath: 'my-file.js' }],
92+
compilation,
93+
pluginData,
94+
callback
95+
);
8696

8797
expect(pluginData.assets).toMatchSnapshot();
8898

@@ -94,26 +104,43 @@ test('should add sourcemap to compilation', async () => {
94104
const callback = jest.fn();
95105
const addFileToAssetsStub = jest.fn();
96106
const compilation = { options: { output: {} } };
97-
const pluginData = { assets: { js: [], css: [] }, plugin: { addFileToAssets: addFileToAssetsStub } };
107+
const pluginData = {
108+
assets: { js: [], css: [] },
109+
plugin: { addFileToAssets: addFileToAssetsStub },
110+
};
98111
addFileToAssetsStub.mockReturnValue(Promise.resolve('my-file.js'));
99112

100-
await addAllAssetsToCompilation([{ filepath: 'my-file.js' }], compilation, pluginData, callback);
113+
await addAllAssetsToCompilation(
114+
[{ filepath: 'my-file.js' }],
115+
compilation,
116+
pluginData,
117+
callback
118+
);
101119

102120
expect(pluginData.assets).toMatchSnapshot();
103121

104122
expect(callback).toHaveBeenCalledTimes(1);
105123
expect(callback).toHaveBeenCalledWith(null, pluginData);
106124

107125
expect(addFileToAssetsStub).toHaveBeenCalledTimes(2);
108-
expect(addFileToAssetsStub.mock.calls[0]).toEqual(['my-file.js', compilation]);
109-
expect(addFileToAssetsStub.mock.calls[1]).toEqual(['my-file.js.map', compilation]);
126+
expect(addFileToAssetsStub.mock.calls[0]).toEqual([
127+
'my-file.js',
128+
compilation,
129+
]);
130+
expect(addFileToAssetsStub.mock.calls[1]).toEqual([
131+
'my-file.js.map',
132+
compilation,
133+
]);
110134
});
111135

112136
test('should skip adding sourcemap to compilation if set to false', async () => {
113137
const callback = jest.fn();
114138
const addFileToAssetsStub = jest.fn();
115139
const compilation = { options: { output: {} } };
116-
const pluginData = { assets: { js: [], css: [] }, plugin: { addFileToAssets: addFileToAssetsStub } };
140+
const pluginData = {
141+
assets: { js: [], css: [] },
142+
plugin: { addFileToAssets: addFileToAssetsStub },
143+
};
117144
addFileToAssetsStub.mockReturnValue(Promise.resolve('my-file.js'));
118145

119146
await addAllAssetsToCompilation(
@@ -136,11 +163,18 @@ test('should include hash of file content if option is set', async () => {
136163
const callback = jest.fn();
137164
const compilation = {
138165
options: { output: {} },
139-
assets: { 'my-file.js': { source: () => 'some source code is cool to have;' } },
166+
assets: {
167+
'my-file.js': { source: () => 'some source code is cool to have;' },
168+
},
140169
};
141170
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
142171

143-
await addAllAssetsToCompilation([{ filepath: 'my-file.js', hash: true }], compilation, pluginData, callback);
172+
await addAllAssetsToCompilation(
173+
[{ filepath: 'my-file.js', hash: true }],
174+
compilation,
175+
pluginData,
176+
callback
177+
);
144178

145179
expect(pluginData.assets).toMatchSnapshot();
146180

@@ -152,11 +186,18 @@ test('should add to css if `typeOfAsset` is css', async () => {
152186
const callback = jest.fn();
153187
const compilation = {
154188
options: { output: {} },
155-
assets: { 'my-file.js': { source: () => 'some source code is cool to have;' } },
189+
assets: {
190+
'my-file.js': { source: () => 'some source code is cool to have;' },
191+
},
156192
};
157193
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
158194

159-
await addAllAssetsToCompilation([{ filepath: 'my-file.css', typeOfAsset: 'css' }], compilation, pluginData, callback);
195+
await addAllAssetsToCompilation(
196+
[{ filepath: 'my-file.css', typeOfAsset: 'css' }],
197+
compilation,
198+
pluginData,
199+
callback
200+
);
160201

161202
expect(pluginData.assets).toMatchSnapshot();
162203

@@ -176,7 +217,10 @@ test('should replace compilation assets key if `outputPath` is set', async () =>
176217
options: { output: {} },
177218
assets: {},
178219
};
179-
const pluginData = { assets: { js: [], css: [] }, plugin: { addFileToAssets: addFileToAssetsMock } };
220+
const pluginData = {
221+
assets: { js: [], css: [] },
222+
plugin: { addFileToAssets: addFileToAssetsMock },
223+
};
180224

181225
await addAllAssetsToCompilation(
182226
[{ filepath: 'my-file.js', outputPath: 'assets' }],
@@ -199,7 +243,12 @@ test('filter option should exclude some files', async () => {
199243
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
200244

201245
await addAllAssetsToCompilation(
202-
[{ filepath: path.join(__dirname, 'my-file.js'), files: ['something-weird'] }],
246+
[
247+
{
248+
filepath: path.join(__dirname, 'my-file.js'),
249+
files: ['something-weird'],
250+
},
251+
],
203252
compilation,
204253
pluginData,
205254
callback

0 commit comments

Comments
 (0)