#!/bin/sh
# Upstream builds with esbuild + dts-bundle-generator. esbuild is packaged in
# Debian; dts-bundle-generator is not, so the type declarations are produced
# with rollup-plugin-dts instead. ip-address and express stay external.
set -e
mkdir -p dist

esbuild --tsconfig=debian/tsconfig.json \
    --packages=external --platform=node --bundle --target=es2022 \
    --format=cjs --outfile=dist/index.cjs \
    --footer:js="module.exports = Object.assign(rateLimit, module.exports);" \
    source/index.ts
esbuild --tsconfig=debian/tsconfig.json \
    --packages=external --platform=node --bundle --target=es2022 \
    --format=esm --outfile=dist/index.mjs source/index.ts

rollup -c debian/rollup.dts.config.mjs
cp dist/index.d.ts dist/index.d.cts
cp dist/index.d.ts dist/index.d.mts
