From 74dc8ea0b0757e4c9f3c84d9de69774702ce8214 Mon Sep 17 00:00:00 2001 From: Okiki Ojo Date: Thu, 12 Feb 2026 17:02:14 -0500 Subject: [PATCH] feat: enhance CdnResolution to support remapFalse configuration for excluded modules Signed-off-by: Okiki Ojo --- core/plugins/cdn.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/core/plugins/cdn.ts b/core/plugins/cdn.ts index f3e532c..16c9959 100644 --- a/core/plugins/cdn.ts +++ b/core/plugins/cdn.ts @@ -86,7 +86,7 @@ import { extname, isBareImport, join } from "@bundle/utils/path"; import { fetchWithCache } from "@bundle/utils/fetch-and-cache"; import { deepMerge } from "@bundle/utils/deep-object"; -import { determineExtension, HTTP_NAMESPACE } from "./http.ts"; +import { determineExtension, HTTP_NAMESPACE, EXCLUDED_MODULE_NAMESPACE } from "./http.ts"; import { dispatchEvent, LOGGER_WARN } from "../configs/events.ts"; import { getCDNUrl, getCDNStyle, DEFAULT_CDN_HOST } from "../utils/cdn-format.ts"; @@ -713,7 +713,7 @@ export function CdnResolution(StateContext: Context>) { }); if (resolutionResult.excluded && conditions.browser) { - // Generate accurate error message based on exclusion reason + // Generate accurate message based on exclusion reason const reason = (resolutionResult as { exclusionReason?: string }).exclusionReason; let text: string; @@ -730,6 +730,24 @@ export function CdnResolution(StateContext: Context>) { detail = resolutionResult.error?.message ?? "Unknown resolution error"; } + // ── Respect remapFalse.packageRemapFalse config ── + // Default is "error". When set to "stub", produce an empty export + // instead of a hard build error. + const packagePolicy = LocalConfig.remapFalse?.packageRemapFalse ?? "error"; + + if (packagePolicy === "stub") { + const warnOnStub = LocalConfig.remapFalse?.warnOnStubbedRemapFalse ?? true; + return { + path: `${effectiveName}/${combinedSubpath || "."}`, + namespace: EXCLUDED_MODULE_NAMESPACE, + pluginData: Object.assign({}, args.pluginData, { + excludedBy: reason ?? "field-remapping", + originalPath: combinedSubpath || ".", + suppressWarning: !warnOnStub, + }), + }; + } + return { errors: [{ text, detail }], }; -- 2.51.2