Skip to content

Commit 2181bca

Browse files
authored
Merge pull request #8944 from jolicode/feat/fix-vercel-and-wasm
feat(vercel): add wrapper for generated wasm, adapt vercel middleware with new wrapper
2 parents 94b1cec + 109502d commit 2181bca

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

Makefile.in

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ install: @RUST_TARGET_DIR@/@RUST_TARGET_SUBDIR@/libredirectionio.a redirectionio
3636
mkdir -p $(DESTDIR)@libdir@/pkgconfig/
3737
install -c -m 644 libredirectionio.pc $(DESTDIR)@libdir@/pkgconfig/
3838

39+
build-wasm:
40+
wasm-pack build --scope redirection.io --no-default-features --out-dir pkg/wasm --no-pack --release
41+
3942
.PHONY: clean
4043
clean:
4144
rm -f redirectionio.h

pkg/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@redirection.io/redirectionio",
3+
"collaborators": [
4+
"Joel Wurtz <[email protected]>"
5+
],
6+
"description": "Redirection IO Library to handle matching rule, redirect and filtering headers and body.",
7+
"version": "2.11.8",
8+
"license": "MIT",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/redirectionio/libredirectionio"
12+
},
13+
"files": [
14+
"wasm/redirectionio.d.ts",
15+
"wasm/redirectionio.js",
16+
"wasm/redirectionio_bg.js",
17+
"wasm/redirectionio_bg.wasm",
18+
"wasm/redirectionio_bg.wasm.d.ts",
19+
"redirectionio.js",
20+
"redirectionio.d.ts"
21+
],
22+
"module": "redirectionio.js",
23+
"types": "redirectionio.d.ts"
24+
}

pkg/redirectionio.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './wasm/redirectionio';
2+
3+
export function init(instantiate?: () => Promise<WebAssembly.Instance>): Promise<void>;

pkg/redirectionio.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as redirectionio from './wasm/redirectionio_bg.js';
2+
import wasmModule from './wasm/redirectionio_bg.wasm?module';
3+
4+
export * from './wasm/redirectionio_bg.js';
5+
6+
function getImports() {
7+
const imports = {"./redirectionio_bg.js": {}};
8+
9+
for (const functionName of Object.keys(redirectionio)) {
10+
if (functionName.startsWith("__") && functionName !== "__wbg_set_wasm") {
11+
imports["./redirectionio_bg.js"][functionName] = redirectionio[functionName];
12+
}
13+
}
14+
15+
return imports;
16+
}
17+
18+
let loadedModule = null;
19+
20+
export async function init(instantiate) {
21+
if (loadedModule) {
22+
return;
23+
}
24+
25+
if (!instantiate) {
26+
instantiate = async () => {
27+
return await WebAssembly.instantiate(wasmModule, getImports());
28+
};
29+
}
30+
31+
const module = await instantiate();
32+
33+
redirectionio.__wbg_set_wasm(module.exports);
34+
loadedModule = module;
35+
redirectionio.init_log();
36+
}

pkg/tsconfig.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"lib": [
6+
"es2020",
7+
"DOM"
8+
],
9+
"allowJs": true,
10+
"skipLibCheck": true,
11+
"strict": true,
12+
"noEmit": true,
13+
"strictNullChecks": true,
14+
"esModuleInterop": true,
15+
"moduleResolution": "bundler",
16+
"resolveJsonModule": true,
17+
"isolatedModules": true,
18+
"jsx": "preserve",
19+
"incremental": true
20+
}
21+
}

0 commit comments

Comments
 (0)