paivana

HTTP paywall reverse proxy
Log | Files | Refs | Submodules | README | LICENSE

typecheck.sh (1630B)


      1 #!/bin/sh
      2 # Type-check paywall.js with the TypeScript compiler in checkJs mode.
      3 #
      4 # Exits 77 ("skipped" for meson and for the GNU test convention) when no
      5 # TypeScript compiler is available locally.  We never fall back to a
      6 # plain `npx --package typescript', which would download a compiler:
      7 # running the test suite must not reach out to the network.  To run it
      8 # by hand without installing anything:
      9 #
     10 #   npx --package typescript tsc --allowJs --checkJs --noEmit \
     11 #     --target esnext --lib esnext,esnext.bigint,dom,dom.iterable \
     12 #     src/frontend/paywall.js src/frontend/global.d.ts
     13 #
     14 # dom.iterable is not optional: without it `for (const x of
     15 # el.getElementsByClassName(...))' is an error, because plain `dom'
     16 # declares HTMLCollectionOf without a [Symbol.iterator].
     17 
     18 set -eu
     19 
     20 srcdir=${SRCDIR:-$(dirname "$0")}
     21 
     22 # `tsc' on npm is NOT the TypeScript compiler -- it is a squatted
     23 # package whose entire content is a message telling you so, and it
     24 # exits 0 for --version.  A bare `npx --no-install tsc --version'
     25 # probe therefore succeeds against it and we then run it for real,
     26 # which fails the test with that message and nothing to do with this
     27 # code.  Insist the probe looks like a version.
     28 if command -v tsc >/dev/null 2>&1; then
     29   set -- tsc
     30 elif npx --no-install tsc --version 2>/dev/null | grep -Eq '[0-9]+\.[0-9]+'; then
     31   set -- npx --no-install tsc
     32 else
     33   echo "no local TypeScript compiler found, skipping type check" >&2
     34   exit 77
     35 fi
     36 
     37 exec "$@" \
     38   --allowJs \
     39   --checkJs \
     40   --noEmit \
     41   --target esnext \
     42   --lib esnext,esnext.bigint,dom,dom.iterable \
     43   "$srcdir/paywall.js" \
     44   "$srcdir/global.d.ts"