From 19e97193d3ab5cedb48d2df972f9b860a41f4c68 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 5 Apr 2026 09:48:04 +0100 Subject: [PATCH] fix(ci): make discord doctor loading bundler-safe --- extensions/discord/src/shared.ts | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/extensions/discord/src/shared.ts b/extensions/discord/src/shared.ts index 404d79d876b..5aebe5d6f94 100644 --- a/extensions/discord/src/shared.ts +++ b/extensions/discord/src/shared.ts @@ -1,4 +1,3 @@ -import { createJiti } from "jiti"; import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers"; import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from"; import { adaptScopedAccountAccessor } from "openclaw/plugin-sdk/channel-config-helpers"; @@ -13,6 +12,7 @@ import { } from "./accounts.js"; import { getChatChannelMeta, type ChannelPlugin } from "./channel-api.js"; import { DiscordChannelConfigSchema } from "./config-schema.js"; +import { normalizeCompatibilityConfig } from "./doctor-contract.js"; import { DISCORD_LEGACY_CONFIG_RULES } from "./doctor-shared.js"; import { collectRuntimeConfigAssignments, @@ -29,40 +29,25 @@ export const DISCORD_CHANNEL = "discord" as const; type DiscordDoctorModule = typeof import("./doctor.js"); let discordDoctorModulePromise: Promise | undefined; -let discordDoctorLoader: ReturnType | undefined; -let cachedDiscordDoctorModule: DiscordDoctorModule | undefined; async function loadDiscordDoctorModule(): Promise { discordDoctorModulePromise ??= import("./doctor.js"); return await discordDoctorModulePromise; } -function loadDiscordDoctorModuleSync(): DiscordDoctorModule { - if (cachedDiscordDoctorModule) { - return cachedDiscordDoctorModule; - } - discordDoctorLoader ??= createJiti(import.meta.url, { interopDefault: true }); - cachedDiscordDoctorModule = discordDoctorLoader("./doctor.js") as DiscordDoctorModule; - return cachedDiscordDoctorModule; -} - const discordDoctor: ChannelDoctorAdapter = { dmAllowFromMode: "topOrNested", groupModel: "route", groupAllowFromFallbackToAllowFrom: false, warnOnEmptyGroupSenderAllowlist: false, legacyConfigRules: DISCORD_LEGACY_CONFIG_RULES, - normalizeCompatibilityConfig: (params) => - loadDiscordDoctorModuleSync().discordDoctor.normalizeCompatibilityConfig?.(params) ?? { - config: params.cfg, - changes: [], - }, + normalizeCompatibilityConfig, collectPreviewWarnings: async (params) => (await loadDiscordDoctorModule()).discordDoctor.collectPreviewWarnings?.(params) ?? [], collectMutableAllowlistWarnings: async (params) => (await loadDiscordDoctorModule()).discordDoctor.collectMutableAllowlistWarnings?.(params) ?? [], - repairConfig: (params) => - loadDiscordDoctorModuleSync().discordDoctor.repairConfig?.(params) ?? { + repairConfig: async (params) => + (await loadDiscordDoctorModule()).discordDoctor.repairConfig?.(params) ?? { config: params.cfg, changes: [], },