Skip to content

About

Opt-in npm registry: while a package's real CI light is dark, serve a fixed fork under the same name.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

patch-cloud

Opt-in npm-compatible registry that rewrites broken dependencies to your fork when the light computer internet lights say CI is dark.

Live status: https://patch-cloud-production.up.railway.app/status

Opt in to the live registry for one install:

npm install <pkg> --registry https://patch-cloud-production.up.railway.app

or for a whole project, add registry=https://patch-cloud-production.up.railway.app/ to .npmrc. Remove it to opt out.

pnpm users can opt in with the pnpm plugin instead (not on npm yet): pnpm add --config pnpm-plugin-patch-cloud. It only swaps packages whose light is dark and that have a fork ready, and installs normally if patch-cloud can't be reached.

Not committed here: the ~44 MB annotated next tarball (rebuild with npm run pack:next) and local-lights.json (copy local-lights.example.json to force the demo light dark).

Nothing is published to the public npm registry by this project. Fork / annotated tarballs live under tarballs/.

Dark lights board (/status)

/status in a browser is a public dark lights board:

  • Dark now: tracked packages whose upstream build is red, with days dark (from the first red run after the last passing one; "≥" when no passing run is in the 30 runs checked), whether a patch-cloud fork is served, and the one-line opt-in install when it is.
  • Merged fixes: near the top of /status (JSON: merged), upstream PRs merged by their maintainers that took a dark light to lit upstream: repo, PR link, title, merged date (ET), merged by, what was dark before, and that it's lit upstream now. Each entry says what happened: Before (which upstream light was dark, since when, why, plus a dark upstream run before the merge), Fix (one sentence) and After (the first upstream run after the merge and how many of the light's jobs are lit; "waiting for upstream light" until it is). Data lives in merged.json; add one with node add-merged.mjs owner/repo N --light "job name" --dark "why" --dark-since ISO --fix "what changed" [--dark-run URL] [--lit-run URL] (no deps; uses gh api, refuses unmerged PRs, dedupes by repo + PR, auto-detects the runs on the default branch when the URLs are omitted), then redeploy. Same list as lit-dark.
  • Watchlist: popular packages with dark CI from the npmmirror scan (watchlist.json, built by node build-watchlist.mjs from /workspace/mirror/dig.json + notes.json), with repo link, red run, why the build is red, fixability, and "no patch-cloud fork yet". It's a snapshot with day counts as of the scan; it isn't refreshed live.
  • All tracked lights: the full table as before.

JSON (/status?format=json) adds packages[].dark, packages[].install, packages[].npmWeeklyDownloads, and a top-level watchlist. "Dark" always means the upstream CI didn't pass. Installs from npm still work.

node seed-lights.mjs refreshes the bundled lights.json (with darkSince) before a deploy.

Light programs

light-programs reads this repo's lights.json, mapping.json and watchlist.json (plus the light computer's state.json) and prints suggested actions in plain words, such as the opt-in install line for a dark package with a ready fork. It's read-only, offline and suggest-only: node cli.mjs --patch-cloud ../patch-cloud.

Idea

  1. The light computer fetches CI status for public repos into lights.json (● lit = upstream build passing, ○ dark = upstream build failing; active-low). The registry tracks the light computer's 8 repos plus every GitHub repo in mapping.json, refreshed live.
  2. You point npm install at this registry (explicit --registry or project .npmrc).
  3. For a mapped package whose light is dark and rewriteReady, the registry serves your fork / annotated tarball under the same package name.
  4. When the light is lit, it serves local upstream (demo) or proxies to registry.npmjs.org — unless the package carries the labeled manual: fix available switch (below).
  5. Only the fork's version is replaced: the rest of the upstream packument (other versions, dist-tags) is merged in, so ranges like [email protected] or ajv@^8 keep resolving to upstream.
  6. Unmapped packages (including scoped @scope/name) are always proxied.

Opt in (one-liner)

npm install <pkg> --registry http://127.0.0.1:4873

