Skip to content

Commit

Permalink
fix: allow compiling multiple icon sets
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Jan 29, 2021
1 parent 8f0c1f6 commit 03c3514
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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": [
Expand Down
2 changes: 1 addition & 1 deletion src/cache.js
Expand Up @@ -39,8 +39,8 @@ function runCached(
idGenerator,
generator
) {
const logger = webpackLogger(compilation);
const latestSnapShot = snapshots.get(pluginInstance);

/** @type {Promise<TResult> | undefined} */
const cachedFavicons = latestSnapShot && faviconCache.get(latestSnapShot);

Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Expand Up @@ -9,9 +9,6 @@ const url = require('url');
const { resolvePublicPath, replaceContentHash } = require('./hash');
const { webpackLogger } = require('./logger');

/** @type {WeakMap<any, Promise<{tags: string[], assets: Array<{name: string, contents: import('webpack').sources.RawSource}>}>>} */
const faviconCompilations = new WeakMap();

class FaviconsWebpackPlugin {
/**
* @param {import('./options').FaviconWebpackPlugionOptions | string} args
Expand Down Expand Up @@ -48,6 +45,8 @@ class FaviconsWebpackPlugin {
const webpack = compiler.webpack;
const Compilation = webpack.Compilation;
const oracle = new Oracle(compiler.context);
/** @type {WeakMap<any, Promise<{tags: string[], assets: Array<{name: string, contents: import('webpack').sources.RawSource}>}>>} */
const faviconCompilations = new WeakMap();

{
const {
Expand Down
27 changes: 27 additions & 0 deletions 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);
});
47 changes: 47 additions & 0 deletions 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: `␊
<!doctype html>␊
<html>␊
<head>␊
<link rel="icon"␊
href="/assets/favicon.png"␊
>␊
<link rel="icon"␊
href="/second/favicon.png"␊
>␊
</head>␊
<body>␊
</body>␊
</html>␊
`,
},
{
assetName: 'second/favicon.png',
content: 'png 874x989',
},
]
Binary file added test/snapshots/light.multiple.test.js.snap
Binary file not shown.

0 comments on commit 03c3514

Please sign in to comment.