File tree Expand file tree Collapse file tree 6 files changed +43
-9
lines changed Expand file tree Collapse file tree 6 files changed +43
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @opennextjs/aws " : patch
3+ ---
4+
5+ fix: make dev overrides work in monorepo
Original file line number Diff line number Diff line change 1- import type { IncrementalCache } from "types/overrides.js" ;
2-
31import fs from "node:fs/promises" ;
42import path from "node:path" ;
53
4+ import type { IncrementalCache } from "types/overrides.js" ;
5+ import { getMonorepoRelativePath } from "utils/normalize-path" ;
6+
67const buildId = process . env . NEXT_BUILD_ID ;
7- const basePath = path . resolve ( process . cwd ( ) , `../../ cache/${ buildId } ` ) ;
8+ const basePath = path . join ( getMonorepoRelativePath ( ) , `cache/${ buildId } ` ) ;
89
910const getCacheKey = ( key : string ) => {
1011 return path . join ( basePath , `${ key } .cache` ) ;
Original file line number Diff line number Diff line change 1- import type { TagCache } from "types/overrides" ;
2-
31import fs from "node:fs" ;
2+ import path from "node:path" ;
43
5- // TODO: fix this for monorepo
6- const tagFile = "../../dynamodb-provider/dynamodb-cache.json ";
4+ import type { TagCache } from "types/overrides" ;
5+ import { getMonorepoRelativePath } from "utils/normalize-path ";
76
7+ const tagFile = path . join (
8+ getMonorepoRelativePath ( ) ,
9+ "dynamodb-provider/dynamodb-cache.json" ,
10+ ) ;
811const tagContent = fs . readFileSync ( tagFile , "utf-8" ) ;
912
1013let tags = JSON . parse ( tagContent ) as {
Original file line number Diff line number Diff line change 1+ import path from "node:path" ;
12import express from "express" ;
23
34import type { StreamCreator } from "types/open-next.js" ;
45import type { WrapperHandler } from "types/overrides.js" ;
6+ import { getMonorepoRelativePath } from "utils/normalize-path" ;
57
68const wrapper : WrapperHandler = async ( handler , converter ) => {
79 const app = express ( ) ;
810 // To serve static assets
9- app . use ( express . static ( "../../assets" ) ) ;
11+ app . use ( express . static ( path . join ( getMonorepoRelativePath ( ) , "assets" ) ) ) ;
12+
13+ const imageHandlerPath = path . join (
14+ getMonorepoRelativePath ( ) ,
15+ "image-optimization-function/index.mjs" ,
16+ ) ;
1017
11- const imageHandlerPath = "../../image-optimization-function/index.mjs" ;
1218 const imageHandler = await import ( imageHandlerPath ) . then ( ( m ) => m . handler ) ;
1319
1420 app . all ( "/_next/image" , async ( req , res ) => {
Original file line number Diff line number Diff line change @@ -220,4 +220,10 @@ declare global {
220220 var __next_route_preloader : (
221221 stage : "waitUntil" | "start" | "warmerEvent" | "onDemand" ,
222222 ) => Promise < void > ;
223+
224+ /**
225+ * This is the relative package path of the monorepo. It will be an empty string "" in normal repos.
226+ * ex. `packages/web`
227+ */
228+ var monorepoPackagePath : string ;
223229}
Original file line number Diff line number Diff line change 1+ import path from "node:path" ;
2+
13export function normalizePath ( path : string ) {
24 return path . replace ( / \\ / g, "/" ) ;
35}
6+
7+ export function getMonorepoRelativePath ( relativePath = "../.." ) : string {
8+ return path . join (
9+ globalThis . monorepoPackagePath
10+ . split ( "/" )
11+ . filter ( Boolean )
12+ . map ( ( ) => ".." )
13+ . join ( "/" ) ,
14+ relativePath ,
15+ ) ;
16+ }
You can’t perform that action at this time.
0 commit comments