Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use uint8array for user's wasm modules used in middleware instead of base64 #2740

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion edge-runtime/vendor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// It acts as a seed that populates the `vendor/` directory and should not be
// imported directly.

import 'https://deno.land/[email protected]/encoding/base64.ts'
import 'https://deno.land/[email protected]/http/cookie.ts'
import 'https://deno.land/[email protected]/node/buffer.ts'
import 'https://deno.land/[email protected]/node/events.ts'
Expand Down
21 changes: 2 additions & 19 deletions src/build/functions/edge.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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))
Expand Down Expand Up @@ -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/[email protected]/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])})`)
}
}

Expand Down
Loading