From 98e27b5b06ab88ce048d91e21ea62edf55753c27 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Sun, 24 Jan 2021 12:06:35 +0100 Subject: [PATCH] fix: resolve correct result if filesnapshot is out of date --- package.json | 2 +- src/cache.js | 23 ++++++----------------- src/hash.js | 7 +++++-- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 98311095..e45f506d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "favicons-webpack-plugin", - "version": "5.0.0-alpha.8", + "version": "5.0.0-alpha.9", "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 362eec96..b9734bbe 100644 --- a/src/cache.js +++ b/src/cache.js @@ -1,29 +1,16 @@ -// / @ts-check +// @ts-check // Import types /** @typedef {ReturnType} WebpackCacheFacade */ /** @typedef {import("webpack").Compilation} WebpackCompilation */ /** @typedef {Parameters[0]} Snapshot */ -/** @typedef {{, - publicPath: string, - tags: string[], - assets: Array<{ - name: string, - contents: import('webpack').sources.RawSource - }> -}} FaviconsCompilationResult */ - const path = require('path'); -const { - replaceContentHash, - resolvePublicPath, - getContentHash -} = require('./hash'); +const { getContentHash } = require('./hash'); /** @type {WeakMap>} */ const snapshots = new WeakMap(); -/** @type {WeakMap, Promise>} */ +/** @type {WeakMap, Promise>} */ const faviconCache = new WeakMap(); /** @@ -52,6 +39,7 @@ function runCached( generator ) { const latestSnapShot = snapshots.get(pluginInstance); + /** @type {Promise | undefined} */ const cachedFavicons = latestSnapShot && faviconCache.get(latestSnapShot); if (latestSnapShot && cachedFavicons) { @@ -64,9 +52,10 @@ function runCached( return runCached( files, pluginInstance, + useWebpackCache, compilation, - idGenerator, eTags, + idGenerator, generator ); } diff --git a/src/hash.js b/src/hash.js index 74bf28a3..93e2ff13 100644 --- a/src/hash.js +++ b/src/hash.js @@ -1,4 +1,4 @@ -// / @ts-check +// @ts-check // Import types /** @typedef {import("webpack").Compilation} WebpackCompilation */ @@ -55,9 +55,12 @@ function appendSlash(url) { /** * Returns the content hash for the given file content - * @param {Buffer|string} file + * @param {Buffer | string | undefined} file */ function getContentHash(file) { + if (!file) { + return ''; + } return crypto .createHash('sha256') .update(file.toString('utf8'))