From 1b1e86b8d4252a7ee86c2eb98b7690ffa88a2918 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Sun, 12 Nov 2023 20:30:46 +0100 Subject: [PATCH] executor dual pkg (#541) --- executor/Cargo.lock | 2 +- executor/Cargo.toml | 2 +- executor/package.json | 35 +++++++++++++------ executor/scripts/pack-wasm.cjs | 6 ++-- packages/chopsticks/package.json | 2 +- packages/core/package.json | 2 +- .../src/wasm-executor/node-wasm-executor.js | 5 +++ packages/db/package.json | 2 +- packages/testing/package.json | 2 +- packages/web-test/src/App.tsx | 2 +- yarn.lock | 2 ++ 11 files changed, 42 insertions(+), 20 deletions(-) diff --git a/executor/Cargo.lock b/executor/Cargo.lock index a062c15f..da19bef3 100644 --- a/executor/Cargo.lock +++ b/executor/Cargo.lock @@ -165,7 +165,7 @@ dependencies = [ [[package]] name = "chopsticks-executor" -version = "0.9.2-4" +version = "0.9.2-5" dependencies = [ "arrayvec 0.7.4", "console_error_panic_hook", diff --git a/executor/Cargo.toml b/executor/Cargo.toml index 1ebdce1f..4909b9bb 100644 --- a/executor/Cargo.toml +++ b/executor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chopsticks-executor" -version = "0.9.2-4" +version = "0.9.2-5" description = "Chopsticks executor" repository = "https://github.com/AcalaNetwork/chopsticks" license = "Apache-2.0" diff --git a/executor/package.json b/executor/package.json index 348d8c7c..9ddb5ee6 100644 --- a/executor/package.json +++ b/executor/package.json @@ -1,30 +1,45 @@ { "name": "@acala-network/chopsticks-executor", "description": "Chopsticks executor", - "version": "0.9.2-4", + "version": "0.9.2-5", "license": "Apache-2.0", + "type": "module", "repository": { "type": "git", "url": "https://github.com/AcalaNetwork/chopsticks" }, "scripts": { - "clean": "rm -rf browser node", - "build": "wasm-pack build --target web --out-dir browser; wasm-pack build --target nodejs --out-dir node; scripts/pack-wasm.cjs" + "clean": "rm -rf pkg dist", + "wasm": "yarn clean && wasm-pack build --target web --out-dir pkg && scripts/pack-wasm.cjs", + "build": "yarn wasm && yarn build:cjs && yarn build:esm", + "build:cjs": "swc ./pkg -C module.type=commonjs -d dist/cjs --copy-files && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json", + "build:esm": "swc ./pkg -C module.type=es6 -d dist/esm --copy-files && echo '{\"type\": \"module\"}' > dist/esm/package.json" }, "dependencies": { "@polkadot/util": "^12.5.1", "@polkadot/wasm-util": "^7.2.2" }, "devDependencies": { + "@swc/cli": "0.1.62", + "@swc/core": "^1.3.96", "fflate": "^0.8.1" }, "files": [ - "browser/index.js", - "browser/chopsticks_executor.js", - "browser/chopsticks_executor_bg.wasm", - "node/chopsticks_*" + "dist/esm/**", + "dist/cjs/**", + "pkg/chopsticks_executor.d.ts" ], - "main": "node/chopsticks_executor.js", - "types": "node/chopsticks_executor.d.ts", - "browser": "browser/index.js" + "require": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./pkg/chopsticks_executor.d.ts", + "exports": { + ".": { + "require": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "default": "./dist/esm/index.js", + "types": "./pkg/chopsticks_executor.d.ts" + }, + "./package.json": "./package.json", + "./package.cjs.json": "./dist/cjs/package.json" + } } diff --git a/executor/scripts/pack-wasm.cjs b/executor/scripts/pack-wasm.cjs index d9d56ff5..5a48c49d 100755 --- a/executor/scripts/pack-wasm.cjs +++ b/executor/scripts/pack-wasm.cjs @@ -5,13 +5,13 @@ const path = require('node:path'); const { zlibSync } = require('fflate/node'); const { formatNumber } = require('@polkadot/util'); -const data = fs.readFileSync(path.resolve(__dirname, `../browser/chopsticks_executor_bg.wasm`)); +const data = fs.readFileSync(path.resolve(__dirname, `../pkg/chopsticks_executor_bg.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.writeFileSync(path.resolve(__dirname, `../browser/index.js`), `// Auto-generated file, do not edit by hand +fs.writeFileSync(path.resolve(__dirname, `../pkg/index.js`), `// Auto-generated file, do not edit by hand const LEN_IN = ${compressed.length}; const LEN_OUT = ${data.length}; const BYTES = '${base64}'; @@ -28,4 +28,4 @@ export * from "./chopsticks_executor.js"; // replace wasm with empty file because it's not needed // but we need to have it in the repo for the build to work -fs.writeFileSync(path.resolve(__dirname, `../browser/chopsticks_executor_bg.wasm`), '') +fs.writeFileSync(path.resolve(__dirname, `../pkg/chopsticks_executor_bg.wasm`), '') diff --git a/packages/chopsticks/package.json b/packages/chopsticks/package.json index 3784bb3e..add54db7 100644 --- a/packages/chopsticks/package.json +++ b/packages/chopsticks/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks", - "version": "0.9.2-4", + "version": "0.9.2-5", "author": "Acala Developers ", "license": "Apache-2.0", "bin": "./chopsticks.cjs", diff --git a/packages/core/package.json b/packages/core/package.json index 3db0d532..73b42257 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks-core", - "version": "0.9.2-4", + "version": "0.9.2-5", "author": "Acala Developers ", "license": "Apache-2.0", "type": "module", diff --git a/packages/core/src/wasm-executor/node-wasm-executor.js b/packages/core/src/wasm-executor/node-wasm-executor.js index ce225a80..d19744db 100644 --- a/packages/core/src/wasm-executor/node-wasm-executor.js +++ b/packages/core/src/wasm-executor/node-wasm-executor.js @@ -5,23 +5,28 @@ import { parentPort } from 'node:worker_threads' import nodeEndpoint from 'comlink/dist/umd/node-adapter.js' const getRuntimeVersion = async (code) => { + await pkg.wasmReady return pkg.get_runtime_version(code) } // trie_version: 0 for old trie, 1 for new trie const calculateStateRoot = async (entries, trie_version) => { + await pkg.wasmReady return pkg.calculate_state_root(entries, trie_version) } const decodeProof = async (trieRootHash, keys, nodes) => { + await pkg.wasmReady return pkg.decode_proof(trieRootHash, keys, nodes) } const createProof = async (nodes, entries) => { + await pkg.wasmReady return pkg.create_proof(nodes, entries) } const runTask = async (task, callback) => { + await pkg.wasmReady return pkg.run_task(task, callback, process.env.RUST_LOG) } diff --git a/packages/db/package.json b/packages/db/package.json index 35f6226a..e321d9b9 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks-db", - "version": "0.9.2-4", + "version": "0.9.2-5", "author": "Acala Developers ", "license": "Apache-2.0", "type": "module", diff --git a/packages/testing/package.json b/packages/testing/package.json index b5cfd1c8..03353549 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -1,6 +1,6 @@ { "name": "@acala-network/chopsticks-testing", - "version": "0.9.2-4", + "version": "0.9.2-5", "author": "Acala Developers ", "license": "Apache-2.0", "type": "module", diff --git a/packages/web-test/src/App.tsx b/packages/web-test/src/App.tsx index 94a4d7e7..59974179 100644 --- a/packages/web-test/src/App.tsx +++ b/packages/web-test/src/App.tsx @@ -86,7 +86,7 @@ function App() { const [extrinsic, setExtrinsic] = useState('') const [dryRunResult, setDryRunResult] = useState('') const [config, setConfig] = useState({ - endpoint: 'wss://acala-rpc-0.aca-api.network', + endpoint: 'wss://acala-rpc.aca-api.network', block: 4_000_000, }) const [blocks, setBlocks] = useState<{ number: number; hash: HexString }[]>([]) diff --git a/yarn.lock b/yarn.lock index 44fc7e4f..ebed1998 100644 --- a/yarn.lock +++ b/yarn.lock @@ -65,6 +65,8 @@ __metadata: dependencies: "@polkadot/util": ^12.5.1 "@polkadot/wasm-util": ^7.2.2 + "@swc/cli": 0.1.62 + "@swc/core": ^1.3.96 fflate: ^0.8.1 languageName: unknown linkType: soft