Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Aug 12, 2023
1 parent 92d9e1b commit 3d9df02
Show file tree
Hide file tree
Showing 8 changed files with 2,075 additions and 1,458 deletions.
3,403 changes: 2,010 additions & 1,393 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"html-webpack-plugin": "^5.5.0",
"image-size": "^1.0.2",
"nyc": "^15.0.0",
"prettier": "^2.7.1",
"prettier": "^3.0.1",
"rimraf": "^5.0.0",
"standard-version": "^9.5.0",
"typescript": "^5.0.4",
Expand Down
22 changes: 11 additions & 11 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ async function runCached(
compilation,
eTags,
idGenerator,
generator
generator,
) {
const latestSnapShot = snapshots.get(pluginInstance);

if (latestSnapShot) {
const cachedFavicons = faviconCache.get(latestSnapShot);
if (cachedFavicons) {
const isValid = await asPromise((cb) =>
compilation.fileSystemInfo.checkSnapshotValid(latestSnapShot, cb)
compilation.fileSystemInfo.checkSnapshotValid(latestSnapShot, cb),
);

if (isValid) {
Expand All @@ -87,8 +87,8 @@ async function runCached(
[],
[],
{},
cb
)
cb,
),
);

if (!newSnapShot) {
Expand All @@ -104,10 +104,10 @@ async function runCached(
compilation,
idGenerator,
eTags,
generator
generator,
)
: readFiles(absoluteFilePaths, compilation).then((fileContents) =>
generator(fileContents, idGenerator(fileContents))
generator(fileContents, idGenerator(fileContents)),
));

// Store the promise of the favicon compilation in cache
Expand Down Expand Up @@ -138,7 +138,7 @@ async function runWithFileCache(
compilation,
idGenerator,
eTags,
generator
generator,
) {
const fileSources = await readFiles(files, compilation);
const webpackCache = compilation.getCache('favicons-webpack-plugin');
Expand All @@ -147,7 +147,7 @@ async function runWithFileCache(
const cacheId = idGenerator(fileSources);

return webpackCache.providePromise(cacheId, eTag, () =>
generator(fileSources, cacheId)
generator(fileSources, cacheId),
);
}

Expand All @@ -168,16 +168,16 @@ function readFiles(absoluteFilePaths, compilation) {
const content = await asPromise((cb) =>
compilation.inputFileSystem.readFile(
path.resolve(compilation.compiler.context, absoluteFilePath),
cb
)
cb,
),
);

return {
filePath: absoluteFilePath,
hash: getContentHash(content),
content,
};
})
}),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function resolvePublicPath(compilation, publicPath, assetPath) {

const fullAssetPath = url.resolve(
appendSlash(publicPathString || ''),
assetPath
assetPath,
);

return fullAssetPath;
Expand Down
80 changes: 40 additions & 40 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ class FaviconsWebpackPlugin {
// @ts-ignore
assert(
typeof this.#options.logo[0] === 'string',
'Could not find `logo.png` for the current webpack context'
'Could not find `logo.png` for the current webpack context',
);
} else if (this.#options.logo instanceof Array) {
this.#options.logo = this.#options.logo.map((logo) =>
path.resolve(compiler.context, logo)
path.resolve(compiler.context, logo),
);
} else {
this.#options.logo = [path.resolve(compiler.context, this.#options.logo)];
Expand All @@ -100,11 +100,11 @@ class FaviconsWebpackPlugin {
// @ts-ignore
assert(
this.#options.logoMaskable instanceof Array,
'options.logoMaskable must be string or array '
'options.logoMaskable must be string or array ',
);

logoMaskable = this.#options.logoMaskable.map((logoMaskable) =>
path.resolve(compiler.context, logoMaskable)
path.resolve(compiler.context, logoMaskable),
);
}
} else {
Expand All @@ -114,7 +114,7 @@ class FaviconsWebpackPlugin {
if (typeof this.#options.manifest === 'string') {
this.#options.manifest = path.resolve(
compiler.context,
this.#options.manifest
this.#options.manifest,
);
}

Expand Down Expand Up @@ -145,17 +145,17 @@ class FaviconsWebpackPlugin {
getRelativeOutputPath(
getContentHash(...fileSources.map((s) => s.content)),
compilation,
this.#options
this.#options,
),
(fileSources, outputPath) => {
const logoFileSources = fileSources.slice(
0,
this.#options.logo.length
this.#options.logo.length,
);

const logoMaskableFileSources = fileSources.slice(
this.#options.logo.length,
this.#options.logo.length + logoMaskable.length
this.#options.logo.length + logoMaskable.length,
);

const manifestFileSource =
Expand All @@ -165,7 +165,7 @@ class FaviconsWebpackPlugin {
logoFileSources,
logoMaskableFileSources,
manifestFileSource.content,
compilation
compilation,
).then((favicons) => {
const RawSource = compilation.compiler.webpack.sources.RawSource;

Expand All @@ -179,7 +179,7 @@ class FaviconsWebpackPlugin {
})),
};
});
}
},
);

// Watch for changes to the logo
Expand Down Expand Up @@ -223,7 +223,7 @@ class FaviconsWebpackPlugin {
// relative: my/app/
const publicPathFromHtml = url.resolve(
htmlPluginData.publicPath,
faviconCompilationResult.publicPath
faviconCompilationResult.publicPath,
);

// Prefix links to icons
Expand All @@ -246,13 +246,13 @@ class FaviconsWebpackPlugin {
attributes: attrs.reduce(
(obj, { name, value }) =>
Object.assign(obj, { [name]: value }),
{}
{},
),
};
// Prefix link tags
if (typeof htmlTag.attributes.href === 'string') {
htmlTag.attributes.href = pathReplacer(
htmlTag.attributes.href
htmlTag.attributes.href,
);
}
// Prefix meta tags
Expand All @@ -264,24 +264,24 @@ class FaviconsWebpackPlugin {
].includes(htmlTag.attributes.name)
) {
htmlTag.attributes.content = pathReplacer(
htmlTag.attributes.content
htmlTag.attributes.content,
);
}

