Skip to content

Commit aab8803

Browse files
authoredJan 16, 2025
fix: use uint8array for user's wasm modules used in middleware instead of base64 (#2740)
1 parent 25f6f30 commit aab8803

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed
 

‎edge-runtime/vendor.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// It acts as a seed that populates the `vendor/` directory and should not be
33
// imported directly.
44

5-
import 'https://deno.land/std@0.175.0/encoding/base64.ts'
65
import 'https://deno.land/std@0.175.0/http/cookie.ts'
76
import 'https://deno.land/std@0.175.0/node/buffer.ts'
87
import 'https://deno.land/std@0.175.0/node/events.ts'

‎src/build/functions/edge.ts

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
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'
43

54
import type { Manifest, ManifestFunction } from '@netlify/edge-functions'
65
import { glob } from 'fast-glob'
@@ -9,8 +8,6 @@ import { pathToRegexp } from 'path-to-regexp'
98

109
import { EDGE_HANDLER_NAME, PluginContext } from '../plugin-context.js'
1110

12-
const toPosixPath = (path: string) => path.split(sep).join(posixSep)
13-
1411
const 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))
@@ -126,23 +123,9 @@ const copyHandlerDependencies = async (
126123
const outputFile = join(destDir, `server/${name}.js`)
127124

128125
if (wasm?.length) {
129-
const base64ModulePath = join(
130-
destDir,
131-
'edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts',
132-
)
133-
134-
const base64ModulePathRelativeToOutputFile = toPosixPath(
135-
relative(dirname(outputFile), base64ModulePath),
136-
)
137-
138-
parts.push(`import { decode as _base64Decode } from "${base64ModulePathRelativeToOutputFile}";`)
139126
for (const wasmChunk of wasm ?? []) {
140127
const data = await readFile(join(srcDir, wasmChunk.filePath))
141-
parts.push(
142-
`const ${wasmChunk.name} = _base64Decode(${JSON.stringify(
143-
data.toString('base64'),
144-
)}).buffer`,
145-
)
128+
parts.push(`const ${wasmChunk.name} = Uint8Array.from(${JSON.stringify([...data])})`)
146129
}
147130
}
148131

0 commit comments

Comments
 (0)
Please sign in to comment.