Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 13 additions & 1 deletion packages/open-next/src/build/createServerBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ async function generateBundle(
outfile: path.join(outputPath, packagePath, `index.${outfileExt}`),
banner: {
js: [
`globalThis.monorepoPackagePath = "${packagePath}";`,
needsGlobalOutputDir(options)
? `globalThis.outputDir = "${outputDir}";`
: "",
"import process from 'node:process';",
"import { Buffer } from 'node:buffer';",
"import { createRequire as topLevelCreateRequire } from 'module';",
Expand Down Expand Up @@ -395,3 +397,13 @@ async function minifyServerBundle(outputDir: string) {
mangle: true,
});
}

// Check if we need the outputDir in any dev override
// Remember to update this if you add a new override that needs the outputDir
function needsGlobalOutputDir(options: buildHelper.BuildOptions) {
return (
options.config.default?.override?.wrapper === "express-dev" ||
options.config.default.override?.incrementalCache === "fs-dev" ||
options.config.default.override?.tagCache === "fs-dev"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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.outputDir, `cache/${buildId}`);

const getCacheKey = (key: string) => {
return path.join(basePath, `${key}.cache`);
Expand Down
8 changes: 5 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,12 @@
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.outputDir,
"dynamodb-provider/dynamodb-cache.json",
);
const tagContent = fs.readFileSync(tagFile, "utf-8");

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

import type { StreamCreator } from "types/open-next.js";
Expand All @@ -6,9 +7,13 @@ import type { WrapperHandler } from "types/overrides.js";
const wrapper: WrapperHandler = async (handler, converter) => {
const app = express();
// To serve static assets
app.use(express.static("../../assets"));
app.use(express.static(path.join(globalThis.outputDir, "assets")));

const imageHandlerPath = path.join(
globalThis.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
5 changes: 5 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,9 @@ declare global {
var __next_route_preloader: (
stage: "waitUntil" | "start" | "warmerEvent" | "onDemand",
) => Promise<void>;

/**
* This is for dev overrides that needs the output directory.
*/
var outputDir: string;
}
Loading