Files
wasm/scripts/test-quantus-js.sh
rob thijssenandClaude Opus 5 a6d3685c59 refactor(quantus-crypto): drop the @polkadot/wasm-util dependency
It cost more than it saved. Two problems, the second only visible once
quantus/common tried to consume this package:

Its index re-exports packageDetect, whose only job is a side effect registering
with @polkadot/util — a peer dependency inherited for nothing. Deep imports
(/base64, /fflate) avoided that.

But it is a workspace package, so a symlinked consumer resolves its dependencies
through *this* repo's node_modules, where @polkadot/wasm-util points at the
package source rather than its build and carries no exports map. Node follows
symlinks to their realpath, so `@polkadot/wasm-util/base64` failed to resolve
from quantus/common no matter which yarn protocol was used — portal: and link:
behave the same once the realpath is taken.

So: fflate directly for zlib inflate, and fifteen lines for base64 rather than a
dependency at all. Deliberately not atob or Buffer.from — the first is
browser-only, the second node-only, and this runs in an MV3 service worker, a
Worker, node tests and a bundled extension page.

The package is now self-contained apart from fflate, which resolves normally from
any checkout. Size is unchanged at 234,292 raw / 109,649 zlib / 146,200 base64.

Refs quantus/wasm#1, quantus/common#2

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-10 18:39:54 +03:00

28 lines
944 B
Bash
Executable File

#!/usr/bin/env bash
# Copyright 2026 @quantus/crypto authors & contributors
# SPDX-License-Identifier: Apache-2.0
# Runs the consumer test against a staged node_modules rather than in-place.
#
# Staging the built artifact the way an install lays it out tests module
# resolution too, which is half of what can break in a published package — it is
# what caught binaryen 105 producing a wasm that fails to instantiate.
#
# `fflate`, the one runtime dependency, resolves by node walking up to the repo's
# own node_modules, which is exactly what it would do inside a real install.
set -e
PKG=packages/quantus-crypto
STAGE=$PKG/build-test
rm -rf $STAGE
mkdir -p $STAGE/node_modules/@quantus
cp -r $PKG/build $STAGE/node_modules/@quantus/crypto
echo '{ "name": "quantus-crypto-consumer-test", "type": "module", "version": "0.0.0" }' > $STAGE/package.json
cp $PKG/test/consumer.mjs $STAGE/consumer.mjs
node $STAGE/consumer.mjs
rm -rf $STAGE