From aab8803a20b7f0894e2314e9b4ee51d63966e1d1 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Thu, 16 Jan 2025 08:13:55 +0100 Subject: [PATCH] fix: use uint8array for user's wasm modules used in middleware instead of base64 (#2740) --- edge-runtime/vendor.ts | 1 - src/build/functions/edge.ts | 21 ++------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/edge-runtime/vendor.ts b/edge-runtime/vendor.ts index df153912c3..d49037792f 100644 --- a/edge-runtime/vendor.ts +++ b/edge-runtime/vendor.ts @@ -2,7 +2,6 @@ // It acts as a seed that populates the `vendor/` directory and should not be // imported directly. -import 'https://deno.land/std@0.175.0/encoding/base64.ts' import 'https://deno.land/std@0.175.0/http/cookie.ts' import 'https://deno.land/std@0.175.0/node/buffer.ts' import 'https://deno.land/std@0.175.0/node/events.ts' diff --git a/src/build/functions/edge.ts b/src/build/functions/edge.ts index ab4d6662c7..e8def1a11b 100644 --- a/src/build/functions/edge.ts +++ b/src/build/functions/edge.ts @@ -1,6 +1,5 @@ import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises' -import { dirname, join, relative, sep } from 'node:path' -import { sep as posixSep } from 'node:path/posix' +import { dirname, join } from 'node:path' import type { Manifest, ManifestFunction } from '@netlify/edge-functions' import { glob } from 'fast-glob' @@ -9,8 +8,6 @@ import { pathToRegexp } from 'path-to-regexp' import { EDGE_HANDLER_NAME, PluginContext } from '../plugin-context.js' -const toPosixPath = (path: string) => path.split(sep).join(posixSep) - const writeEdgeManifest = async (ctx: PluginContext, manifest: Manifest) => { await mkdir(ctx.edgeFunctionsDir, { recursive: true }) await writeFile(join(ctx.edgeFunctionsDir, 'manifest.json'), JSON.stringify(manifest, null, 2)) @@ -126,23 +123,9 @@ const copyHandlerDependencies = async ( const outputFile = join(destDir, `server/${name}.js`) if (wasm?.length) { - const base64ModulePath = join( - destDir, - 'edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts', - ) - - const base64ModulePathRelativeToOutputFile = toPosixPath( - relative(dirname(outputFile), base64ModulePath), - ) - - parts.push(`import { decode as _base64Decode } from "${base64ModulePathRelativeToOutputFile}";`) for (const wasmChunk of wasm ?? []) { const data = await readFile(join(srcDir, wasmChunk.filePath)) - parts.push( - `const ${wasmChunk.name} = _base64Decode(${JSON.stringify( - data.toString('base64'), - )}).buffer`, - ) + parts.push(`const ${wasmChunk.name} = Uint8Array.from(${JSON.stringify([...data])})`) } }