Skip to content

Commit 461821f

Browse files
committed
refactor: use source dir to get app path in config
1 parent 88c0335 commit 461821f

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

packages/cloudflare/src/cli/build/index.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { containsDotNextDir, getConfig } from "../config";
2-
import type { ProjectOptions } from "../config";
1+
import type { Config } from "../config";
32
import { buildNextjsApp } from "./build-next-app";
43
import { buildWorker } from "./build-worker";
4+
import { containsDotNextDir } from "../config";
55
import { cpSync } from "node:fs";
66
import { join } from "node:path";
77
import { rm } from "node:fs/promises";
@@ -11,25 +11,23 @@ import { rm } from "node:fs/promises";
1111
*
1212
* It saves the output in a `.worker-next` directory
1313
*
14-
* @param projectOpts The options for the project
14+
* @param config Build config
1515
*/
16-
export async function build(projectOpts: ProjectOptions): Promise<void> {
17-
if (!projectOpts.skipNextBuild) {
16+
export async function build(config: Config): Promise<void> {
17+
if (!config.build.skipNextBuild) {
1818
// Build the next app
19-
await buildNextjsApp(projectOpts.sourceDir);
19+
await buildNextjsApp(config.paths.sourceDir);
2020
}
2121

22-
if (!containsDotNextDir(projectOpts.sourceDir)) {
23-
throw new Error(`.next folder not found in ${projectOpts.sourceDir}`);
22+
if (!containsDotNextDir(config.paths.sourceDir)) {
23+
throw new Error(`.next folder not found in ${config.paths.sourceDir}`);
2424
}
2525

2626
// Clean the output directory
27-
await cleanDirectory(projectOpts.outputDir);
27+
await cleanDirectory(config.paths.outputDir);
2828

2929
// Copy the .next directory to the output directory so it can be mutated.
30-
cpSync(join(projectOpts.sourceDir, ".next"), join(projectOpts.outputDir, ".next"), { recursive: true });
31-
32-
const config = getConfig(projectOpts);
30+
cpSync(join(config.paths.sourceDir, ".next"), join(config.paths.outputDir, ".next"), { recursive: true });
3331

3432
await buildWorker(config);
3533
}

packages/cloudflare/src/cli/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ export type Config = {
4949
* @returns The configuration, see `Config`
5050
*/
5151
export function getConfig(projectOpts: ProjectOptions): Config {
52+
const sourceDirDotNext = join(projectOpts.sourceDir, ".next");
5253
const dotNext = join(projectOpts.outputDir, ".next");
53-
const appPath = getNextjsApplicationPath(dotNext).replace(/\/$/, "");
54+
const appPath = getNextjsApplicationPath(sourceDirDotNext).replace(/\/$/, "");
5455
const standaloneRoot = join(dotNext, "standalone");
5556
const standaloneApp = join(standaloneRoot, appPath);
5657
const standaloneAppDotNext = join(standaloneApp, ".next");

packages/cloudflare/src/cli/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { build } from "./build";
33
import { existsSync } from "node:fs";
44
import { getArgs } from "./args";
5+
import { getConfig } from "./config";
56
import { resolve } from "node:path";
67

78
const nextAppDir = resolve(".");
@@ -18,9 +19,11 @@ if (!["js", "cjs", "mjs", "ts"].some((ext) => existsSync(`./next.config.${ext}`)
1819

1920
const { skipNextBuild, outputDir, minify } = getArgs();
2021

21-
await build({
22+
const config = getConfig({
2223
sourceDir: nextAppDir,
2324
outputDir: resolve(outputDir ?? nextAppDir, ".worker-next"),
2425
skipNextBuild,
2526
minify,
2627
});
28+
29+
await build(config);

0 commit comments

Comments
 (0)