Skip to content

Commit 739fbdd

Browse files
authoredJan 25, 2024
fix: support wasm chunks (#190)
* fix: support wasm chunks * Import from vendor
1 parent 11fb5e0 commit 739fbdd

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed
 

‎edge-runtime/vendor.ts

-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@ import 'https://deno.land/std@0.175.0/path/mod.ts'
1414
import 'https://deno.land/x/path_to_regexp@v6.2.1/index.ts'
1515
import 'https://deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts'
1616

17-
import 'https://esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js'
18-
import 'https://esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js'
19-
2017
import 'https://v1-7-0--edge-utils.netlify.app/logger/mod.ts'

‎src/build/functions/edge.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,41 @@ const writeHandlerFile = async (ctx: PluginContext, { matchers, name }: NextDefi
7777
)
7878
}
7979

80-
const copyHandlerDependencies = async (ctx: PluginContext, { name, files }: NextDefinition) => {
80+
const copyHandlerDependencies = async (
81+
ctx: PluginContext,
82+
{ name, files, wasm }: NextDefinition,
83+
) => {
8184
const edgeRuntimePath = join(ctx.pluginDir, 'edge-runtime')
8285
const srcDir = join(ctx.standaloneDir, '.next')
8386
const shimPath = join(edgeRuntimePath, 'shim/index.js')
8487
const shim = await readFile(shimPath, 'utf8')
8588
const imports = `import './edge-runtime-webpack.js';`
8689
const exports = `export default _ENTRIES["middleware_${name}"].default;`
90+
const parts = [shim, imports]
91+
92+
if (wasm?.length) {
93+
parts.push(
94+
`import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts";`,
95+
)
96+
for (const wasmChunk of wasm ?? []) {
97+
const data = await readFile(join(srcDir, wasmChunk.filePath))
98+
parts.push(
99+
`const ${wasmChunk.name} = _base64Decode(${JSON.stringify(
100+
data.toString('base64'),
101+
)}).buffer`,
102+
)
103+
}
104+
}
87105

88106
await Promise.all(
89107
files.map(async (file) => {
90108
const destDir = join(ctx.edgeFunctionsDir, getHandlerName({ name }))
91109

92110
if (file === `server/${name}.js`) {
93111
const entrypoint = await readFile(join(srcDir, file), 'utf8')
94-
const parts = [shim, imports, entrypoint, exports]
95112

96113
await mkdir(dirname(join(destDir, file)), { recursive: true })
97-
await writeFile(join(destDir, file), parts.join('\n;'))
114+
await writeFile(join(destDir, file), [...parts, entrypoint, exports].join('\n;'))
98115

99116
return
100117
}

‎tests/netlify-e2e.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@
145145
},
146146
"test/e2e/app-dir/app-routes/app-custom-route-base-path.test.ts": {
147147
"flakey": [
148-
"app-custom-routes no response returned should print an error when no response is returned"
148+
"app-custom-routes no response returned should print an error when no response is returned",
149+
"app-custom-routes error conditions responds with 400 (Bad Request) when the requested method is not a valid HTTP method"
149150
]
150151
},
151152
"test/e2e/app-dir/app-routes/app-custom-routes.test.ts": {
152153
"flakey": [
153-
"app-custom-routes no response returned should print an error when no response is returned"
154+
"app-custom-routes no response returned should print an error when no response is returned",
155+
"app-custom-routes error conditions responds with 400 (Bad Request) when the requested method is not a valid HTTP method"
154156
]
155157
},
156158
"test/e2e/app-dir/actions/app-action.test.ts": {

0 commit comments

Comments
 (0)
Please sign in to comment.