Skip to content

Commit

Permalink
chore(imt): fix tests and update rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Apr 16, 2024
1 parent d5e0a94 commit 73eda59
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
4 changes: 3 additions & 1 deletion packages/imt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
"access": "public"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"incrementalquintree": "^1.0.9",
"poseidon-lite": "^0.2.0",
"rimraf": "^5.0.5",
"rollup": "^4.12.0",
"rollup-plugin-cleanup": "^3.2.1"
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-polyfill-node": "^0.13.0"
},
"dependencies": {
"@zk-kit/utils": "1.0.0-beta.1"
Expand Down
59 changes: 39 additions & 20 deletions packages/imt/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { nodeResolve } from "@rollup/plugin-node-resolve"
import terser from "@rollup/plugin-terser"
import typescript from "@rollup/plugin-typescript"
import fs from "fs"
import cleanup from "rollup-plugin-cleanup"
import nodePolyfills from "rollup-plugin-polyfill-node"

const pkg = JSON.parse(fs.readFileSync("./package.json", "utf8"))
const banner = `/**
Expand All @@ -15,23 +17,40 @@ const banner = `/**

const name = pkg.name.substr(1).replace(/[-/]./g, (x: string) => x.toUpperCase()[1])

export default {
input: "src/index.ts",
output: [
{
file: pkg.iife,
name,
format: "iife",
banner
},
{
file: pkg.unpkg,
name,
format: "iife",
plugins: [terser({ output: { preamble: banner } })]
},
{ file: pkg.exports["."].require, format: "cjs", banner },
{ file: pkg.exports["."].default, format: "es", banner }
],
plugins: [typescript({ tsconfig: "./build.tsconfig.json" }), cleanup({ comments: "jsdoc" })]
}
export default [
{
input: "src/index.ts",
output: [
{ file: pkg.exports["."].require, format: "cjs", banner },
{ file: pkg.exports["."].default, format: "es", banner }
],
external: [...Object.keys(pkg.dependencies), "@zk-kit/utils/error-handlers"],
plugins: [typescript({ tsconfig: "./build.tsconfig.json" }), cleanup({ comments: "jsdoc" })]
},
{
input: "src/index.ts",
output: [
{
file: pkg.iife,
name,
format: "iife",
banner
},
{
file: pkg.unpkg,
name,
format: "iife",
plugins: [terser({ output: { preamble: banner } })]
}
],
external: [],
plugins: [
typescript({
tsconfig: "./build.tsconfig.json"
}),
nodeResolve({ preferBuiltins: false, browser: true }),
nodePolyfills(),
cleanup({ comments: "jsdoc" })
]
}
]
6 changes: 3 additions & 3 deletions packages/imt/tests/imt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe("IMT", () => {
const fun2 = () => new IMT(1 as any, 33, 0, arity)
const fun3 = () => new IMT(poseidon, depth, 0, arity, 2 as any)

expect(fun1).toThrow("Parameter 'hash' is not defined")
expect(fun2).toThrow("Parameter 'hash' is none of these types: function")
expect(fun3).toThrow("Parameter 'leaves' is none of these types: object")
expect(fun1).toThrow("Parameter 'hash' is not a function, received type: undefined")
expect(fun2).toThrow("Parameter 'hash' is not a function, received type: number")
expect(fun3).toThrow("Parameter 'leaves' is not an object, received type: number")
})

it("Should not initialize a tree with a number of leaves > arity ** depth", () => {
Expand Down

0 comments on commit 73eda59

Please sign in to comment.