Or a project .npmrc:

registry=http://127.0.0.1:4873/

After you pick a host, replace with https://<your-host>/. See DEPLOY.md.

Safety

  • Opt-in only — never the default registry.
  • Only packages in mapping.json with rewriteReady: true are rewritten, and only while their light is dark.
  • Registry is read-only (PUT/POST/DELETE → 405).
  • Check /status or open / for the landing page.
  • Opt out: remove the registry= override and reinstall from registry.npmjs.org.
  • Lockfiles: rewritten tarballs have different integrity hashes. Existing package-lock.json / npm ci will fail until you regenerate the lock while opted in (or opt out and use upstream).

Quick start (local)

# Terminal 1
node server.mjs
# or: npm start

curl -s http://127.0.0.1:4873/health
open http://127.0.0.1:4873/          # landing
curl -s http://127.0.0.1:4873/status | jq .

Demo: broken-demo

Forces both light states on demand (local/broken-demo). See the public light specification and proof in fitzyracing1/lit-dark (active-low: lit = 0, dark = 1).

node flip-light.mjs dark
npm install broken-demo --registry http://127.0.0.1:4873
node -e "console.log(require('broken-demo'))"   # fork

node flip-light.mjs lit
rm -rf node_modules/broken-demo package-lock.json
npm install broken-demo --registry http://127.0.0.1:4873
# upstream throws on require

Annotated next (CI-only fork)

