Skip to content

Commit

Permalink
fix: resolve correct result if filesnapshot is out of date
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Jan 24, 2021
1 parent f653ac7 commit 98e27b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
23 changes: 6 additions & 17 deletions src/cache.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
// / @ts-check
// @ts-check

// Import types
/** @typedef {ReturnType<import("webpack").Compiler['getCache']>} WebpackCacheFacade */
/** @typedef {import("webpack").Compilation} WebpackCompilation */
/** @typedef {Parameters<WebpackCompilation['fileSystemInfo']['checkSnapshotValid']>[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<any, Promise<Snapshot>>} */
const snapshots = new WeakMap();
/** @type {WeakMap<Promise<Snapshot>, Promise<FaviconsCompilationResult>>} */
/** @type {WeakMap<Promise<Snapshot>, Promise<any>>} */
const faviconCache = new WeakMap();

/**
Expand Down Expand Up @@ -52,6 +39,7 @@ function runCached(
generator
) {
const latestSnapShot = snapshots.get(pluginInstance);
/** @type {Promise<TResult> | undefined} */
const cachedFavicons = latestSnapShot && faviconCache.get(latestSnapShot);

if (latestSnapShot && cachedFavicons) {
Expand All @@ -64,9 +52,10 @@ function runCached(
return runCached(
files,
pluginInstance,
useWebpackCache,
compilation,
idGenerator,
eTags,
idGenerator,
generator
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/hash.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// / @ts-check
// @ts-check

// Import types
/** @typedef {import("webpack").Compilation} WebpackCompilation */
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 98e27b5

Please sign in to comment.