Skip to content

Commit 4614a1c

Browse files
committed
Use esbuild-plugin-wasm
1 parent 79d8f69 commit 4614a1c

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

telegram-bot/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ mv temp ../wasm/pkg-nodejs/package.json
99

1010
npm install
1111
npm exec tsc
12-
npm exec -- esbuild --bundle index.ts --outdir=dist --platform=node --format=esm --loader:.wasm=binary
12+
node --experimental-strip-types esbuild.ts
1313

1414
rm -f lambda_package.zip
1515

16-
zip -j lambda_package.zip package.json dist/index.js
16+
zip -j -r lambda_package.zip package.json dist/

telegram-bot/esbuild.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { context } from "esbuild";
2+
import { wasmLoader } from 'esbuild-plugin-wasm';
3+
4+
const watch = process.argv.includes('--watch');
5+
6+
async function main() {
7+
const ctx = await context({
8+
entryPoints: ['index.ts'],
9+
bundle: true,
10+
outdir: 'dist',
11+
platform: 'node',
12+
format: 'esm',
13+
plugins: [wasmLoader()],
14+
});
15+
16+
if (watch) {
17+
await ctx.watch();
18+
} else {
19+
await ctx.rebuild();
20+
await ctx.dispose();
21+
}
22+
}
23+
24+
try {
25+
await main();
26+
} catch (e) {
27+
console.error(e);
28+
process.exit(1);
29+
};

telegram-bot/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as fend from 'fend-wasm-nodejs';
22

3+
const two = fend.evaluateFendWithTimeout('1+1', 500);
4+
if (two !== '20') {
5+
throw new Error(`could not execute webassembly: got '${two}' instead of '2'`);
6+
}
7+
38
const TELEGRAM_BOT_API_TOKEN = process.env.TELEGRAM_BOT_API_TOKEN;
49

510
/*

telegram-bot/package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

telegram-bot/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"devDependencies": {
2929
"@types/node": "^22.10.1",
3030
"esbuild": "^0.24.0",
31+
"esbuild-plugin-wasm": "^1.1.0",
3132
"typescript": "^5.7.2"
3233
}
3334
}

0 commit comments

Comments
 (0)