Files
pezkuwi-wasm/scripts/pack-wasm-base.mjs
T
Satoshi Qazi MuhammedandClaude Opus 5.5 0d7494b87d Make lint pass: tooling names, headers, compiled files, test imports
Lint never ran here: the build step stopped first on @pezkuwi/dev 0.85.7.
With it running:
- .prettierrc.cjs loaded @polkadot/dev; it is @pezkuwi/dev
- license headers on .prettierrc.cjs and scripts/pack-wasm-base.mjs
- packages/scure-sr25519/lib holds compiled files only; it is ignored
- the wasm-crypto test entries take upstream's form: one @ts-ignore, for
  the build output that may not exist, with the reason; test globals by
  reference
- three ad-hoc scripts from the 7.5.17 release, referenced nowhere, removed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 08:23:53 +04:00

49 lines
1.7 KiB
JavaScript
Executable File

// Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { zlibSync } from 'fflate/node';
import fs from 'node:fs';
import { formatNumber } from '@pezkuwi/util';
const PKG_NAME = process.env['PKG_NAME'];
const DIR_DENO = `./${PKG_NAME}-wasm/build-deno/deno`;
const DIR_ESM = `./${PKG_NAME}-wasm/build`;
const DIR_CJS = `./${PKG_NAME}-wasm/build/cjs`;
const HDR = `// Copyright 2019-${new Date().getFullYear()} @pezkuwi/${PKG_NAME}-wasm 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(`./${PKG_NAME}/build-wasm/wasm_opt.wasm`);
const compressed = Buffer.from(zlibSync(data, { level: 9 }));
const base64 = compressed.toString('base64');
console.log(`*** Compressed WASM: in=${formatNumber(data.length)}, out=${formatNumber(compressed.length)}, opt=${(100 * compressed.length / data.length).toFixed(2)}%, base64=${formatNumber(base64.length)}`);
fs.mkdirSync(DIR_DENO, { recursive: true });
fs.writeFileSync(`${DIR_CJS}/bytes.js`, `${HDR}
exports.lenIn = ${compressed.length};
exports.lenOut = ${data.length};
exports.bytes = '${base64}';
`);
// The package exports `./bytes` from build/bytes.js for ESM consumers. Without this
// write that file kept whatever src/bytes.js held, and could ship a different wasm
// from the one in build/cjs.
fs.writeFileSync(`${DIR_ESM}/bytes.js`, `${HDR}
export const lenIn = ${compressed.length};
export const lenOut = ${data.length};
export const bytes = '${base64}';
`);
fs.writeFileSync(`${DIR_DENO}/bytes.js`, `${HDR}
export const lenIn = ${compressed.length};
export const lenOut = ${data.length};
export const bytes = '${base64}';
`);