diff --git a/wasm/README.md b/wasm/README.md index d05a7869e..565fbb141 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -29,6 +29,7 @@ More information on these concepts can be found at the [Aleo Developer Hub](http The [rollup-plugin-rust](https://github.com/wasm-tool/rollup-plugin-rust/) tool is used to compile the Rust code in this crate into JavaScript modules which can be imported into other JavaScript projects. +Node version must be `18.0.0` or higher in order for WASM modules to make network requests. #### Installation @@ -46,7 +47,7 @@ This will produce `.js` and `.wasm` files inside of the `dist` folder. Run tests in Node.js ```bash -wasm-pack test --node +npm test ``` Run tests in a browser diff --git a/wasm/package.json b/wasm/package.json index 2196f7e79..64f1d38c8 100644 --- a/wasm/package.json +++ b/wasm/package.json @@ -6,10 +6,9 @@ "The Provable Team" ], "license": "GPL-3.0", - "type": "module", - "main": "./dist/testnet/index.js", - "browser": "./dist/testnet/index.js", - "types": "./dist/testnet/index.d.ts", + "main": "./dist/index.js", + "browser": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { ".": "./dist/testnet/index.js", "./worker.js": "./dist/testnet/worker.js", @@ -38,13 +37,18 @@ }, "homepage": "https://github.com/ProvableHQ/sdk#readme", "scripts": { - "build": "rimraf dist && node build.js", - "test": "node test.js" + "build": "rimraf dist && rollup -c rollup.config.js && cpr js/types dist && rimraf dist/wasm*", + "prepublish": "yarn build", + "test": "trap \"npm pkg set type='module'\" && echo EXIT && npm pkg delete type \n declare -a networks=('testnet', 'mainnet') \n for n in \"${networks[@]}\" \n do \n wasm-pack test --node --features $n \n done" }, "devDependencies": { "@rollup/plugin-virtual": "^3.0.2", "@wasm-tool/rollup-plugin-rust": "^2.4.2", "rimraf": "^5.0.1", "rollup": "^3.27.2" - } + }, + "engines": { + "node": ">=18.0.0" + }, + "type": "module" } diff --git a/wasm/test.js b/wasm/test.js deleted file mode 100644 index ff1b1b4f5..000000000 --- a/wasm/test.js +++ /dev/null @@ -1,17 +0,0 @@ -import $child from "node:child_process"; -import $fs from "node:fs"; - -const file = $fs.readFileSync("package.json", { encoding: "utf8" }); - -$fs.writeFileSync("package.json", file.replace(/"type": "module",/g, "")); - -try { - ["testnet", "mainnet"].forEach((network) => { - $child.execSync(`wasm-pack test --node --features ${network}`, { - stdio: "inherit", - }); - }); - -} finally { - $fs.writeFileSync("package.json", file); -}