Skip to content

Add a compileEdge parameter to compileOpenNextConfig #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
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
5 changes: 5 additions & 0 deletions .changeset/gorgeous-rocks-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

Add a `compileEdge` parameter to `compileOpenNextConfig`
2 changes: 1 addition & 1 deletion packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ export async function build(
const { config, buildDir } = await compileOpenNextConfig(
baseDir,
openNextConfigPath,
nodeExternals,
{ nodeExternals },
);

// Initialize options
15 changes: 8 additions & 7 deletions packages/open-next/src/build/compileConfig.ts
Original file line number Diff line number Diff line change
@@ -15,13 +15,14 @@ import { validateConfig } from "./validateConfig.js";
*
* @param baseDir Directory where to look for the configuration.
* @param openNextConfigPath Override the default configuration when provided. Relative to baseDir.
* @param nodeExternals Externals for the Node.js compilation.
* @param nodeExternals Coma separated list of Externals for the Node.js compilation.
* @param compileEdge Force compiling for the edge runtime when true
* @return The configuration and the build directory.
*/
export async function compileOpenNextConfig(
baseDir: string,
openNextConfigPath?: string,
nodeExternals?: string,
{ nodeExternals = "", compileEdge = false } = {},
) {
const sourcePath = path.join(
baseDir,
@@ -32,7 +33,7 @@ export async function compileOpenNextConfig(
let configPath = compileOpenNextConfigNode(
sourcePath,
buildDir,
nodeExternals ? nodeExternals.split(",") : [],
nodeExternals.split(","),
);

// On Windows, we need to use file:// protocol to load the config file using import()
@@ -52,13 +53,13 @@ export async function compileOpenNextConfig(
const usesEdgeRuntime =
(config.middleware?.external && config.middleware.runtime !== "node") ||
Object.values(config.functions || {}).some((fn) => fn.runtime === "edge");
if (!usesEdgeRuntime) {
if (usesEdgeRuntime || compileEdge) {
compileOpenNextConfigEdge(sourcePath, buildDir, config.edgeExternals ?? []);
} else {
// Skip compiling for the edge runtime.
logger.debug(
"No edge runtime found in the open-next.config.ts. Using default config.",
);
//Nothing to do here
} else {
compileOpenNextConfigEdge(sourcePath, buildDir, config.edgeExternals ?? []);
}

return { config, buildDir };