// Copyright 2026 @quantus/crypto authors & contributors // SPDX-License-Identifier: Apache-2.0 // A near-copy of pack-wasm-base.mjs. Kept separate rather than parameterised // because that script is upstream's and rebases should not have to reconcile our // changes with theirs — the duplication is the cheaper of the two costs. // // ESM only: no deno variant and no CJS variant, matching what the package ships. // This must run *after* the TypeScript build, which clears build/. import fs from 'node:fs'; import { zlibSync } from 'fflate/node'; const PKG_NAME = process.env['PKG_NAME']; const CRATE_NAME = process.env['CRATE_NAME']; const DIR_ESM = `./packages/${PKG_NAME}/build`; const HDR = `// Copyright 2026 @quantus/crypto authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// Generated as part of the build, do not edit\n`; const data = fs.readFileSync(`./packages/${PKG_NAME}/build-wasm/${CRATE_NAME}_opt.wasm`); const compressed = Buffer.from(zlibSync(data, { level: 9 })); const base64 = compressed.toString('base64'); console.log(`*** Compressed WASM: in=${data.length}, out=${compressed.length}, opt=${(100 * compressed.length / data.length).toFixed(2)}%, base64=${base64.length}`); fs.mkdirSync(DIR_ESM, { recursive: true }); fs.writeFileSync(`${DIR_ESM}/bytes.js`, `${HDR} export const lenIn = ${compressed.length}; export const lenOut = ${data.length}; export const bytes = '${base64}'; `);