#!/usr/bin/env bash # Copyright 2026 @quantus/crypto authors & contributors # SPDX-License-Identifier: Apache-2.0 # Builds the JS side of packages/quantus-crypto. # # Not `polkadot-dev-build-ts`, because that tool returns early for any package # not named `@polkadot/*` — twice, in `buildJs` and when collecting `locals` for # import rewriting. Renaming the package into someone else's scope to satisfy a # string check would be worse than not using the tool. # # Nothing is lost by that: this package needs none of what the tool adds (a deno # variant, a rollup bundle, cross-package import rewriting, generated exports # maps). It is four TypeScript files and two generated artifacts. Keeping it out # also means `yarn build:js` stays byte-identical to upstream's behaviour, which # is the rebasability convention in quantus/extension#1. # # ESM only. The consumers — quantus/common and the extension — are ESM, and the # wasm-bindgen glue is ESM-only, so a CJS variant would mean either a second # generated glue or hand-written marshalling. See quantus/wasm#1 before adding one. set -e NAME=${1:-quantus-crypto} PKG=packages/$NAME CRATE=$(echo "$NAME" | tr '-' '_') echo "*** Building $NAME" rm -rf $PKG/build-tsc yarn polkadot-exec-tsc --outDir $PKG/build-tsc --project $PKG/tsconfig.build.json # tsc emits only what it compiles; the generated glue and the packed bytes are # .js and have to be carried over by hand. mkdir -p $PKG/build/generated cp -r $PKG/build-tsc/* $PKG/build/ cp $PKG/src/generated/$CRATE.js $PKG/build/generated/$CRATE.js cp $PKG/src/generated/$CRATE.d.ts $PKG/build/generated/$CRATE.d.ts rm -rf $PKG/build-tsc # package.json, with the paths rewritten for a consumer installing the build # output rather than the source tree. node -e " const fs = require('node:fs'); const pkg = JSON.parse(fs.readFileSync('$PKG/package.json', 'utf-8')); delete pkg.private; pkg.main = './index.js'; pkg.types = './index.d.ts'; pkg.exports = { '.': { types: './index.d.ts', default: './index.js' }, './package.json': './package.json' }; fs.writeFileSync('$PKG/build/package.json', JSON.stringify(pkg, null, 2) + '\n'); " cp $PKG/README.md $PKG/build/README.md echo "*** Built $(ls $PKG/build/*.js | wc -l) modules"