consensus-shipyard / ipc

🌳 Spawn multi-level trees of customized, scalable, EVM-compatible networks with IPC. L2++ powered by FVM, Wasm, libp2p, IPFS/IPLD, and CometBFT.
https://ipc.space
Apache License 2.0
44 stars 39 forks source link

chore(contracts, extras): adopt pnpm; use node_modules dependencies. #1020

Closed raulk closed 5 months ago

raulk commented 5 months ago

Summary

Prepares the repo to publish functioning npm packages for contracts, extras/linked-token, and extras/axelar-token.

Dependencies as node packages

We stop relying on forge dependencies (submodules in lib) and instead adopts package.json for contract dependency management, i.e. OpenZeppelin, Elliptic Curve, and Fevmate are now taken from node_modules. Unfortunately, murky is not published as a package, so that remains. This is necessary to enable dependents to create build graphs and resolve transitive dependencies correctly. We could've kept both Foundry libs and node_modules in parallel, but we'd have created a footgun, as dependency graphs for local builds (forge) could diverge from the dependency graph as seen by importers (npm).

Migration to pnpm

To make remapping resolution work properly and cleanly from node_modules with contract monorepos like this, we need to prevent node_modules hoisting. That is, inner modules cannot hoist dependencies to the workspace root, as (a) Foundry cannot find them there, and (b) adding a manual remapping would be dirty as it'll need to escape the current module scope. We could avoid using workspaces (that way every node_modules would be isolated), but this would force us to use ugly relative paths in inter-package dependencies (e.g. axelar-token and linked-token need to use the IPC contracts and SDK).

This was our forcing function to migrate from npm to pnpm, which is anyway a more modern, space-efficient and way faster package manager. While it does hoist dependencies to the root, it creates symlinks from the node_modules in inner modules to the real location at the root. This enables Foundry to discover these modules, and makes us happy as we don't need to use tree-dependent paths (e.g. ../../node_modules/...) in our remappings.

I have migrated all Makefiles, GitHub Action Workflows, and scripts to use pnpm.

Other minor cleanups