Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f246247

Browse files
committedDec 18, 2024
fix: inline htmlrewriter wasm blob to workaround bundling problems
1 parent a804602 commit f246247

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed
 

‎edge-runtime/lib/response.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Context } from '@netlify/edge-functions'
22
import {
33
HTMLRewriter,
4-
init,
54
type TextChunk,
65
} from '../vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts'
76

@@ -17,8 +16,6 @@ import {
1716
relativizeURL,
1817
} from './util.ts'
1918

20-
await init()
21-
2219
export interface FetchEventResult {
2320
response: Response
2421
waitUntil: Promise<any>

‎src/build/functions/edge.ts

+14
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,27 @@ const writeHandlerFile = async (ctx: PluginContext, { matchers, name }: NextDefi
8585
JSON.stringify(minimalNextConfig),
8686
)
8787

88+
const htmlRewriterWasm = await readFile(
89+
join(
90+
ctx.pluginDir,
91+
'edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter_bg.wasm',
92+
),
93+
)
94+
8895
// Writing the function entry file. It wraps the middleware code with the
8996
// compatibility layer mentioned above.
9097
await writeFile(
9198
join(handlerDirectory, `${handlerName}.js`),
9299
`
100+
import { decode as _base64Decode } from './edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts';
101+
import { init as htmlRewriterInit } from './edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts'
93102
import {handleMiddleware} from './edge-runtime/middleware.ts';
94103
import handler from './server/${name}.js';
104+
105+
await htmlRewriterInit({ module_or_path: _base64Decode(${JSON.stringify(
106+
htmlRewriterWasm.toString('base64'),
107+
)}).buffer });
108+
95109
export default (req, context) => handleMiddleware(req, context, handler);
96110
`,
97111
)

0 commit comments

Comments
 (0)
Please sign in to comment.