From 8955767f95a137a965c0fda4cb8bb6e6290cc744 Mon Sep 17 00:00:00 2001 From: hymbz Date: Thu, 19 Dec 2024 18:54:09 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20:construction=5Fworker:=20=E7=BD=91?= =?UTF-8?q?=E5=9D=80=E5=8F=91=E5=B8=83=E9=A1=B5=E5=A4=B1=E6=95=88=E4=B8=8D?= =?UTF-8?q?=E5=BD=B1=E5=93=8D=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rollup-plugin/siteUrl.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/rollup-plugin/siteUrl.ts b/src/rollup-plugin/siteUrl.ts index a0b6bfa7..0b01b756 100644 --- a/src/rollup-plugin/siteUrl.ts +++ b/src/rollup-plugin/siteUrl.ts @@ -18,14 +18,21 @@ const siteUrlFnMap = { let siteUrlMap: Record | undefined; -const initSiteUrlMap = async () => - Object.fromEntries( - await Promise.all( - Object.entries(siteUrlFnMap).map( - async ([name, fn]) => [name, await fn()] as const, - ), - ), +const initSiteUrlMap = async () => { + const map = {} as Record; + await Promise.all( + Object.entries(siteUrlFnMap).map(async ([name, fn]) => { + try { + const list = await fn(); + if (list.length === 0) throw new Error(`未找到可用网址`); + map[name] = list; + } catch { + console.error(`获取可用网址失败,${name}发布页已失效`); + } + }), ); + return map; +}; /** 根据发布页自动获取可用网址 */ export const siteUrl: OutputPluginOption = { @@ -36,13 +43,13 @@ export const siteUrl: OutputPluginOption = { return code.replaceAll( /case 'siteUrl#(.+?)':(.+?)(?={)/gs, (_, name, other) => { - if (!Reflect.has(siteUrlMap!, name)) - throw new Error(`未知站点:${name}`); + if (!Reflect.has(siteUrlMap!, name)) { + console.error(`未知站点: ${name}`); + return ''; + } const list = siteUrlMap![name].filter((url) => URL.canParse(`https://${url}`), ); - if (list.length === 0) - throw new Error(`未找到可用网址,${name}发布页已失效`); const otherUrlList = new Set( [...other.matchAll(/(?<=case ').+?(?=':)/g)].flat(),