@@ -20,22 +20,26 @@ export const inlineChunksPatch: CodePatcher = {
2020 } ) ,
2121 contentFilter : / l o a d R u n t i m e C h u n k P a t h / ,
2222 patchCode : async ( { code, tracedFiles } ) => {
23- const patched = patchCode ( code , inlineChunksRule ) ;
23+ let patched = patchCode ( code , inlineExternalImportRule ) ;
24+ patched = patchCode ( patched , inlineChunksRule ) ;
2425
2526 return `${ patched } \n${ inlineChunksFn ( tracedFiles ) } ` ;
2627 } ,
2728 } ,
2829 ] ,
2930} ;
3031
31- function getInlinableChunks ( tracedFiles : string [ ] ) {
32+ function getInlinableChunks ( tracedFiles : string [ ] ) : string [ ] {
3233 const chunks = new Set < string > ( ) ;
3334 for ( const file of tracedFiles ) {
34- if ( file . includes ( ".next/server/chunks/" ) && ! file . includes ( "[turbopack]_runtime.js" ) ) {
35+ if ( file === "[turbopack]_runtime.js" ) {
36+ continue ;
37+ }
38+ if ( file . includes ( ".next/server/chunks/" ) ) {
3539 chunks . add ( file ) ;
3640 }
3741 }
38- return chunks ;
42+ return Array . from ( chunks ) ;
3943}
4044
4145function inlineChunksFn ( tracedFiles : string [ ] ) {
@@ -44,12 +48,12 @@ function inlineChunksFn(tracedFiles: string[]) {
4448 return `
4549 function requireChunk(chunkPath) {
4650 switch(chunkPath) {
47- ${ Array . from ( chunks )
51+ ${ chunks
4852 . map (
4953 ( chunk ) =>
5054 ` case "${
5155 // we only want the path after /path/to/.next/
52- chunk . replace ( / .* \. n e x t \/ / , "" )
56+ chunk . replace ( / .* \/ \ .n e x t \/ / , "" )
5357 } ": return require("${ chunk } ");`
5458 )
5559 . join ( "\n" ) }
@@ -59,3 +63,20 @@ ${Array.from(chunks)
5963 }
6064` ;
6165}
66+
67+ const inlineExternalImportRule = `
68+ rule:
69+ pattern: "$RAW = await import($ID)"
70+ inside:
71+ regex: "externalImport"
72+ kind: function_declaration
73+ stopBy: end
74+ fix: |-
75+ switch ($ID) {
76+ case "next/dist/compiled/@vercel/og/index.node.js":
77+ $RAW = await import("next/dist/compiled/@vercel/og/index.edge.js");
78+ break;
79+ default:
80+ $RAW = await import($ID);
81+ }
82+ ` ;
0 commit comments