Convert pack wasm to ESM (#463)

* Convert pack wasm to ESM

* Cleanup clean scripts

* Adjust
This commit is contained in:
Jaco
2023-01-27 10:26:14 +02:00
committed by GitHub
parent 6f06fe6b2a
commit f3a5b7e373
7 changed files with 15 additions and 28 deletions

View File

@@ -41,7 +41,7 @@
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@polkadot/dev": "^0.68.1",
"@polkadot/dev": "^0.68.2",
"@polkadot/util": "^10.2.6",
"@polkadot/x-randomvalues": "^10.2.6",
"@types/jest": "^29.4.0",

View File

@@ -5,5 +5,5 @@
set -e
./scripts/clean-js.sh
yarn polkadot-dev-clean-build
yarn polkadot-dev-build-ts

View File

@@ -32,7 +32,7 @@ echo "*** Optimising WASM output"
# convert wasm to base64 structure
echo "*** Packing WASM into baseX"
node ../scripts/pack-wasm-base.cjs
node ../scripts/pack-wasm-base.mjs
# build asmjs version from the input (optimised) WASM
echo "*** Building asm.js version"

View File

@@ -1,10 +0,0 @@
#!/usr/bin/env bash
# Copyright 2019-2023 @polkadot/wasm authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
set -e
# cleanup old
echo "*** Cleaning old builds"
rm -rf build packages/*/build*

View File

@@ -5,11 +5,8 @@
set -e
./scripts/clean-js.sh
yarn polkadot-dev-clean-build
echo "*** Cleaning wasm"
cd packages/wasm-crypto
cargo clean
cd ../..

View File

@@ -1,22 +1,22 @@
// Copyright 2019-2023 @polkadot/wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
const fflate = require('fflate/node');
const fs = require('fs');
const mkdirp = require('mkdirp');
const { formatNumber } = require('@polkadot/util');
import { zlibSync } from 'fflate/node';
import fs from 'fs';
import { formatNumber } from '@polkadot/util';
const DIR_DENO = `./${process.env.PKG_NAME}-wasm/build-deno/deno`;
const DIR_CJS = `./${process.env.PKG_NAME}-wasm/build/cjs`;
const HDR = `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.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(`./${process.env.PKG_NAME}/build-wasm/wasm_opt.wasm`);
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
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)}`);
mkdirp.sync(DIR_DENO);
fs.mkdirSync(DIR_DENO, { recursive: true });
fs.writeFileSync(`${DIR_CJS}/bytes.js`, `${HDR}
const lenIn = ${compressed.length};

View File

@@ -1974,9 +1974,9 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/dev@npm:^0.68.1":
version: 0.68.1
resolution: "@polkadot/dev@npm:0.68.1"
"@polkadot/dev@npm:^0.68.2":
version: 0.68.2
resolution: "@polkadot/dev@npm:0.68.2"
dependencies:
"@babel/cli": ^7.20.7
"@babel/core": ^7.20.12
@@ -2069,7 +2069,7 @@ __metadata:
polkadot-exec-swc: scripts/polkadot-exec-swc.mjs
polkadot-exec-tsc: scripts/polkadot-exec-tsc.mjs
polkadot-exec-webpack: scripts/polkadot-exec-webpack.mjs
checksum: 55bfc095964c1684486a9765f7fe8805cd2faca8a5cad999476957d1f28abf705326fdb873eab0c3afdab535ee6f29d145ef7c2e03af665074d623ede231527f
checksum: 4fad7d5137034ecf4672c163e0f8fc1cb16aa5e2b92101a9d65dbaee18e2a19c8f6e6b4c5bc4d94bb91adbe043afd6492dbe93664a58fdca1113ed5a2e7a1371
languageName: node
linkType: hard
@@ -9932,7 +9932,7 @@ __metadata:
resolution: "root-workspace-0b6124@workspace:."
dependencies:
"@babel/core": ^7.20.12
"@polkadot/dev": ^0.68.1
"@polkadot/dev": ^0.68.2
"@polkadot/util": ^10.2.6
"@polkadot/x-randomvalues": ^10.2.6
"@types/jest": ^29.4.0