1
1
import { cp , mkdir , readFile , rm , writeFile } from 'node:fs/promises'
2
- import { dirname , join } from 'node:path'
2
+ import { dirname , join , relative } from 'node:path'
3
3
4
4
import type { Manifest , ManifestFunction } from '@netlify/edge-functions'
5
5
import { glob } from 'fast-glob'
@@ -107,10 +107,17 @@ const copyHandlerDependencies = async (
107
107
108
108
const parts = [ shim ]
109
109
110
+ const outputFile = join ( destDir , `server/${ name } .js` )
111
+
110
112
if ( wasm ?. length ) {
111
- parts . push (
112
- `import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/[email protected] /encoding/base64.ts";` ,
113
+ const base64ModulePath = join (
114
+ destDir ,
115
+ 'edge-runtime/vendor/deno.land/[email protected] /encoding/base64.ts' ,
113
116
)
117
+
118
+ const base64ModulePathRelativeToOutputFile = relative ( dirname ( outputFile ) , base64ModulePath )
119
+
120
+ parts . push ( `import { decode as _base64Decode } from "${ base64ModulePathRelativeToOutputFile } ";` )
114
121
for ( const wasmChunk of wasm ?? [ ] ) {
115
122
const data = await readFile ( join ( srcDir , wasmChunk . filePath ) )
116
123
parts . push (
@@ -126,9 +133,9 @@ const copyHandlerDependencies = async (
126
133
parts . push ( `;// Concatenated file: ${ file } \n` , entrypoint )
127
134
}
128
135
const exports = `const middlewareEntryKey = Object.keys(_ENTRIES).find(entryKey => entryKey.startsWith("middleware_${ name } ")); export default _ENTRIES[middlewareEntryKey].default;`
129
- await mkdir ( dirname ( join ( destDir , `server/ ${ name } .js` ) ) , { recursive : true } )
136
+ await mkdir ( dirname ( outputFile ) , { recursive : true } )
130
137
131
- await writeFile ( join ( destDir , `server/ ${ name } .js` ) , [ ...parts , exports ] . join ( '\n' ) )
138
+ await writeFile ( outputFile , [ ...parts , exports ] . join ( '\n' ) )
132
139
}
133
140
134
141
const createEdgeHandler = async ( ctx : PluginContext , definition : NextDefinition ) : Promise < void > => {
0 commit comments