From e74e466c2badb335c4be6b3c8e5c449be8ce8367 Mon Sep 17 00:00:00 2001 From: Dimasik Kolezhniuk Date: Fri, 13 Oct 2023 17:19:39 +0200 Subject: [PATCH] ES module browser fix --- config/rollup.browser.esm.config.js | 13 ++++----- package-lock.json | 43 ++++++++++------------------- package.json | 6 ++-- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/config/rollup.browser.esm.config.js b/config/rollup.browser.esm.config.js index 6bbee4b8..76049856 100644 --- a/config/rollup.browser.esm.config.js +++ b/config/rollup.browser.esm.config.js @@ -2,7 +2,6 @@ import { nodeResolve } from "@rollup/plugin-node-resolve"; import commonJS from "@rollup/plugin-commonjs"; import virtual from "@rollup/plugin-virtual"; import replace from "@rollup/plugin-replace"; -import visualizer from "rollup-plugin-visualizer"; // Needed by fastfile import { O_TRUNC, O_CREAT, O_RDWR, O_EXCL, O_RDONLY } from "constants"; @@ -20,14 +19,14 @@ export default { input: "main.js", output: { file: "build/esm.js", - format: "es" + format: "es", }, - external: ['ffjavascript'], + external: ["ffjavascript"], plugins: [ replace({ // The current default is false, but they are changing it next version preventAssignment: false, - "process.browser": true + "process.browser": true, }), virtual({ fs: empty, @@ -43,13 +42,11 @@ export default { nodeResolve({ browser: true, preferBuiltins: false, - exportConditions: ["module"] + exportConditions: ["module"], }), commonJS(), - // terser(), - visualizer(), ], treeshake: { preset: "smallest", - } + }, }; diff --git a/package-lock.json b/package-lock.json index 8995f176..4843322a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "circom_runtime": "0.1.24", "ejs": "^3.1.6", "fastfile": "0.0.20", - "ffjavascript": "file:../ffjavascript", + "ffjavascript": "https://github.com/iden3/ffjavascript.git#chore/esm-patch", "js-sha3": "^0.8.0", "logplease": "^1.2.15", "r1csfile": "0.0.47" @@ -36,25 +36,6 @@ "rollup-plugin-visualizer": "^5.6.0" } }, - "../ffjavascript": { - "version": "0.2.61", - "license": "GPL-3.0", - "dependencies": { - "wasmbuilder": "0.0.16", - "wasmcurves": "0.2.2", - "web-worker": "^1.2.0" - }, - "devDependencies": { - "@rollup/plugin-commonjs": "^25.0.4", - "@rollup/plugin-node-resolve": "^15.2.1", - "@rollup/plugin-replace": "^5.0.3", - "blake2b": "^2.1.3", - "chai": "^4.2.0", - "eslint": "^8.0.1", - "mocha": "^10.0.0", - "rollup": "^3.29.4" - } - }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -546,9 +527,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.8.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.4.tgz", - "integrity": "sha512-ZVPnqU58giiCjSxjVUESDtdPk4QR5WQhhINbc9UBrKLU68MX5BF6kbQzTrkwbolyr0X8ChBpXfavr5mZFKZQ5A==", + "version": "20.8.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.5.tgz", + "integrity": "sha512-SPlobFgbidfIeOYlzXiEjSYeIJiOCthv+9tSQVpvk4PAdIIc+2SmjNVzWXk9t0Y7dl73Zdf+OgXKHX9XtkqUpw==", "dev": true, "dependencies": { "undici-types": "~5.25.1" @@ -1309,8 +1290,14 @@ } }, "node_modules/ffjavascript": { - "resolved": "../ffjavascript", - "link": true + "version": "0.2.61", + "resolved": "git+ssh://git@github.com/iden3/ffjavascript.git#dc9e45ad18678014611dc23a8d516014a8b33872", + "license": "GPL-3.0", + "dependencies": { + "wasmbuilder": "0.0.16", + "wasmcurves": "0.2.2", + "web-worker": "^1.2.0" + } }, "node_modules/file-entry-cache": { "version": "6.0.1", @@ -2274,9 +2261,9 @@ } }, "node_modules/resolve": { - "version": "1.22.6", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.6.tgz", - "integrity": "sha512-njhxM7mV12JfufShqGy3Rz8j11RPdLy4xi15UurGJeoHLfJpVXKdh3ueuOqbYUcDZnffr6X739JBo5LzyahEsw==", + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", "dev": true, "dependencies": { "is-core-module": "^2.13.0", diff --git a/package.json b/package.json index a80ce7a1..ccd39e09 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "files": [ "COPYING", "README.md", + "config", "build/", "cli.js", "main.js", @@ -25,13 +26,14 @@ "templates/" ], "scripts": { + "prepare": "npm run build:browser:esm", "test": "mocha", "testv12": "mocha test/fflonk.test.js test/fullprocess.js test/keypar_test.js test/polynomial.test.js", "build": "rollup -c config/rollup.cjs.config.js", "buildcli": "rollup -c config/rollup.cli.config.js", "buildiife": "BROWSER=true rollup -c config/rollup.iife.config.js", "buildiifemin": "BROWSER=true rollup -c config/rollup.iife_min.config.js", - "build:esm": "BROWSER=true rollup -c config/rollup.browser.esm.config" + "build:browser:esm": "BROWSER=true rollup -c config/rollup.browser.esm.config" }, "bin": { "snarkjs": "build/cli.cjs" @@ -61,7 +63,7 @@ "circom_runtime": "0.1.24", "ejs": "^3.1.6", "fastfile": "0.0.20", - "ffjavascript": "file:../ffjavascript", + "ffjavascript": "https://github.com/iden3/ffjavascript.git#chore/esm-patch", "js-sha3": "^0.8.0", "logplease": "^1.2.15", "r1csfile": "0.0.47"