Skip to content

Commit 443a4c5

Browse files
committed
review
1 parent 5736037 commit 443a4c5

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@ async function generateBundle(
302302
outfile: path.join(outputPath, packagePath, `index.${outfileExt}`),
303303
banner: {
304304
js: [
305-
needsGlobalOutputDir(options)
306-
? `globalThis.outputDir = "${outputDir}";`
307-
: "",
305+
`globalThis.monorepoPackagePath = "${packagePath}";`,
308306
"import process from 'node:process';",
309307
"import { Buffer } from 'node:buffer';",
310308
"import { createRequire as topLevelCreateRequire } from 'module';",
@@ -397,13 +395,3 @@ async function minifyServerBundle(outputDir: string) {
397395
mangle: true,
398396
});
399397
}
400-
401-
// Check if we need the outputDir in any dev override
402-
// Remember to update this if you add a new override that needs the outputDir
403-
function needsGlobalOutputDir(options: buildHelper.BuildOptions) {
404-
return (
405-
options.config.default?.override?.wrapper === "express-dev" ||
406-
options.config.default.override?.incrementalCache === "fs-dev" ||
407-
options.config.default.override?.tagCache === "fs-dev"
408-
);
409-
}

packages/open-next/src/overrides/incrementalCache/fs-dev.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import fs from "node:fs/promises";
44
import path from "node:path";
55

66
const buildId = process.env.NEXT_BUILD_ID;
7-
const basePath = path.join(globalThis.outputDir, `cache/${buildId}`);
7+
const basePath = path.join(
8+
globalThis.monorepoPackagePath
9+
.split("/")
10+
.filter(Boolean)
11+
.map(() => "../")
12+
.join(""),
13+
`../../cache/${buildId}`,
14+
);
815

916
const getCacheKey = (key: string) => {
1017
return path.join(basePath, `${key}.cache`);

packages/open-next/src/overrides/tagCache/fs-dev.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import fs from "node:fs";
44
import path from "node:path";
55

66
const tagFile = path.join(
7-
globalThis.outputDir,
8-
"dynamodb-provider/dynamodb-cache.json",
7+
globalThis.monorepoPackagePath
8+
.split("/")
9+
.filter(Boolean)
10+
.map(() => "../")
11+
.join(""),
12+
"../../dynamodb-provider/dynamodb-cache.json",
913
);
1014
const tagContent = fs.readFileSync(tagFile, "utf-8");
1115

packages/open-next/src/overrides/wrappers/express-dev.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ import express from "express";
44
import type { StreamCreator } from "types/open-next.js";
55
import type { WrapperHandler } from "types/overrides.js";
66

7+
const outputDir = path.join(
8+
globalThis.monorepoPackagePath
9+
.split("/")
10+
.filter(Boolean)
11+
.map(() => "../")
12+
.join(""),
13+
"../../",
14+
);
15+
716
const wrapper: WrapperHandler = async (handler, converter) => {
817
const app = express();
918
// To serve static assets
10-
app.use(express.static(path.join(globalThis.outputDir, "assets")));
19+
app.use(express.static(path.join(outputDir, "assets")));
1120

1221
const imageHandlerPath = path.join(
13-
globalThis.outputDir,
22+
outputDir,
1423
"image-optimization-function/index.mjs",
1524
);
1625

packages/open-next/src/types/global.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ declare global {
222222
) => Promise<void>;
223223

224224
/**
225-
* This is for dev overrides that needs the output directory.
225+
* This is the relative package path of the monorepo. It will be an empty string "" in normal repos.
226+
* ex. `packages/web`
226227
*/
227-
var outputDir: string;
228+
var monorepoPackagePath: string;
228229
}

0 commit comments

Comments
 (0)