#!/bin/sh
# Compile the TypeScript sources into the library layouts that package.json
# exports: lib/ (CommonJS) and esm/ (ECMAScript modules).
#
# The UMD bundle (umd/index.js) is only meant to be loaded from a browser
# through the unpkg/jsdelivr CDNs, is not referenced by package.json exports
# and would require terser; it is therefore not built.
set -e

# TypeScript definitions for Node.js, shipped by the nodejs package.
mkdir -p node_modules/@types
[ -e node_modules/@types/node ] || ln -s /usr/share/nodejs/@types/node node_modules/@types/node

tsc
tsc --project tsconfig.esm.json
node scripts/rewriteBuilds.js
