Skip to content

Commit 5c0e121

Browse files
authored
refactor: minor updates (#634)
1 parent 9a5ef0a commit 5c0e121

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ export async function copyTracedFiles(
3838
const standaloneNextDir = path.join(standaloneDir, packagePath, ".next");
3939
const outputNextDir = path.join(outputDir, packagePath, ".next");
4040

41-
const extractFiles = (files: string[], from = standaloneNextDir) => {
42-
return files.map((f) => path.resolve(from, f));
43-
};
41+
const extractFiles = (files: string[], from = standaloneNextDir) =>
42+
files.map((f) => path.resolve(from, f));
4443

4544
// On next 14+, we might not have to include those files
4645
// For next 13, we need to include them otherwise we get runtime error
@@ -203,25 +202,36 @@ File ${fullFilePath} does not exist
203202
}
204203
});
205204

206-
readdirSync(standaloneNextDir).forEach((f) => {
207-
if (statSync(path.join(standaloneNextDir, f)).isDirectory()) return;
208-
copyFileSync(path.join(standaloneNextDir, f), path.join(outputNextDir, f));
209-
});
205+
readdirSync(standaloneNextDir)
206+
.filter(
207+
(fileOrDir) =>
208+
!statSync(path.join(standaloneNextDir, fileOrDir)).isDirectory(),
209+
)
210+
.forEach((file) =>
211+
copyFileSync(
212+
path.join(standaloneNextDir, file),
213+
path.join(outputNextDir, file),
214+
),
215+
);
210216

211217
// We then need to copy all the files at the root of server
212218

213219
mkdirSync(path.join(outputNextDir, "server"), { recursive: true });
214220

215-
readdirSync(path.join(standaloneNextDir, "server")).forEach((f) => {
216-
if (statSync(path.join(standaloneNextDir, "server", f)).isDirectory())
217-
return;
218-
if (f !== "server.js") {
221+
readdirSync(path.join(standaloneNextDir, "server"))
222+
.filter(
223+
(fileOrDir) =>
224+
!statSync(
225+
path.join(standaloneNextDir, "server", fileOrDir),
226+
).isDirectory(),
227+
)
228+
.filter((file) => file !== "server.js")
229+
.forEach((file) =>
219230
copyFileSync(
220-
path.join(standaloneNextDir, "server", f),
221-
path.join(path.join(outputNextDir, "server"), f),
222-
);
223-
}
224-
});
231+
path.join(standaloneNextDir, "server", file),
232+
path.join(path.join(outputNextDir, "server"), file),
233+
),
234+
);
225235

226236
// Copy patch file
227237
copyPatchFile(path.join(outputDir, packagePath));
@@ -285,11 +295,9 @@ File ${fullFilePath} does not exist
285295
}
286296
});
287297

288-
staticFiles.forEach((f: string) => {
289-
if (f.endsWith(".html")) {
290-
copyStaticFile(`server/${f}`);
291-
}
292-
});
298+
staticFiles
299+
.filter((file) => file.endsWith(".html"))
300+
.forEach((file) => copyStaticFile(`server/${file}`));
293301
}
294302

295303
logger.debug("copyTracedFiles:", Date.now() - tsStart, "ms");

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,11 @@ ${contents}
169169
const MiddlewareManifest = loadMiddlewareManifest(nextDir);
170170

171171
const contents = `
172-
import path from "path";
172+
import path from "node:path";
173173
174174
import { debug } from "../logger";
175175
176-
if(!globalThis.__dirname) {
177-
globalThis.__dirname = ""
178-
}
176+
globalThis.__dirname ??= "";
179177
180178
export const NEXT_DIR = path.join(__dirname, ".next");
181179
export const OPEN_NEXT_DIR = path.join(__dirname, ".open-next");

0 commit comments

Comments
 (0)