#!/bin/sh
# Upstream's build is `./build.js && tsc --project tsconfig.dist.json`.
#
# build.js is ESM and does not run on Debian's Node, so it is driven through
# debian/build.cjs, which rewrites the two incompatible import lines and leaves
# everything else -- including all esbuild options -- untouched.  Debian ships
# esbuild itself (CLI + Node API), so no bundled or substitute bundler is
# needed.
#
# Declarations are emitted by tsc from debian/tsconfig.json rather than
# upstream's tsconfig.dist.json.  The latter cannot be used as-is with
# TypeScript 6 (Debian has 6.0.3, upstream pins ^5.1.6), which now errors on
# two things that upstream's config relies on implicitly:
#
#   * TS5011 -- "common source directory" is ./src but no rootDir is set.
#   * TS5107 -- moduleResolution=node10 is deprecated.
#
# debian/tsconfig.json extends the upstream config and only adds
# `rootDir`/`ignoreDeprecations`, plus `files: []` to drop typing.d.ts.  That
# file exists purely to bring jest's CustomMatcherResult into the test
# compilation unit; the distribution build neither needs it nor can resolve it,
# since jest is not installed for a binary build.  Output is byte-identical to
# the published npm declarations.
set -e

NODE_PATH=/usr/share/nodejs node debian/build.cjs
NODE_PATH=/usr/share/nodejs tsc --project debian/tsconfig.json
