Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/build/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function baseBuildPlugins(nitro: Nitro, base: BaseBuildConfig) {
plugins.push(
externals({
rootDir: nitro.options.rootDir,
conditions: nitro.options.exportConditions || ["default"],
conditions: nitro.options.exportConditions!,
exclude: [...base.noExternal],
include: isDevOrPrerender
? undefined
Expand Down
47 changes: 12 additions & 35 deletions src/config/resolvers/export-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,28 @@ export async function resolveExportConditionsOptions(options: NitroOptions) {
}

function _resolveExportConditions(
conditions: string[],
userConditions: string[],
opts: { dev: boolean; node: boolean; wasm?: boolean }
) {
const resolvedConditions: string[] = [];
const conditions: string[] = [...userConditions.filter((c) => !c.startsWith("!"))];

// 1. Add dev or production
resolvedConditions.push(opts.dev ? "development" : "production");
conditions.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"
);
}

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

// 5. Add default conditions
// "module" is NOT A STANDARD CONDITION but widely used in the ecosystem adding helps with compatibility
resolvedConditions.push("import", "default", "module");
if (opts.node) {
conditions.push("node");
}

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

// Dedup with preserving order
return resolvedConditions.filter((c, i) => resolvedConditions.indexOf(c) === i);
const negated = new Set(userConditions.filter((c) => c.startsWith("!")).map((c) => c.slice(1)));

return [...new Set(conditions)].filter((c) => !negated.has(c));
}
2 changes: 1 addition & 1 deletion src/presets/bun/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const bun = defineNitroPreset(
entry: "./bun/runtime/bun",
serveStatic: true,
// https://bun.sh/docs/runtime/modules#resolution
exportConditions: ["bun", "node", "import", "default"],
exportConditions: ["bun"],
commands: {
preview: "bun run ./server/index.mjs",
},
Expand Down
Loading