The Next.js patch (PR #100001, branch rspack-manifest-fix) changes test manifests only. A rebuilt next would match upstream runtime for the same version, so we do not build the monorepo.

Instead, when vercel/next.js is dark, patch-cloud serves an annotated upstream [email protected] tarball:

  • PATCH-CLOUD.md inside the package
  • package.json#_patchCloud → { fork, branch, pr, … }

When the light is lit, requests for next are proxied to the public registry.

npm install next --registry http://127.0.0.1:4873
# then: ls node_modules/next/PATCH-CLOUD.md

Repack / refresh the annotated tarball:

node pack-annotated.mjs next \
  --fork fitzyracing1/next.js \
  --branch rspack-manifest-fix \
  --pr https://github.com/vercel/next.js/pull/100001 \
  --version 16.4.0

Mapping (npm rewrite targets)

Light repo npm name Rewrite
local/broken-demo broken-demo dark→fork, lit→local upstream
vercel/next.js next dark→annotated upstream tarball, lit→proxy
react/react react dark→annotated upstream [email protected] (fork fitzyracing1/react, no code changes yet), lit→proxy
ZJONSSON/node-unzipper [email protected] dark→fork: PR #331, @aws-sdk/client-s3 moved to dependencies
jimp-dev/jimp [email protected] dark→fork: real browser bundle instead of the published stub (#1402)
vercel/ms [email protected] dark→fork: format/parse round-trip (port of #299) + decimal option (#125)
prebuild/prebuild-install [email protected] dark→fork: tar-fs ^2.1.4 (CVE-2025-59343, PR #214)
cli-table/cli-table3 [email protected] dark→fork: rowSpan crash fix (PR #359)
iamkun/dayjs [email protected] light lit → served via manual: fix available (fork: tz perf, port of PR #2019)
ajv-validator/ajv ajv not rewritten (rewriteReady: false): PR #2591's ReDoS could not be reproduced; corrected branch on the fork for review
deno / node / vscode / rust / cpython / fakegreen — not npm rewrite targets (see ciPatch on some)

Each fork tarball keeps the upstream package name and version and adds PATCH-CLOUD.md plus package.json#_patchCloud describing exactly what changed. Built with node annotate-fork.mjs <checkout> fork-specs/<pkg>.json then npm pack. Focused repros live in repros/.

Manual switch: manual: fix available (#1)

Some fixes are real but CI can't see them (e.g. a performance bug). Faking a dark light would be dishonest, so a mapping entry can carry a clearly labeled override instead:

"iamkun/dayjs": {
  "npmName": "dayjs", "version": "1.11.23", "rewriteReady": true,
  "forkTarball": "tarballs/dayjs-1.11.23.tgz",
  "manualRewrite": { "reason": "Upstream CI is green but the perf fix (PR #2019) is unmerged", "since": "2026-10-11" }
}
  • Serves the fork while the light is lit; the light keeps its real CI conclusion and is never changed.
  • Needs rewriteReady: true and a reason. If the light goes dark, the normal dark rewrite applies.
  • /status shows rewrite: "manual", a manual object (label: "manual: fix available", reason, since) and counts it separately (counts.manual); HTML shows Fork available (manual: fix waiting upstream).
  • Responses carry X-Patch-Cloud: manual and _patchCloud.source: "manual"; tarballs are counted under downloads.manual, not fork.

Status wording

The primary label says what an installer gets; the upstream CI result is a small secondary line linking to the run:

Situation Primary label Secondary
light dark + fork packaged Fork available — download via patch-cloud upstream build: failing
manual switch Fork available (manual: fix waiting upstream) upstream build: passing
light dark, no fork Upstream build failing — no fork yet upstream build: failing
light lit Upstream OK — normal npm upstream build: passing

Config (env)

Env Default Purpose
PORT / PATCH_CLOUD_PORT 4873 Listen port
HOST / PATCH_CLOUD_HOST 127.0.0.1 Bind address (0.0.0.0 in Docker)
PUBLIC_URL (empty) Absolute base for dist.tarball URLs
LIGHTS_FILE greenlight or ./lights.json Lights snapshot
LIGHTS_CACHE_MINUTES 5 Cache TTL
LIGHTS_REFRESH off 1 = refresh from GitHub when cache expires
GITHUB_TOKEN — Optional for API rate limits (recommended: 15 repos are tracked)
LIGHTS_REFRESH_MINUTES cache minutes with token, 20 without Min interval between GitHub lights refreshes; failed fetches keep the last known light
UPSTREAM_REFRESH_MINUTES 10 with token, 60 without Min interval between upstream PR/issue state checks
PACKUMENT_CACHE_MINUTES 5 Cache for upstream packuments merged into rewrites
RATE_LIMIT_PER_MIN 120 Per-IP; 0 = off

Tests

node test-server.mjs

Starts the server on a random port and checks dark/lit rewrite, proxy (incl. scoped), PUT rejection, every patch-cloud target (fork version merged into the upstream packument, deps from the fork tarball, PATCH-CLOUD.md), the manual switch, and the status wording.

Deploy

Live on Railway: https://patch-cloud-production.up.railway.app (railway up from this directory; .railwayignore keeps fork checkouts out of the upload). See DEPLOY.md for other hosts.

Ethics

Silently replacing popular packages in a production registry that people hit by accident would be wrong. This tool is opt-in, read-only, and documents every rewrite on / and /status.

Files

Path Role
server.mjs Registry (no npm deps)
config.mjs Env-driven config
mapping.json lightRepo → npm / tarballs / ciPatch / manualRewrite
annotate-fork.mjs Adds PATCH-CLOUD.md + _patchCloud to a fork checkout before npm pack
fork-specs/ Per-package change/verification descriptions used for PATCH-CLOUD.md
repros/ Focused repros run against installed copies (unzipper, ms, cli-table3, dayjs, jimp, prebuild-install, ajv)
pack-annotated.mjs Download upstream + annotate + repack
test-server.mjs Integration tests
Dockerfile Container image
DEPLOY.md Host options (no accounts created)
tarballs/ Served .tgz files
lights.json Bundled snapshot for deploy

Plans

This project is free, and its license stays as is. Support it through GitHub Sponsors:

  • Free: use the code, community support.
  • Pro ($49/month): priority issues and support.
  • Team ($199/month): priority support for your team plus early access.

About

Opt-in npm registry: while a package's real CI light is dark, serve a fixed fork under the same name.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages