Skip to content

Commit

Permalink
Merge pull request #8944 from jolicode/feat/fix-vercel-and-wasm
Browse files Browse the repository at this point in the history
feat(vercel): add wrapper for generated wasm, adapt vercel middleware with new wrapper
  • Loading branch information
joelwurtz authored May 16, 2024
2 parents 94b1cec + 109502d commit 2181bca
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ install: @RUST_TARGET_DIR@/@RUST_TARGET_SUBDIR@/libredirectionio.a redirectionio
mkdir -p $(DESTDIR)@libdir@/pkgconfig/
install -c -m 644 libredirectionio.pc $(DESTDIR)@libdir@/pkgconfig/

build-wasm:
wasm-pack build --scope redirection.io --no-default-features --out-dir pkg/wasm --no-pack --release

.PHONY: clean
clean:
rm -f redirectionio.h
Expand Down
24 changes: 24 additions & 0 deletions pkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@redirection.io/redirectionio",
"collaborators": [
"Joel Wurtz <jwurtz@redirection.io>"
],
"description": "Redirection IO Library to handle matching rule, redirect and filtering headers and body.",
"version": "2.11.8",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/redirectionio/libredirectionio"
},
"files": [
"wasm/redirectionio.d.ts",
"wasm/redirectionio.js",
"wasm/redirectionio_bg.js",
"wasm/redirectionio_bg.wasm",
"wasm/redirectionio_bg.wasm.d.ts",
"redirectionio.js",
"redirectionio.d.ts"
],
"module": "redirectionio.js",
"types": "redirectionio.d.ts"
}
3 changes: 3 additions & 0 deletions pkg/redirectionio.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './wasm/redirectionio';

export function init(instantiate?: () => Promise<WebAssembly.Instance>): Promise<void>;
36 changes: 36 additions & 0 deletions pkg/redirectionio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as redirectionio from './wasm/redirectionio_bg.js';
import wasmModule from './wasm/redirectionio_bg.wasm?module';

export * from './wasm/redirectionio_bg.js';

function getImports() {
const imports = {"./redirectionio_bg.js": {}};

for (const functionName of Object.keys(redirectionio)) {
if (functionName.startsWith("__") && functionName !== "__wbg_set_wasm") {
imports["./redirectionio_bg.js"][functionName] = redirectionio[functionName];
}
}

return imports;
}

let loadedModule = null;

export async function init(instantiate) {
if (loadedModule) {
return;
}

if (!instantiate) {
instantiate = async () => {
return await WebAssembly.instantiate(wasmModule, getImports());
};
}

const module = await instantiate();

redirectionio.__wbg_set_wasm(module.exports);
loadedModule = module;
redirectionio.init_log();
}
21 changes: 21 additions & 0 deletions pkg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"es2020",
"DOM"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"strictNullChecks": true,
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
}
}

0 comments on commit 2181bca

Please sign in to comment.