From 67b7c0b0d773bad8c30a456eb01f2625f3637311 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 17 May 2025 15:48:20 +0800 Subject: [PATCH] Fix: Stash Hosts --- ...ic-direct-lan-ruleset-dns-mapping-module.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts b/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts index e52252ae..020d68ef 100644 --- a/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts +++ b/Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts @@ -194,7 +194,7 @@ export const buildDomesticRuleset = task(require.main === module, __filename)(as yaml.stringify( dataset.reduce<{ dns: { 'nameserver-policy': Record }, - hosts: Record + hosts: Record }>((acc, cur) => { const { domains, dns, ...rest } = cur[1]; domains.forEach((domain) => { @@ -216,7 +216,21 @@ export const buildDomesticRuleset = task(require.main === module, __filename)(as }); if ('hosts' in rest) { - Object.assign(acc.hosts, rest.hosts); + // eslint-disable-next-line guard-for-in -- known plain object + for (const domain in rest.hosts) { + const dest = rest.hosts[domain]; + + if (domain in acc.hosts) { + if (typeof acc.hosts[domain] === 'string') { + acc.hosts[domain] = [acc.hosts[domain]]; + } + acc.hosts[domain].push(...dest); + } else if (dest.length === 1) { + acc.hosts[domain] = dest[0]; + } else { + acc.hosts[domain] = dest; + } + } } return acc;