From fcc25d0e1f901eb7fccb3e0e8d4be49391b36ca1 Mon Sep 17 00:00:00 2001 From: Okiki Ojo Date: Fri, 30 Jan 2026 18:28:14 -0500 Subject: [PATCH] chore: fix browser-supported package checks cdn-resolutions.ts Signed-off-by: Okiki Ojo --- core/build.ts | 2 +- core/plugins/cdn.ts | 2 +- core/utils/cdn-resolution.ts | 27 ++++++++++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/core/build.ts b/core/build.ts index 678560e..7db0578 100644 --- a/core/build.ts +++ b/core/build.ts @@ -42,7 +42,7 @@ export const BUILD_CONFIG: BuildConfig = { "minify": true, "treeShaking": true, - "platform": "neutral", + "platform": "node", "jsx": "transform" }, diff --git a/core/plugins/cdn.ts b/core/plugins/cdn.ts index 760f173..da80d53 100644 --- a/core/plugins/cdn.ts +++ b/core/plugins/cdn.ts @@ -491,7 +491,7 @@ export function CdnResolution(StateContext: Context>) { allowLiteralSubpath: !isSubpathDirectoryPackage && combinedSubpath.trim().length > 0, }); - if (resolutionResult.excluded) { + if (resolutionResult.excluded && conditions.browser) { // Module is excluded for browser (e.g., browser: false) return { errors: [{ diff --git a/core/utils/cdn-resolution.ts b/core/utils/cdn-resolution.ts index 01e1a5f..a551c78 100644 --- a/core/utils/cdn-resolution.ts +++ b/core/utils/cdn-resolution.ts @@ -30,7 +30,7 @@ import type { PackageJson, FullPackageVersion } from "@bundle/utils/types"; import type { SideEffectsMatchers } from "./side-effects.ts"; import type { ResolverConditions as BaseResolverConditions } from "@bundle/utils/resolve-conditions"; -import { resolve, legacy } from "@bundle/utils/resolve-exports-imports"; +import { resolve, legacy, imports } from "@bundle/utils/resolve-exports-imports"; import { computeEsbuildSideEffects } from "./side-effects.ts"; import { dispatchEvent, LOGGER_WARN } from "../configs/events.ts"; @@ -104,6 +104,10 @@ export interface SideEffectsConfig { /** * Resolve using modern exports/imports field. * + * This supports: + * - `exports` resolution (subpaths like "." or "./feature") + * - `imports` resolution (subpath imports like "#minpath") + * * @param manifest Package manifest * @param subpath Subpath to resolve (e.g., ".", "./utils") * @param conditions Resolution conditions @@ -115,17 +119,30 @@ export interface SideEffectsConfig { * // result.path = "./dist/esm/index.mjs" * } * ``` + * + * @example exports + * ```ts + * resolveModern(pkg, ".", conditions) + * ``` + * + * @example imports (Node subpath imports) + * ```ts + * resolveModern(pkg, "#minpath", conditions) + * ``` */ export function resolveModern( manifest: Partial, subpath: string, conditions: ResolverConditions ): ModernResolutionResult { + const isSubpathImport = subpath.startsWith("#"); + // Normalize subpath for exports resolution - const exportSubpath = + const exportSubpath = isSubpathImport ? subpath : ( subpath.startsWith("./") ? subpath : - subpath === "" || subpath === "." ? "." : - `./${subpath.replace(/^\//, "")}`; + subpath === "" || subpath === "." ? "." : + `./${subpath.replace(/^\//, "")}` + ); try { // Primary resolution with specified conditions @@ -383,7 +400,7 @@ export function resolvePackageEntry(options: PackageResolutionOptions): PackageR const legacyResult = resolveLegacy(manifest, { browser: conditions.browser }, legacyFields); // Check if excluded for browser - if (legacyResult.excluded) { + if (conditions.browser && legacyResult.excluded) { result.excluded = true; result.error = new Error("Module excluded by browser field"); return result; -- knotmirror 0.0.1