Skip to content

Commit

Permalink
feat: expose utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanie committed Dec 20, 2024
1 parent aa1cc70 commit b2df49d
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 225 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
dist/utils.*
24 changes: 24 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { uniqWith } from 'lodash';
import { AbiEvent, AbiFunction, type Abi } from 'abitype';

export type NodeType = 'event' | 'function';

export type AbiNode = AbiEvent | AbiFunction;

const stringifyInputTypes = (node: AbiNode) =>
JSON.stringify(node.inputs.map(({ type }) => type));

// Some newer versions of the compiler add extra stuff that prevents a deep equal comparison
const nodesAreEqual = (nodeA: AbiNode, nodeB: AbiNode) =>
nodeA.name === nodeB.name &&
stringifyInputTypes(nodeA) === stringifyInputTypes(nodeB);

export const joinAbis = (abiA: Abi, abiB: Abi, nodeType: NodeType) => {
return uniqWith(
(abiA as AbiNode[]).concat(
(abiB as AbiNode[]).filter(({ type }: { type: string }) => type === nodeType),
),
nodesAreEqual,
);
};

18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@
"README.md"
],
"exports": {
"./utils": "./dist/utils.js",
"./*": "./dist/*.json"
},
"main": "./dist/versions.json",
"module": "./dist/versions.json",
"license": "GPL-3.0-only",
"engines": {
"node": "^16 || ^18 || ^20",
"npm": "^8 || ^9 || ^10"
"node": "^18 || ^20 || ^22",
"npm": "^10"
},
"scripts": {
"build": "ts-node scripts/extract-contract-abis.ts",
"build": "ts-node scripts/extract-contract-abis.ts && tsc lib/utils.ts --skipLibCheck --declaration --outDir dist",
"test": "node scripts/check-versions.mjs",
"prepare": "husky install"
},
"dependencies": {
"abitype": "^1.0.7",
"lodash": "^4.17.21"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@types/lodash": "^4.14.191",
"@types/mkdirp": "^1.0.2",
"@types/rimraf": "^3.0.2",
Expand All @@ -39,12 +44,11 @@
"eslint-plugin-prettier": "^4.2.1",
"fast-glob": "^3.2.11",
"husky": "^8.0.3",
"lodash": "^4.17.21",
"mkdirp": "^1.0.4",
"prettier": "^2.8.0",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.3",
"typescript": "^5.7.2",
"yargs": "^17.3.1"
}
}
Loading

0 comments on commit b2df49d

Please sign in to comment.