Synthetix JS - Monorepo
Packages
| Package | Status | Description |
|---|---|---|
@synthetixio/contracts-interface |
Synthetix contracts interface | |
@synthetixio/queries |
React library for querying data | |
@synthetixio/providers |
Synthetix providers for layer 1 and 2 | |
@synthetixio/optimism-networks |
Network utility for layer 2 | |
@synthetixio/codegen-graph-ts |
Query generator | |
@synthetixio/safe-import |
Async imports with retry |
Install
This repo uses Yarn workspaces to manage multiple packages in the same repo. To prepare the repository for use, run:
yarn installThis will install all dependencies, wire dependencies between packages in this repo, and allow for you to build projects.
Build
If you make a change and want to generate the library JS code, run:
yarn buildThis will ensure all projects are fully built in topological order. You are also free to run script commands from individual repositories if necessary or desired.
Publish
Monorepo is now switched to independent versioning so each package inside monorepo can have its own version independently of all others
Publishing new version after synthetix upgrade
We have a GitHub workflow for publishing releases.
To publish:
- Go here https://github.com/Synthetixio/js-monorepo/actions/workflows/updateDependency.yml
- Click Run Workflow
- Fill
synthetix_versionin a format of1.2.3for the version - Run the workflow
This will upgrade synthetix in the monorepo and all affected packages will be published with new patch release
For example now only the @synthetixio/contracts-interface package depends on synthetix, so it will get new patch version. But then all the packages that depend on it will get new patch version in a cascade (check full list of cascade updates with yarn deps:version). So overall these packages will be published:
@synthetixio/contracts-interface@synthetixio/providers@synthetixio/queries
Publishing new version of a single package
We have a GitHub workflow for publishing package releases.
To publish:
- Go here https://github.com/Synthetixio/js-monorepo/actions/workflows/publishSinglePackage.yml
- Click Run Workflow
- Fill
packagein a format of@synthetixio/weifor the package name - Fill
versionin a format of1.2.3(orpatch,minor,major) for the package version (optional, default value ispatch) - Run the workflow
NOTE: All the packages that depend on package will be published with patch version automatically.
For example when publishing @synthetixio/wei these packages will get updates (check with yarn deps:version):
@synthetixio/wei@synthetixio/codegen-graph-ts@synthetixio/queries
Testing release
When you open a PR a dev package will be published automatically when CI passes. The version will be 0.0.0-<git short sha>
Manual
Yarn workspaces are specially designed to handle package updates. If you want to push a new release for one or more packages in this repo, run:
- Firstly set desired versions to updated packages:
yarn version check --interactive - Then apply new versions
yarn apply --all - Commit changes
- And now we can publish all the updated packages
yarn workspaces foreach --no-private npm publish --tolerate-republish - Yarn will automatically replace all the
workspace:*versions with appropriate semver on publish.
Adding external library to the monorepo preserving git history
This is 3-step process:
- Prepare original repo
- Add remote to monorepo
- Merge original repo branch and update build to match monorepo processes
Using codegen-graph-ts as an example
1. Prepare original repo
- Create a separate branch
move-to-monorepo - Create the intended destination folder inside monorepo
mkdir -p tools/codegen-graph-ts - Move all the package files into
tools/codegen-graph-ts - Remove all the files that won't be used (CI config, lockfile, etc)
Commit looks like this:

2. Add remote to monorepo
cd ~/synthetix/js-monorepo
git remote add codegen-graph-ts ~/synthetix/codegen-graph-ts
git fetch --all
#
git merge codegen-graph-ts/move-to-monorepo --allow-unrelated-histories3. Merge original repo branch
Using --allow-unrelated-histories allows merging independent git history
git merge codegen-graph-ts/move-to-monorepo --allow-unrelated-historiesBecause we moved all the files into the separate folder we have no merge conflicts and at the same time we have full history added to the git tree

Now we can remove remote as it is no longer necessary and cleanup all the added tags too
git remote remove codegen-graph-ts
# Cleanup all local tags and re-fetch existing tags without just removed `codegen-graph-ts` remote
git tag -l | xargs git tag -d
git fetch --tagsRebasing unmerged branch
To preserve all the merge commits when rebasing on top of updated master use --rebase-merges
git rebase master --rebase-mergeInteractive rebase works too
git rebase master --rebase-merge --interactive