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
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
Expand Up @@ -34,7 +34,7 @@ export async function build(
const { config, buildDir } = await compileOpenNextConfig(
baseDir,
openNextConfigPath,
nodeExternals,
{ nodeExternals },
);

// Initialize options
Expand Down
15 changes: 8 additions & 7 deletions packages/open-next/src/build/compileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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 };
Expand Down