From 2f0285ffbb8dc31989ed30d37934a09dbcae0009 Mon Sep 17 00:00:00 2001 From: codecalm Date: Sun, 14 Dec 2025 19:54:27 +0100 Subject: [PATCH] Refactor build-outline.mjs to improve cache handling and error management by replacing existsSync with try/catch for file checks, ensuring smoother processing of SVG icons. --- packages/icons-webfont/.build/build-outline.mjs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/icons-webfont/.build/build-outline.mjs b/packages/icons-webfont/.build/build-outline.mjs index d9adb065e..dee957712 100644 --- a/packages/icons-webfont/.build/build-outline.mjs +++ b/packages/icons-webfont/.build/build-outline.mjs @@ -62,19 +62,21 @@ const buildOutline = async () => { const filename = `u${unicode.toUpperCase()}-${name}.svg` const filePath = resolve(DIR, `icons-outlined/${strokeName}/${type}/${filename}`) - // Check cache - if (fs.existsSync(filePath)) { - let cachedContent = fs.readFileSync(filePath, 'utf-8') + // Check cache (try/catch faster than existsSync + readFileSync) + try { + const cachedContent = fs.readFileSync(filePath, 'utf-8') let cachedHash = '' - cachedContent = cachedContent.replace(//, (m, hash) => { + const contentWithoutHash = cachedContent.replace(//, (m, hash) => { cachedHash = hash return '' }) - if (crypto.createHash('sha1').update(cachedContent).digest("hex") === cachedHash) { + if (cachedHash && crypto.createHash('sha1').update(contentWithoutHash).digest("hex") === cachedHash) { cached++ return } + } catch (e) { + // File doesn't exist, will be created } // Prepare content @@ -135,11 +137,13 @@ const buildOutline = async () => { const iconName = `u${unicode.toUpperCase()}-${name}` const srcPath = resolve(DIR, `icons-outlined/${strokeName}/${type}/${iconName}.svg`) - if (fs.existsSync(srcPath)) { + try { fs.copyFileSync( srcPath, resolve(DIR, `icons-outlined/${strokeName}/all/${iconName}${type !== 'outline' ? `-${type}` : ''}.svg`) ) + } catch (e) { + // Source file doesn't exist, skip } } }