return htmlTag;
})
}),
);

return htmlPluginData;
}
},
);
}

// Save the promise and execute the callback immediately to not block
// the webpack build see the `afterCompile` FaviconsWebpackPlugin hook
// implementation where the promise is picked up again
faviconCompilations.set(compilation, faviconCompilation);
}
},
);

compiler.hooks.thisCompilation.tap(
Expand All @@ -300,9 +300,9 @@ class FaviconsWebpackPlugin {
compilation.emitAsset(name, contents);
});
}
}
},
);
}
},
);

// Make sure that the build waits for the favicon generation to complete
Expand All @@ -314,7 +314,7 @@ class FaviconsWebpackPlugin {
if (faviconCompilation) {
await faviconCompilation;
}
}
},
);
}

Expand All @@ -330,23 +330,23 @@ class FaviconsWebpackPlugin {
logoFileSources,
logoMaskableFileSources,
baseManifest,
compilation
compilation,
) {
const logoFileSourceContents = logoFileSources.map(
(source) => source.content
(source) => source.content,
);

const logoMaskableFileSourceContents = logoMaskableFileSources.map(
(source) => source.content
(source) => source.content,
);

const resolvedPublicPath = getResolvedPublicPath(
getContentHash(
...logoFileSourceContents,
...logoMaskableFileSourceContents
...logoMaskableFileSourceContents,
),
compilation,
this.#options
this.#options,
);

/** @type {{[key: string]: any}} - the parsed manifest from options.manifest */
Expand All @@ -359,15 +359,15 @@ class FaviconsWebpackPlugin {
case 'light':
if (!this.#options.mode) {
webpackLogger(compilation).info(
'generate only a single favicon for fast compilation time in development mode. This behaviour can be changed by setting the favicon mode option.'
'generate only a single favicon for fast compilation time in development mode. This behaviour can be changed by setting the favicon mode option.',
);
}

return this.#generateFaviconsLight(
logoFileSourceContents,
logoMaskableFileSourceContents,
parsedBaseManifest,
resolvedPublicPath
resolvedPublicPath,
);
case 'webapp':
default:
Expand All @@ -377,7 +377,7 @@ class FaviconsWebpackPlugin {
logoFileSourceContents,
logoMaskableFileSourceContents,
parsedBaseManifest,
resolvedPublicPath
resolvedPublicPath,
);
}
}
Expand All @@ -396,7 +396,7 @@ class FaviconsWebpackPlugin {
logoFileSources,
logoMaskableFileSources,
baseManifest,
resolvedPublicPath
resolvedPublicPath,
) {
const faviconExt = path.extname(this.#options.logo[0]);
const faviconName = `favicon${faviconExt}`;
Expand All @@ -423,7 +423,7 @@ class FaviconsWebpackPlugin {
],
}),
null,
2
2,
),
});
}
Expand All @@ -449,7 +449,7 @@ class FaviconsWebpackPlugin {
logoFileSources,
logoMaskableFileSources,
baseManifest,
resolvedPublicPath
resolvedPublicPath,
) {
const { favicons } = loadFaviconsLibrary();

Expand Down Expand Up @@ -479,7 +479,7 @@ class FaviconsWebpackPlugin {
contents: JSON.stringify(
mergeManifests(generatedManifest, baseManifest),
null,
2
2,
),
};
}
Expand Down Expand Up @@ -533,7 +533,7 @@ function getRelativeOutputPath(logoContentHash, compilation, faviconOptions) {
const relativeOutputPath = faviconOptions.outputPath
? path.relative(
compilationOutputPath,
path.resolve(compilationOutputPath, faviconOptions.outputPath)
path.resolve(compilationOutputPath, faviconOptions.outputPath),
)
: faviconOptions.prefix;

Expand All @@ -557,9 +557,9 @@ function getResolvedPublicPath(logoContentHash, compilation, faviconOptions) {
resolvePublicPath(
compilation,
faviconOptions.publicPath || webpackPublicPath,
faviconOptions.prefix
faviconOptions.prefix,
),
logoContentHash
logoContentHash,
);
}

Expand Down Expand Up @@ -625,7 +625,7 @@ function findHtmlWebpackPlugin(compilation) {
* Find only HtmlWebpkackPlugin constructors
* @type {(constructor: Function) => constructor is typeof import('html-webpack-plugin')}
*/
(constructor) => constructor && constructor.name === 'HtmlWebpackPlugin'
(constructor) => constructor && constructor.name === 'HtmlWebpackPlugin',
);

if (!HtmlWebpackPlugin) {
Expand All @@ -638,8 +638,8 @@ function findHtmlWebpackPlugin(compilation) {
`${
'FaviconsWebpackPlugin - This FaviconsWebpackPlugin version is not compatible with your current HtmlWebpackPlugin version.\n' +
'Please upgrade to HtmlWebpackPlugin >= 5 OR downgrade to FaviconsWebpackPlugin 2.x\n'
}${getHtmlWebpackPluginVersion()}`
)
}${getHtmlWebpackPluginVersion()}`,
),
);

return undefined;
Expand All @@ -660,8 +660,8 @@ function loadFaviconsLibrary() {
} catch (e) {
throw new Error(
`Could not find the npm peerDependency "favicons".\nPlease run:\nnpm i favicons\n - or -\nyarn add favicons\n\n${String(
e
)}`
e,
)}`,
);
}
}
Expand Down
Loading

0 comments on commit 3d9df02

Please sign in to comment.