Small cleanups (#182)

* Small cleanups

* Detect wasm-crypt-* alongside detectPackage

* Adjust alias imports

* Adjust

* Adjust
This commit is contained in:
Jaco Greeff
2021-03-04 17:59:38 +01:00
committed by GitHub
parent 98bc7147e3
commit 641ea0f9d8
10 changed files with 52 additions and 49 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ echo "*** Optimising WASM output"
# convert wasm to base64 structure
echo "*** Packing WASM into baseX"
node ../scripts/pack-wasm-base.js
node ../scripts/pack-wasm-base.cjs
# build asmjs version from the input (optimised) WASM
echo "*** Building asm.js version"
@@ -1,6 +1,7 @@
// Copyright 2019-2021 @polkadot/wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
const fflate = require('fflate/node');
const fs = require('fs');
const { formatNumber } = require('@polkadot/util');
@@ -15,16 +16,11 @@ function hdr (package) {
`;
}
// only one of the deps are included, here are the details for package.json -
// "fflate": "^0.4.2"
// "lz4js": "^0.2.0"
function getWasmBuffer (lib = 'fflate') {
function getWasmBuffer () {
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
const compressed = lib === 'fflate'
? Buffer.from(require('fflate/node').zlibSync(data, { level: 9 }))
: Buffer.from(require('lz4js').compress(data));
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
console.log(`*** Compressed WASM via ${lib}: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
return { compressed, sizeUncompressed: data.length };
}