@@ -77,24 +77,41 @@ const writeHandlerFile = async (ctx: PluginContext, { matchers, name }: NextDefi
77
77
)
78
78
}
79
79
80
- const copyHandlerDependencies = async ( ctx : PluginContext , { name, files } : NextDefinition ) => {
80
+ const copyHandlerDependencies = async (
81
+ ctx : PluginContext ,
82
+ { name, files, wasm } : NextDefinition ,
83
+ ) => {
81
84
const edgeRuntimePath = join ( ctx . pluginDir , 'edge-runtime' )
82
85
const srcDir = join ( ctx . standaloneDir , '.next' )
83
86
const shimPath = join ( edgeRuntimePath , 'shim/index.js' )
84
87
const shim = await readFile ( shimPath , 'utf8' )
85
88
const imports = `import './edge-runtime-webpack.js';`
86
89
const exports = `export default _ENTRIES["middleware_${ name } "].default;`
90
+ const parts = [ shim , imports ]
91
+
92
+ if ( wasm ?. length ) {
93
+ parts . push (
94
+ `import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts";` ,
95
+ )
96
+ for ( const wasmChunk of wasm ?? [ ] ) {
97
+ const data = await readFile ( join ( srcDir , wasmChunk . filePath ) )
98
+ parts . push (
99
+ `const ${ wasmChunk . name } = _base64Decode(${ JSON . stringify (
100
+ data . toString ( 'base64' ) ,
101
+ ) } ).buffer`,
102
+ )
103
+ }
104
+ }
87
105
88
106
await Promise . all (
89
107
files . map ( async ( file ) => {
90
108
const destDir = join ( ctx . edgeFunctionsDir , getHandlerName ( { name } ) )
91
109
92
110
if ( file === `server/${ name } .js` ) {
93
111
const entrypoint = await readFile ( join ( srcDir , file ) , 'utf8' )
94
- const parts = [ shim , imports , entrypoint , exports ]
95
112
96
113
await mkdir ( dirname ( join ( destDir , file ) ) , { recursive : true } )
97
- await writeFile ( join ( destDir , file ) , parts . join ( '\n;' ) )
114
+ await writeFile ( join ( destDir , file ) , [ ... parts , entrypoint , exports ] . join ( '\n;' ) )
98
115
99
116
return
100
117
}
0 commit comments