2121import sharp , { type Metadata } from 'sharp'
2222import toIco from 'to-ico'
2323import { writeFile , mkdir } from 'fs/promises'
24- import { ClientScriptError } from '@components/scripts/errors'
24+ import { isTest } from '@lib/config'
25+ import { BuildError } from '@lib/errors'
2526
2627type IconGenerator = ( _options : Metadata ) => Promise < Buffer >
2728
2829const faviconPath = `src/assets/favicon.svg`
2930const generateIcoFavicon : IconGenerator = async ( { width, height, density } ) => {
3031 if ( ! width || ! height || ! density ) {
3132 const message = `Required option not passed to generateIcoFavicon`
32- throw new ClientScriptError ( { message } )
33+ throw new BuildError ( { message } )
3334 }
3435 const faviconDimensions = [ 32 , 64 ]
3536 // Create buffer for each size
@@ -47,7 +48,7 @@ const generateIcoFavicon: IconGenerator = async ({ width, height, density }) =>
4748const generatePngFavicon : IconGenerator = ( { density, width, height } ) => {
4849 if ( ! width || ! height || ! density ) {
4950 const message = `Required option not passed to generatePngFavicon`
50- throw new ClientScriptError ( { message } )
51+ throw new BuildError ( { message } )
5152 }
5253 return sharp ( faviconPath , {
5354 density : ( 180 / Math . max ( width , height ) ) * density ,
@@ -60,7 +61,7 @@ const generatePngFavicon: IconGenerator = ({ density, width, height }) => {
6061const generatePwaIcon = ( size : number ) : IconGenerator => ( { density, width, height } ) => {
6162 if ( ! width || ! height || ! density ) {
6263 const message = `Required option not passed to generatePwaIcon`
63- throw new ClientScriptError ( { message } )
64+ throw new BuildError ( { message } )
6465 }
6566 return sharp ( faviconPath , {
6667 density : ( size / Math . max ( width , height ) ) * density ,
@@ -102,7 +103,7 @@ export const buildFavicons = async () => {
102103}
103104
104105// Execute when run directly (ES module), but not during tests
105- if ( process . env [ 'NODE_ENV' ] !== 'test' ) {
106+ if ( ! isTest ( ) ) {
106107 buildFavicons ( ) . catch ( ( error ) => {
107108 console . error ( '❌ Failed to generate favicons:' , error )
108109 process . exit ( 1 )
0 commit comments