chore: Add version synchronization scripts
ADD
scripts/all-versions.sh
+#!/bin/bash
+jq '
+ ((.dependencies // {}), (.devDependencies // {}))
+ | to_entries[]
+' packages/*/package.json \
+| jq --slurp '
+ group_by(.key)[] |
+ {
+ key: [.[] | .key][0],
+ value: ([
+ .[] |
+ .value |
+ (capture("[^0-9]*(?<major>[0-9]+).(?<minor>[0-9]+).(?<patch>[0-9]+)") // {}) |
+ [(.major | tonumber), (.minor | tonumber), (.patch | tonumber)]
+ ] | sort | last | "^\(.[0]).\(.[1]).\(.[2])")
+ }
+' | jq --slurp 'from_entries'
+

ADD
scripts/get-versions.sh
+#!/bin/bash
+set -ueo pipefail
+
+# Gather a map of the versions from this or another workspace.
+WORKDIR=${1:-.}
+
+cd -- "$WORKDIR"
+yarn workspaces --json info |
+jq -r '.data | fromjson | .[].location | "\(.)/package.json"' |
+xargs jq '{key: .name, value: "^\(.version)"}' |
+jq --slurp from_entries

ADD
scripts/set-versions.sh
+#!/bin/bash
+set -ueo pipefail
+
+# Accepts a dependency version map on stdin and updates all of the
+# package.jsons in this workspace such that, if they depend on one of the named
+# dependencies, it uses the version from the map.
+# This is useful for consistent bulk updates over all packages.
+
+DIR=$(dirname -- "${BASH_SOURCE[0]}")
+VERSIONSHASH=$(git hash-object -w --stdin)
+
+cd -- "$DIR/.."
+
+yarn workspaces --json info |
+jq -r '.data | fromjson | .[].location | "\(.)/package.json"' |
+while read PACKAGEJSON; do
+ PACKAGEJSONHASH=$(
+ jq --argfile versions <(git cat-file blob "$VERSIONSHASH") '
+ def update(name): if .[name] then {
+ (name): [
+ .[name] |
+ to_entries[] |
+ {
+ key: .key,
+ value: ($versions[.key] // .value)
+ }
+ ] | from_entries
+ } else {} end;
+
+ . +
+ update("dependencies") +
+ update("devDependencies") +
+ update("peerDependencies")
+ ' "$PACKAGEJSON" |
+ git hash-object -w --stdin
+ )
+ git cat-file blob "$PACKAGEJSONHASH" > "$PACKAGEJSON"
+done

ADD
scripts/sync-versions.sh
+#!/bin/bash
+set -ueo pipefail
+
+# Synchronizes dependencies from this workspace with the last-published
+# versions of this or another workspace, designated by the path to the work of
+# that workspace.
+# This is specifically useful for syncing the versions published from the
+# Endo workspace repository.
+
+DIR=$(dirname -- "${BASH_SOURCE[0]}")
+
+"$DIR/get-versions.sh" "$@" | "$DIR/set-versions.sh"

chore: Add version synchronization scripts