Mass JSON Edits in a Monorepo

As mentioned in the previous post, I’ve migrated a couple key Abacus repos from Stash to Github. I’ve done this in preparation for open source as well as to leverage greater tooling and infrastructure. I like Stash, but it cannot compete with the Github ecosystem.

One of the two repos I’ve migrated is the Abacus monorepo. For context, Abacus consists of 3 main repos:

  1. Abacus Editor App, a reference implementation and future basis for a hosted offering
  2. Abacus Viz Framework, a framework for laying out performant virtual DOM viz with academic principles
  3. Abacus, a monorepo containing many small modules that other project, including the above, are made out of. Why a monorepo? To take advantage of centralized testing & tooling as well as to see what Lerna is made out of

As part of migrating #3, I used The Silver Searcher to find all references to Stash. Most of them were in the Lerna packages folder at packages/abacus-*/package.json. I’m a fan of using the most precise tool you’re effective with, so I opted to use Trent Mick’s json instead of something like sed. Using zsh in concert with json, I was able to precisely edit those package files like so:

#!/usr/bin/env zsh
for pkg in packages/abacus-*/package.json
echo "Editing $pkg with $1"
json -I -f $pkg -e $1
./pkedit 'this.repository.url=""

Hopefully that will help you out in your own massive JSON situations. Cheers y’all!