Skip to content

Commit

Permalink
Try using ESM for telegram bot
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Dec 7, 2024
1 parent 5d42288 commit 79d8f69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions telegram-bot/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
set -euo pipefail
cd "$(dirname "$0")"

(cd ../wasm && wasm-pack build --target nodejs --out-dir pkg-nodejs)
(cd ../wasm && wasm-pack build --out-dir pkg-nodejs)
echo "Renaming package to 'fend-wasm-nodejs'..."
jq "setpath([\"name\"]; \"fend-wasm-nodejs\")" ../wasm/pkg-nodejs/package.json >temp
mv temp ../wasm/pkg-nodejs/package.json

npm install
npm exec tsc
npm exec -- esbuild --bundle index.ts --outdir=dist --platform=node
npm exec -- esbuild --bundle index.ts --outdir=dist --platform=node --format=esm --loader:.wasm=binary

rm -f lambda_package.zip
# don't include package.json because esbuild makes a CJS bundle that won't work if node finds `"type": "module"`
zip -j lambda_package.zip dist/index.js node_modules/fend-wasm-nodejs/fend_wasm_bg.wasm

zip -j lambda_package.zip package.json dist/index.js
2 changes: 1 addition & 1 deletion telegram-bot/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fend from 'fend-wasm-nodejs';
import * as fend from 'fend-wasm-nodejs';

const TELEGRAM_BOT_API_TOKEN = process.env.TELEGRAM_BOT_API_TOKEN;

Expand Down
4 changes: 2 additions & 2 deletions telegram-bot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowSyntheticDefaultImports": true,
"strict": true,
"noEmit": true
Expand Down

0 comments on commit 79d8f69

Please sign in to comment.