1
1
import { 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'
4
3
5
4
import type { Manifest , ManifestFunction } from '@netlify/edge-functions'
6
5
import { glob } from 'fast-glob'
@@ -9,8 +8,6 @@ import { pathToRegexp } from 'path-to-regexp'
9
8
10
9
import { EDGE_HANDLER_NAME , PluginContext } from '../plugin-context.js'
11
10
12
- const toPosixPath = ( path : string ) => path . split ( sep ) . join ( posixSep )
13
-
14
11
const writeEdgeManifest = async ( ctx : PluginContext , manifest : Manifest ) => {
15
12
await mkdir ( ctx . edgeFunctionsDir , { recursive : true } )
16
13
await writeFile ( join ( ctx . edgeFunctionsDir , 'manifest.json' ) , JSON . stringify ( manifest , null , 2 ) )
@@ -97,14 +94,13 @@ const writeHandlerFile = async (ctx: PluginContext, { matchers, name }: NextDefi
97
94
await writeFile (
98
95
join ( handlerDirectory , `${ handlerName } .js` ) ,
99
96
`
100
- import { decode as _base64Decode } from './edge-runtime/vendor/deno.land/[email protected] /encoding/base64.ts';
101
97
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';
103
99
import handler from './server/${ name } .js';
104
100
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
+ ] ) } ) });
108
104
109
105
export default (req, context) => handleMiddleware(req, context, handler);
110
106
` ,
@@ -127,23 +123,9 @@ const copyHandlerDependencies = async (
127
123
const outputFile = join ( destDir , `server/${ name } .js` )
128
124
129
125
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 } ";` )
140
126
for ( const wasmChunk of wasm ?? [ ] ) {
141
127
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 ] ) } )` )
147
129
}
148
130
}
149
131
0 commit comments