Skip to content

Commit 9c5d582

Browse files
authored
refactor: minor cleanup (#605)
1 parent cf33973 commit 9c5d582

File tree

7 files changed

+28
-31
lines changed

7 files changed

+28
-31
lines changed

packages/open-next/src/build/compileConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function compileOpenNextConfigNode(
7070
externals: string[],
7171
) {
7272
const outputPath = path.join(outputDir, "open-next.config.mjs");
73+
logger.debug("Compiling open-next.config.ts for Node.", outputPath);
7374

7475
//Check if open-next.config.ts exists
7576
if (!fs.existsSync(sourcePath)) {
@@ -105,8 +106,8 @@ export function compileOpenNextConfigEdge(
105106
externals: string[],
106107
) {
107108
const outputPath = path.join(outputDir, "open-next.config.edge.mjs");
109+
logger.debug("Compiling open-next.config.ts for edge runtime.", outputPath);
108110

109-
logger.info("Compiling open-next.config.ts for edge runtime.", outputPath);
110111
buildSync({
111112
entryPoints: [sourcePath],
112113
outfile: outputPath,
@@ -117,5 +118,4 @@ export function compileOpenNextConfigEdge(
117118
platform: "browser",
118119
external: externals,
119120
});
120-
logger.info("Compiled open-next.config.ts for edge runtime.");
121121
}

packages/open-next/src/build/copyTracedFiles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export async function copyTracedFiles(
9696
`
9797
--------------------------------------------------------------------------------
9898
${pagePath} cannot use the edge runtime.
99-
OpenNext requires edge runtime function to be defined in a separate function.
99+
OpenNext requires edge runtime function to be defined in a separate function.
100100
See the docs for more information on how to bundle edge runtime functions.
101101
--------------------------------------------------------------------------------
102102
`,
@@ -117,7 +117,7 @@ File ${fullFilePath} does not exist
117117
filesToCopy.set(f, f.replace(standaloneDir, outputDir));
118118
});
119119

120-
if (!existsSync(path.join(standaloneNextDir, `${fullFilePath}`))) {
120+
if (!existsSync(path.join(standaloneNextDir, fullFilePath))) {
121121
throw new Error(
122122
`This error should only happen for static 404 and 500 page from page router. Report this if that's not the case.,
123123
File ${fullFilePath} does not exist`,

packages/open-next/src/core/createGenericHandler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export async function createGenericHandler<
4545
const override = config[handler.type]
4646
?.override as any as DefaultOverrideOptions<E, R>;
4747

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

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

55-
return wrapper.wrapper(handler.handler, adapter);
55+
return wrapper(handler.handler, converter);
5656
}

packages/open-next/src/core/createMainHandler.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ export async function createMainHandler() {
5353

5454
globalThis.lastModified = {};
5555

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

5959
// Then we create the handler
60-
const wrapper = await resolveWrapper(thisFunction.override?.wrapper);
60+
const { wrapper, name } = await resolveWrapper(
61+
thisFunction.override?.wrapper,
62+
);
6163

62-
debug("Using wrapper", wrapper.name);
64+
debug("Using wrapper", name);
6365

64-
return wrapper.wrapper(openNextHandler, adapter);
66+
return wrapper(openNextHandler, converter);
6567
}

packages/open-next/src/overrides/wrappers/cloudflare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const handler: WrapperHandler<
1515
globalThis.process = process;
1616

1717
// Set the environment variables
18-
// Cloudlare suggests to not override the process.env object but instead apply the values to it
18+
// Cloudflare suggests to not override the process.env object but instead apply the values to it
1919
for (const [key, value] of Object.entries(env)) {
2020
if (typeof value === "string") {
2121
process.env[key] = value;

packages/open-next/src/plugins/edge.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export interface IPluginSettings {
2525
/**
2626
* @param opts.nextDir - The path to the .next directory
2727
* @param opts.edgeFunctionHandlerPath - The path to the edgeFunctionHandler.js file that we'll use to bundle the routing
28-
* @param opts.middlewareInfo - The entry files that we'll inject into the edgeFunctionHandler.js file
28+
* @param opts.middlewareInfo - Information about the middleware
29+
* @param opts.isInCloudfare - Whether the code runs on the cloudflare runtime
2930
* @returns
3031
*/
3132
export function openNextEdgePlugins({
@@ -80,12 +81,10 @@ export function openNextEdgePlugins({
8081
// they import from `export * from "node:*";`
8182
build.onLoad(
8283
{ filter: /.*/, namespace: "node-built-in-modules" },
83-
({ path }) => {
84-
return {
85-
contents: `export * from '${path}'`,
86-
loader: "js",
87-
};
88-
},
84+
({ path }) => ({
85+
contents: `export * from '${path}'`,
86+
loader: "js",
87+
}),
8988
);
9089

9190
// We inject the entry files into the edgeFunctionHandler
@@ -190,11 +189,8 @@ ${contents}
190189
export const MiddlewareManifest = ${JSON.stringify(MiddlewareManifest)};
191190
192191
process.env.NEXT_BUILD_ID = BuildId;
193-
194-
`;
195-
return {
196-
contents,
197-
};
192+
`;
193+
return { contents };
198194
});
199195
},
200196
};

packages/open-next/src/plugins/replacement.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ export function openNextReplacementPlugin({
7272
);
7373
contents = contents.replace(pattern, "");
7474
}),
75-
...(replacements ?? []).map(async (fp) => {
76-
const p = fp;
77-
const replacementFile = await readFile(p, "utf-8");
75+
...(replacements ?? []).map(async (filename) => {
76+
const replacementFile = await readFile(filename, "utf-8");
7877
const matches = replacementFile.matchAll(overridePattern);
7978

8079
const importMatch = replacementFile.match(importPattern);
@@ -91,7 +90,7 @@ export function openNextReplacementPlugin({
9190
);
9291
logger.debug(
9392
chalk.blue(`Open-next replacement plugin ${name}`),
94-
`-- Applying override for ${id} from ${fp}`,
93+
`-- Applying override for ${id} from ${filename}`,
9594
);
9695
contents = contents.replace(pattern, replacement);
9796
}

0 commit comments

Comments
 (0)