Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions packages/open-next/src/build/compileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function compileOpenNextConfigNode(
externals: string[],
) {
const outputPath = path.join(outputDir, "open-next.config.mjs");
logger.info("Compiling open-next.config.ts for Node.", outputPath);

//Check if open-next.config.ts exists
if (!fs.existsSync(sourcePath)) {
Expand Down Expand Up @@ -105,8 +106,8 @@ export function compileOpenNextConfigEdge(
externals: string[],
) {
const outputPath = path.join(outputDir, "open-next.config.edge.mjs");

logger.info("Compiling open-next.config.ts for edge runtime.", outputPath);

buildSync({
entryPoints: [sourcePath],
outfile: outputPath,
Expand All @@ -117,5 +118,4 @@ export function compileOpenNextConfigEdge(
platform: "browser",
external: externals,
});
logger.info("Compiled open-next.config.ts for edge runtime.");
}
4 changes: 2 additions & 2 deletions packages/open-next/src/build/copyTracedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function copyTracedFiles(
`
--------------------------------------------------------------------------------
${pagePath} cannot use the edge runtime.
OpenNext requires edge runtime function to be defined in a separate function.
OpenNext requires edge runtime function to be defined in a separate function.
See the docs for more information on how to bundle edge runtime functions.
--------------------------------------------------------------------------------
`,
Expand All @@ -117,7 +117,7 @@ File ${fullFilePath} does not exist
filesToCopy.set(f, f.replace(standaloneDir, outputDir));
});

if (!existsSync(path.join(standaloneNextDir, `${fullFilePath}`))) {
if (!existsSync(path.join(standaloneNextDir, fullFilePath))) {
throw new Error(
`This error should only happen for static 404 and 500 page from page router. Report this if that's not the case.,
File ${fullFilePath} does not exist`,
Expand Down
10 changes: 5 additions & 5 deletions packages/open-next/src/core/createGenericHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export async function createGenericHandler<
const override = config[handler.type]
?.override as any as DefaultOverrideOptions<E, R>;

// From the config, we create the adapter
const adapter = await resolveConverter<E, R>(override?.converter);
// From the config, we create the converter
const converter = await resolveConverter<E, R>(override?.converter);

// Then we create the handler
const wrapper = await resolveWrapper<E, R>(override?.wrapper);
debug("Using wrapper", wrapper.name);
const { name, wrapper } = await resolveWrapper<E, R>(override?.wrapper);
debug("Using wrapper", name);

return wrapper.wrapper(handler.handler, adapter);
return wrapper(handler.handler, converter);
}
12 changes: 7 additions & 5 deletions packages/open-next/src/core/createMainHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ export async function createMainHandler() {

globalThis.lastModified = {};

// From the config, we create the adapter
const adapter = await resolveConverter(thisFunction.override?.converter);
// From the config, we create the converter
const converter = await resolveConverter(thisFunction.override?.converter);

// Then we create the handler
const wrapper = await resolveWrapper(thisFunction.override?.wrapper);
const { wrapper, name } = await resolveWrapper(
thisFunction.override?.wrapper,
);

debug("Using wrapper", wrapper.name);
debug("Using wrapper", name);

return wrapper.wrapper(openNextHandler, adapter);
return wrapper(openNextHandler, converter);
}
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/wrappers/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const handler: WrapperHandler<
globalThis.process = process;

// Set the environment variables
// Cloudlare suggests to not override the process.env object but instead apply the values to it
// Cloudflare suggests to not override the process.env object but instead apply the values to it
for (const [key, value] of Object.entries(env)) {
if (typeof value === "string") {
process.env[key] = value;
Expand Down
20 changes: 8 additions & 12 deletions packages/open-next/src/plugins/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export interface IPluginSettings {
/**
* @param opts.nextDir - The path to the .next directory
* @param opts.edgeFunctionHandlerPath - The path to the edgeFunctionHandler.js file that we'll use to bundle the routing
* @param opts.middlewareInfo - The entry files that we'll inject into the edgeFunctionHandler.js file
* @param opts.middlewareInfo - Information about the middleware
* @param opts.isInCloudfare - Whether the code runs on the cloudflare runtime
* @returns
*/
export function openNextEdgePlugins({
Expand Down Expand Up @@ -80,12 +81,10 @@ export function openNextEdgePlugins({
// they import from `export * from "node:*";`
build.onLoad(
{ filter: /.*/, namespace: "node-built-in-modules" },
({ path }) => {
return {
contents: `export * from '${path}'`,
loader: "js",
};
},
({ path }) => ({
contents: `export * from '${path}'`,
loader: "js",
}),
);

// We inject the entry files into the edgeFunctionHandler
Expand Down Expand Up @@ -190,11 +189,8 @@ ${contents}
export const MiddlewareManifest = ${JSON.stringify(MiddlewareManifest)};

process.env.NEXT_BUILD_ID = BuildId;

`;
return {
contents,
};
`;
return { contents };
});
},
};
Expand Down
7 changes: 3 additions & 4 deletions packages/open-next/src/plugins/replacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ export function openNextReplacementPlugin({
);
contents = contents.replace(pattern, "");
}),
...(replacements ?? []).map(async (fp) => {
const p = fp;
const replacementFile = await readFile(p, "utf-8");
...(replacements ?? []).map(async (filename) => {
const replacementFile = await readFile(filename, "utf-8");
const matches = replacementFile.matchAll(overridePattern);

const importMatch = replacementFile.match(importPattern);
Expand All @@ -91,7 +90,7 @@ export function openNextReplacementPlugin({
);
logger.debug(
chalk.blue(`Open-next replacement plugin ${name}`),
`-- Applying override for ${id} from ${fp}`,
`-- Applying override for ${id} from ${filename}`,
);
contents = contents.replace(pattern, replacement);
}
Expand Down