chadtmiller.com/monolith
An atproto PDS
0
0
#!/usr/bin/env bash
# Pins harness/spaces to a spaces alpha snapshot of the reference PDS:
# rewrites package.json's versions and overrides, and its lockfile. Run
# when the reference moves (`npm view @atproto/pds dist-tags.alpha`); then
# `npm ci`, `node vectors.mjs check`, and the spec's sources
# (spec/spaces/README.md) re-vendored from the commit the snapshot names.
#
# ./pin-alpha.sh 0.0.0-spaces-alpha-<timestamp>
#
# Every package of the snapshot is pinned through `overrides`, not left to
# ranges: the snapshot's own dependencies are ranges like
# `^0.0.0-spaces-alpha-<timestamp>`, which also match the release 0.0.0, and
# @atproto/lex@0.0.0 was published with unresolved `workspace:*`
# dependencies, so a plain install fails.
set -euo pipefail
cd "$(dirname "$0")"
V="${1:?usage: ./pin-alpha.sh <snapshot version>}"
node --input-type=module - "$V" <<'EOF'
import { execFileSync } from 'node:child_process'
import { readFileSync, writeFileSync } from 'node:fs'
const V = process.argv[2]
// Every package in @atproto/dev-env's tree whose range names the snapshot.
const seen = new Set()
const queue = ['@atproto/dev-env']
while (queue.length) {
const name = queue.shift()
if (seen.has(name)) continue
seen.add(name)
const out = execFileSync('npm', ['view', `${name}@${V}`, 'dependencies', '--json']).toString().trim()
for (const [d, r] of Object.entries(out ? JSON.parse(out) : {})) if (String(r).includes('spaces-alpha')) queue.push(d)
}
const pkg = JSON.parse(readFileSync('package.json', 'utf8'))
for (const name of Object.keys(pkg.dependencies)) if (seen.has(name)) pkg.dependencies[name] = V
pkg.overrides = Object.fromEntries([...seen].sort().map((n) => [n, V]))
writeFileSync('package.json', `${JSON.stringify(pkg, null, 2)}\n`)
console.error(`pinned ${seen.size} packages to ${V}`)
EOF
npm install --package-lock-only --loglevel=error