Skip to content

Commit a863666

Browse files
committed
review fix
1 parent 6e8b400 commit a863666

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

packages/open-next/src/adapters/config/util.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ export function loadMiddlewareManifest(nextDir: string) {
126126
}
127127

128128
export function loadFunctionsConfigManifest(nextDir: string) {
129-
const filePath = path.join(
130-
nextDir,
131-
"server/functions-config-manifest.json",
132-
);
129+
const filePath = path.join(nextDir, "server/functions-config-manifest.json");
133130
try {
134131
const json = fs.readFileSync(filePath, "utf-8");
135132
return JSON.parse(json) as FunctionsConfigManifest;

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

+17-8
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,24 @@ function copyPatchFile(outputDir: string) {
2525
copyFileSync(patchFile, outputPatchFile);
2626
}
2727

28+
interface CopyTracedFilesOptions {
29+
buildOutputPath: string;
30+
packagePath: string;
31+
outputDir: string;
32+
routes: string[];
33+
bundledNextServer: boolean;
34+
skipServerFiles?: boolean;
35+
}
36+
2837
// eslint-disable-next-line sonarjs/cognitive-complexity
29-
export async function copyTracedFiles(
30-
buildOutputPath: string,
31-
packagePath: string,
32-
outputDir: string,
33-
routes: string[],
34-
bundledNextServer: boolean,
35-
skipServerFiles = false,
36-
) {
38+
export async function copyTracedFiles({
39+
buildOutputPath,
40+
packagePath,
41+
outputDir,
42+
routes,
43+
bundledNextServer,
44+
skipServerFiles,
45+
}: CopyTracedFilesOptions) {
3746
const tsStart = Date.now();
3847
const dotNextDir = path.join(buildOutputPath, ".next");
3948
const standaloneDir = path.join(dotNextDir, "standalone");

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

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import fs from "node:fs";
2-
import fsAsync from "node:fs/promises";
32
import path from "node:path";
43

4+
import { loadFunctionsConfigManifest } from "config/util.js";
55
import logger from "../logger.js";
66
import type {
7-
FunctionsConfigManifest,
87
MiddlewareInfo,
98
MiddlewareManifest,
109
} from "../types/next-types.js";
@@ -38,25 +37,20 @@ export async function createMiddleware(
3837
),
3938
) as MiddlewareManifest;
4039

41-
const middlewareInfo = middlewareManifest.middleware["/"] as
40+
const edgeMiddlewareInfo = middlewareManifest.middleware["/"] as
4241
| MiddlewareInfo
4342
| undefined;
4443

45-
if (!middlewareInfo) {
44+
if (!edgeMiddlewareInfo) {
4645
// If there is no middleware info, it might be a node middleware
47-
const functionsConfigManifestPath = path.join(
48-
appBuildOutputPath,
49-
".next/server/functions-config-manifest.json",
46+
const functionsConfigManifest = loadFunctionsConfigManifest(
47+
path.join(appBuildOutputPath, ".next"),
5048
);
51-
const functionsConfigManifest = JSON.parse(
52-
await fsAsync
53-
.readFile(functionsConfigManifestPath, "utf8")
54-
.catch(() => '{"functions":{}, "version": 1}'),
55-
) as FunctionsConfigManifest;
5649

5750
if (functionsConfigManifest?.functions["/_middleware"]) {
58-
await (config.middleware?.external ? buildExternalNodeMiddleware(options) : buildBundledNodeMiddleware(options));
59-
return;
51+
await (config.middleware?.external
52+
? buildExternalNodeMiddleware(options)
53+
: buildBundledNodeMiddleware(options));
6054
return;
6155
}
6256
}
@@ -80,7 +74,7 @@ export async function createMiddleware(
8074
"middleware.js",
8175
),
8276
outfile: path.join(outputPath, "handler.mjs"),
83-
middlewareInfo,
77+
middlewareInfo: edgeMiddlewareInfo,
8478
options,
8579
overrides: {
8680
...config.middleware.override,
@@ -102,7 +96,7 @@ export async function createMiddleware(
10296
"edgeFunctionHandler.js",
10397
),
10498
outfile: path.join(options.buildDir, "middleware.mjs"),
105-
middlewareInfo,
99+
middlewareInfo: edgeMiddlewareInfo,
106100
options,
107101
onlyBuildOnce: true,
108102
name: "middleware",

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ async function generateBundle(
153153
buildHelper.copyEnvFile(appBuildOutputPath, packagePath, outputPath);
154154

155155
// Copy all necessary traced files
156-
await copyTracedFiles(
157-
appBuildOutputPath,
156+
await copyTracedFiles({
157+
buildOutputPath: appBuildOutputPath,
158158
packagePath,
159-
outputPath,
160-
fnOptions.routes ?? ["app/page.tsx"],
161-
isBundled,
162-
);
159+
outputDir: outputPath,
160+
routes: fnOptions.routes ?? ["app/page.tsx"],
161+
bundledNextServer: isBundled,
162+
});
163163

164164
// Build Lambda code
165165
// note: bundle in OpenNext package b/c the adapter relies on the

packages/open-next/src/build/middleware/buildNodeMiddleware.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ export async function buildExternalNodeMiddleware(
4545
const packagePath = buildHelper.getPackagePath(options);
4646

4747
// TODO: change this so that we don't copy unnecessary files
48-
await copyTracedFiles(
49-
appBuildOutputPath,
48+
await copyTracedFiles({
49+
buildOutputPath: appBuildOutputPath,
5050
packagePath,
51-
outputPath,
52-
[],
53-
false,
54-
true,
55-
);
51+
outputDir: outputPath,
52+
routes: [],
53+
bundledNextServer: false,
54+
skipServerFiles: true,
55+
});
5656

5757
function override<T extends keyof Override>(target: T) {
5858
return typeof overrides?.[target] === "string"

0 commit comments

Comments
 (0)