11import { cp , mkdir , readFile , rm , writeFile } from 'node:fs/promises'
2- import { dirname , join , relative , sep } from 'node:path'
3- import { sep as posixSep } from 'node:path/posix'
2+ import { dirname , join } from 'node:path'
43
54import type { Manifest , ManifestFunction } from '@netlify/edge-functions'
65import { glob } from 'fast-glob'
@@ -9,8 +8,6 @@ import { pathToRegexp } from 'path-to-regexp'
98
109import { EDGE_HANDLER_NAME , PluginContext } from '../plugin-context.js'
1110
12- const toPosixPath = ( path : string ) => path . split ( sep ) . join ( posixSep )
13-
1411const writeEdgeManifest = async ( ctx : PluginContext , manifest : Manifest ) => {
1512 await mkdir ( ctx . edgeFunctionsDir , { recursive : true } )
1613 await writeFile ( join ( ctx . edgeFunctionsDir , 'manifest.json' ) , JSON . stringify ( manifest , null , 2 ) )
@@ -97,14 +94,13 @@ const writeHandlerFile = async (ctx: PluginContext, { matchers, name }: NextDefi
9794 await writeFile (
9895 join ( handlerDirectory , `${ handlerName } .js` ) ,
9996 `
100- import { decode as _base64Decode } from './edge-runtime/vendor/deno.land/[email protected] /encoding/base64.ts'; 10197 import { init as htmlRewriterInit } from './edge-runtime/vendor/deno.land/x/[email protected] /src/index.ts' 102- import {handleMiddleware} from './edge-runtime/middleware.ts';
98+ import { handleMiddleware } from './edge-runtime/middleware.ts';
10399 import handler from './server/${ name } .js';
104100
105- await htmlRewriterInit({ module_or_path: _base64Decode (${ JSON . stringify (
106- htmlRewriterWasm . toString ( 'base64' ) ,
107- ) } ).buffer });
101+ await htmlRewriterInit({ module_or_path: Uint8Array.from (${ JSON . stringify ( [
102+ ... htmlRewriterWasm ,
103+ ] ) } ) });
108104
109105 export default (req, context) => handleMiddleware(req, context, handler);
110106 ` ,
@@ -127,23 +123,9 @@ const copyHandlerDependencies = async (
127123 const outputFile = join ( destDir , `server/${ name } .js` )
128124
129125 if ( wasm ?. length ) {
130- const base64ModulePath = join (
131- destDir ,
132- 'edge-runtime/vendor/deno.land/[email protected] /encoding/base64.ts' , 133- )
134-
135- const base64ModulePathRelativeToOutputFile = toPosixPath (
136- relative ( dirname ( outputFile ) , base64ModulePath ) ,
137- )
138-
139- parts . push ( `import { decode as _base64Decode } from "${ base64ModulePathRelativeToOutputFile } ";` )
140126 for ( const wasmChunk of wasm ?? [ ] ) {
141127 const data = await readFile ( join ( srcDir , wasmChunk . filePath ) )
142- parts . push (
143- `const ${ wasmChunk . name } = _base64Decode(${ JSON . stringify (
144- data . toString ( 'base64' ) ,
145- ) } ).buffer`,
146- )
128+ parts . push ( `const ${ wasmChunk . name } = Uint8Array.from(${ JSON . stringify ( [ ...data ] ) } )` )
147129 }
148130 }
149131
0 commit comments