Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions src/config/resolvers/export-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,32 @@ function _resolveExportConditions(
conditions: string[],
opts: { dev: boolean; node: boolean; wasm?: boolean }
) {
const negated = new Set(conditions.filter((c) => c.startsWith("!")).map((c) => c.slice(1)));

const resolvedConditions: string[] = [];

// 1. Add dev or production
resolvedConditions.push(opts.dev ? "development" : "production");

// 2. Add user specified conditions
resolvedConditions.push(...conditions);

// 3. Add runtime conditions (node or web)
if (opts.node) {
resolvedConditions.push("node");
} else {
// https://runtime-keys.proposal.wintercg.org/
resolvedConditions.push(
"wintercg",
"worker",
"web",
"browser",
"workerd",
"edge-light",
"netlify",
"edge-routine",
"deno"
);
}
resolvedConditions.push(...conditions.filter((c) => !c.startsWith("!")));

// 4. Add unwasm conditions
// 3. Add unwasm conditions
if (opts.wasm) {
resolvedConditions.push("wasm", "unwasm");
}

// 5. Add default conditions
// 4. Add default conditions
// "module" is NOT A STANDARD CONDITION but widely used in the ecosystem adding helps with compatibility
resolvedConditions.push("import", "default", "module");
resolvedConditions.push("module");
Comment thread
pi0 marked this conversation as resolved.
Outdated

// 6. Auto detect bun and deno (builder)
// 5. Auto detect bun and deno (builder)
if ("Bun" in globalThis) {
resolvedConditions.push("bun");
} else if ("Deno" in globalThis) {
resolvedConditions.push("deno");
}
Comment thread
pi0 marked this conversation as resolved.

// Dedup with preserving order
return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
// 6. Dedup and remove negated conditions
return [...new Set(resolvedConditions)].filter((c) => !negated.has(c));
}
Loading