From 03c351434600c5f8eded4757f3efa9f728cd0de1 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Fri, 29 Jan 2021 09:37:10 +0100 Subject: [PATCH] fix: allow compiling multiple icon sets --- package.json | 2 +- src/cache.js | 2 +- src/index.js | 5 +-- test/light.multiple.test.js | 27 ++++++++++++ test/snapshots/light.multiple.test.js.md | 47 +++++++++++++++++++++ test/snapshots/light.multiple.test.js.snap | Bin 0 -> 433 bytes 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 test/light.multiple.test.js create mode 100644 test/snapshots/light.multiple.test.js.md create mode 100644 test/snapshots/light.multiple.test.js.snap diff --git a/package.json b/package.json index 5cab0bd1..89b435dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "favicons-webpack-plugin", - "version": "5.0.0-alpha.11", + "version": "5.0.0-alpha.12", "description": "Let webpack generate all your favicons and icons for you", "main": "src/index.js", "files": [ diff --git a/src/cache.js b/src/cache.js index d6606184..1a0a2477 100644 --- a/src/cache.js +++ b/src/cache.js @@ -39,8 +39,8 @@ function runCached( idGenerator, generator ) { - const logger = webpackLogger(compilation); const latestSnapShot = snapshots.get(pluginInstance); + /** @type {Promise | undefined} */ const cachedFavicons = latestSnapShot && faviconCache.get(latestSnapShot); diff --git a/src/index.js b/src/index.js index 4882e027..2fccc530 100644 --- a/src/index.js +++ b/src/index.js @@ -9,9 +9,6 @@ const url = require('url'); const { resolvePublicPath, replaceContentHash } = require('./hash'); const { webpackLogger } = require('./logger'); -/** @type {WeakMap}>>} */ -const faviconCompilations = new WeakMap(); - class FaviconsWebpackPlugin { /** * @param {import('./options').FaviconWebpackPlugionOptions | string} args @@ -48,6 +45,8 @@ class FaviconsWebpackPlugin { const webpack = compiler.webpack; const Compilation = webpack.Compilation; const oracle = new Oracle(compiler.context); + /** @type {WeakMap}>>} */ + const faviconCompilations = new WeakMap(); { const { diff --git a/test/light.multiple.test.js b/test/light.multiple.test.js new file mode 100644 index 00000000..dddbc1dd --- /dev/null +++ b/test/light.multiple.test.js @@ -0,0 +1,27 @@ +const test = require('ava'); +const path = require('path'); +const fs = require('fs-extra'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const FaviconsWebpackPlugin = require('../'); + +const { logo, mkdir, generate, snapshotCompilationAssets } = require('./util'); + +test.beforeEach(async t => (t.context.root = await mkdir())); + +test('should generate multiple light icons', async t => { + const dist = path.join(t.context.root, 'dist'); + const compilationStats = await generate({ + context: t.context.root, + output: { + path: dist, + publicPath: '/' + }, + plugins: [ + new HtmlWebpackPlugin(), + new FaviconsWebpackPlugin({ logo, mode: 'light' }), + new FaviconsWebpackPlugin({ logo, mode: 'light', prefix: 'second/' }) + ] + }); + + snapshotCompilationAssets(t, compilationStats); +}); diff --git a/test/snapshots/light.multiple.test.js.md b/test/snapshots/light.multiple.test.js.md new file mode 100644 index 00000000..c0c227c5 --- /dev/null +++ b/test/snapshots/light.multiple.test.js.md @@ -0,0 +1,47 @@ +# Snapshot report for `test/light.multiple.test.js` + +The actual snapshot is saved in `light.multiple.test.js.snap`. + +Generated by [AVA](https://ava.li). + +## should generate multiple light icons + +> Snapshot 1 + + [ + 'assets/favicon.png', + 'index.html', + 'main.js', + 'second/favicon.png', + ] + +> Snapshot 2 + + [ + { + assetName: 'assets/favicon.png', + content: 'png 874x989', + }, + { + assetName: 'index.html', + content: `␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + `, + }, + { + assetName: 'second/favicon.png', + content: 'png 874x989', + }, + ] diff --git a/test/snapshots/light.multiple.test.js.snap b/test/snapshots/light.multiple.test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..41dbc9144c21fb7543876a794c551410ef1b5b7b GIT binary patch literal 433 zcmV;i0Z#rwRzV+~1h*OGH2&Js*n*00000000A( zQaw+?P!xT)Ghd>j=CMWmw-gD2py|4R(5FiKntFQ4#>;6@L&p#Q?w?z2!GQm(LL?-Dl z2WyZlVXPu3;ui6U*oIUNk|&-=M*xDUs!Bj1kRY&u3W@B1Ody$qE$aI$@Qo%N*o~fB z=)0|n1VCsM+qKxR&<>ogs7a!hcBt(ZI=(2#Q)8c@pEYYdGkKzj@d$B>sQooHI%WVa zqh@4xJVHpHIhDAj{E2jo*oBE*s#fo?MgY>3X0zE)dW@1YgtsV_W6}$}fosHrv>;8) zOE<$YRK5hUg7t8>=hR_Kw>{UB#&p2kK)h#AqLmJd!*Z#-;vsX_wai?4BZ|3a^%}vb z&or*DDrOWk&1^Gjae}mKyEmH0x)q&It%u3zX?v_$(T(_LMWR*v