Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/open-next/src/overrides/incrementalCache/fs-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import fs from "node:fs/promises";
import path from "node:path";

const buildId = process.env.NEXT_BUILD_ID;
const basePath = path.resolve(process.cwd(), `../../cache/${buildId}`);
const basePath = path.join(
globalThis.monorepoPackagePath
.split("/")
.filter(Boolean)
.map(() => "../")
.join(""),
`../../cache/${buildId}`,
);

const getCacheKey = (key: string) => {
return path.join(basePath, `${key}.cache`);
Expand Down
12 changes: 9 additions & 3 deletions packages/open-next/src/overrides/tagCache/fs-dev.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { TagCache } from "types/overrides";

import fs from "node:fs";
import path from "node:path";

// TODO: fix this for monorepo
const tagFile = "../../dynamodb-provider/dynamodb-cache.json";

const tagFile = path.join(
globalThis.monorepoPackagePath
.split("/")
.filter(Boolean)
.map(() => "../")
.join(""),
"../../dynamodb-provider/dynamodb-cache.json",
);
const tagContent = fs.readFileSync(tagFile, "utf-8");

let tags = JSON.parse(tagContent) as {
Expand Down
18 changes: 16 additions & 2 deletions packages/open-next/src/overrides/wrappers/express-dev.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import path from "node:path";
import express from "express";

import type { StreamCreator } from "types/open-next.js";
import type { WrapperHandler } from "types/overrides.js";

const outputDir = path.join(
globalThis.monorepoPackagePath
.split("/")
.filter(Boolean)
.map(() => "../")
.join(""),
"../../",
);

const wrapper: WrapperHandler = async (handler, converter) => {
const app = express();
// To serve static assets
app.use(express.static("../../assets"));
app.use(express.static(path.join(outputDir, "assets")));

const imageHandlerPath = path.join(
outputDir,
"image-optimization-function/index.mjs",
);

const imageHandlerPath = "../../image-optimization-function/index.mjs";
const imageHandler = await import(imageHandlerPath).then((m) => m.handler);

app.all("/_next/image", async (req, res) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/open-next/src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,10 @@ declare global {
var __next_route_preloader: (
stage: "waitUntil" | "start" | "warmerEvent" | "onDemand",
) => Promise<void>;

/**
* This is the relative package path of the monorepo. It will be an empty string "" in normal repos.
* ex. `packages/web`
*/
var monorepoPackagePath: string;
}
Loading