File tree 6 files changed +43
-9
lines changed
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
-
3
1
import fs from "node:fs/promises" ;
4
2
import path from "node:path" ;
5
3
4
+ import type { IncrementalCache } from "types/overrides.js" ;
5
+ import { getMonorepoRelativePath } from "utils/normalize-path" ;
6
+
6
7
const buildId = process . env . NEXT_BUILD_ID ;
7
- const basePath = path . resolve ( process . cwd ( ) , `../../ cache/${ buildId } ` ) ;
8
+ const basePath = path . join ( getMonorepoRelativePath ( ) , `cache/${ buildId } ` ) ;
8
9
9
10
const getCacheKey = ( key : string ) => {
10
11
return path . join ( basePath , `${ key } .cache` ) ;
Original file line number Diff line number Diff line change 1
- import type { TagCache } from "types/overrides" ;
2
-
3
1
import fs from "node:fs" ;
2
+ import path from "node:path" ;
4
3
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 ";
7
6
7
+ const tagFile = path . join (
8
+ getMonorepoRelativePath ( ) ,
9
+ "dynamodb-provider/dynamodb-cache.json" ,
10
+ ) ;
8
11
const tagContent = fs . readFileSync ( tagFile , "utf-8" ) ;
9
12
10
13
let tags = JSON . parse ( tagContent ) as {
Original file line number Diff line number Diff line change
1
+ import path from "node:path" ;
1
2
import express from "express" ;
2
3
3
4
import type { StreamCreator } from "types/open-next.js" ;
4
5
import type { WrapperHandler } from "types/overrides.js" ;
6
+ import { getMonorepoRelativePath } from "utils/normalize-path" ;
5
7
6
8
const wrapper : WrapperHandler = async ( handler , converter ) => {
7
9
const app = express ( ) ;
8
10
// 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
+ ) ;
10
17
11
- const imageHandlerPath = "../../image-optimization-function/index.mjs" ;
12
18
const imageHandler = await import ( imageHandlerPath ) . then ( ( m ) => m . handler ) ;
13
19
14
20
app . all ( "/_next/image" , async ( req , res ) => {
Original file line number Diff line number Diff line change @@ -220,4 +220,10 @@ declare global {
220
220
var __next_route_preloader : (
221
221
stage : "waitUntil" | "start" | "warmerEvent" | "onDemand" ,
222
222
) => 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 ;
223
229
}
Original file line number Diff line number Diff line change
1
+ import path from "node:path" ;
2
+
1
3
export function normalizePath ( path : string ) {
2
4
return path . replace ( / \\ / g, "/" ) ;
3
5
}
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