Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

docs: record the platform package check, Wrangler 4 and the audit

spacesdrive956de8caeb22
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 695fa04..e84088d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,8 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Changing a tracked item's account now only accepts one of your own Reddit accounts, and refuses an account on a YouTube item (#76)
- A token refresh and an analytics refresh on the same account at the same moment no longer put the old access token back, and a manual view count no longer disappears when a refresh lands at the same time (#79)
- Accounts are listed in the order they were added, the same on every load (#78)
+- CI and the deploys no longer fail when npm skips a platform binary during the install; every workflow checks the platform packages after `npm ci` and installs once more if one is missing (#82)
+- Security: hono in the Worker and react-router in the app and the site are updated to versions without known vulnerabilities; Wrangler moves to 4 and the shadcn CLI to 4.21.5, which clears every audit finding that has a fix (#83, ADR-039)
---
diff --git a/DECISIONS.md b/DECISIONS.md
index b2b0d76..3d0705d 100644
--- a/DECISIONS.md
+++ b/DECISIONS.md
@@ -827,3 +827,25 @@ New row ids come from `crypto.randomUUID()` (`newRowId()` in `backend/lib/ids.ts
- A field passed as `undefined` in an update is dropped from the JSON, so it keeps its stored value instead of being removed. Clearing a field takes an explicit `null`.
- Rolling back is manual: run the rollback file, then repair the migration history. The baselines cannot be rolled back.
- The PGlite harness that ran the migrations lived in a scratchpad and is not in the repository. Running the SQL in CI would need the `@electric-sql/pglite` dev dependency, which was not approved; `migrations.test.ts` checks names, order, rollback pairs, repeatable baselines and closed functions without running the SQL. Adding the harness is a possible follow-up.
+
+## ADR-039: Wrangler 4, a platform package check after every install, and audit findings without a fix
+
+**Date:** 2026-10-16
+**Status:** Accepted
+
+**Decision:** Wrangler moves from 3 to 4 (4.151.0), hono and react-router move to patched versions within their majors, and the shadcn CLI to 4.21.5, which clears every `npm audit` finding that has a fix. Every workflow runs `scripts/check-platform-packages.ts` after `npm ci` and installs once more when it names a missing platform package. The seven findings left are one chain inside the shadcn CLI (`fast-glob`, `micromatch`, `braces`, GHSA-vfj7-8cjw-p6xm) and are accepted until `braces` publishes a fixed release.
+
+**Context:** `npm audit` reported 18 findings (#83). Two were in shipped code: hono in the Worker (a ReDoS in the CORS middleware, among others) and react-router in the app and the site. The rest came from developer and deploy tooling, most of them from Wrangler 3's esbuild, miniflare, undici, ws and sharp. Separately, a CI run failed because `npm ci` skipped workerd's Linux binary: npm treats a failed download of an optional dependency as success, and platform binaries are optional dependencies (#82).
+
+**Wrangler 4:** its breaking changes are Node 22 or newer (the project already needs Node 22.18), esbuild 0.24 for bundling (it changes wildcard dynamic imports, which the Worker does not use), local mode by default for KV, R2 and D1 commands (not used), and the removal of legacy assets, `node_compat` and commands deprecated in v3 (not used). The Worker bundles to 1160.83 KiB (1149.84 KiB with Wrangler 3; the difference is the newer hono) and starts under `wrangler dev`.
+
+**The accepted chain:** `braces` 3.0.3 is its latest release and the advisory covers every version up to it, so no update or override can fix it. The chain runs only inside the shadcn CLI on a developer's machine: the app imports `shadcn/tailwind.css` and no JavaScript from the package, and the denial of service needs an attacker to pass deeply nested glob patterns to that CLI. `npm audit fix --force` would install shadcn 1.0.0, a downgrade that breaks the CSS import.
+
+**Alternatives considered:**
+- Retrying `npm ci` blindly on any failure. It would not help: the install that skips a package reports success.
+- `npm install --include=optional` or pinning each binary as a direct dependency. The first changes nothing for a failed download, and the second ties the root `package.json` to every tool's binary versions.
+- Overriding `braces` to a fork. It would trade an advisory in a dev-only CLI for an unreviewed package.
+
+**Trade-offs:**
+- A skipped platform package now costs one extra `npm ci` (about 20 seconds) instead of a failed run.
+- The audit is not clean while the shadcn chain waits for upstream; check it again when `braces` or `fast-glob` releases a fix.
diff --git a/claude.md b/claude.md
index e241bed..ff0478b 100644
--- a/claude.md
+++ b/claude.md
@@ -45,7 +45,8 @@ backend/ Hono Worker in layers: middleware/, routes/, controllers/,
frontend/ React SPA (the app); tests in frontend/tests/ mirroring frontend/src/
site/ public marketing site and docs (Vite, React, MDX); docs pages in site/content/docs/,
build plugins in site/build/, tests in site/tests/
-scripts/ publish-scheduled.ts, run by GitHub Actions with no dependencies
+scripts/ publish-scheduled.ts, run by GitHub Actions with no dependencies; check-platform-packages.ts,
+ run after npm ci in every workflow
supabase/ the database schema: migrations/ (versioned SQL, one table or function per file, applied
with the Supabase CLI), rollbacks/ (the reverse of each migration, same file name),
config.toml (CLI config, Postgres 17)
diff --git a/docs/architecture/cloudflare/CI_CD.md b/docs/architecture/cloudflare/CI_CD.md
index 7bbbce7..b0346a6 100644
--- a/docs/architecture/cloudflare/CI_CD.md
+++ b/docs/architecture/cloudflare/CI_CD.md
@@ -21,7 +21,7 @@ Nothing compiles TypeScript ahead of time: Wrangler and Vite strip the types whi
**What it does (one job, "Type check, lint, test, build"):**
1. Checkout repo
2. `actions/setup-node@v4` with Node 24 and the npm cache keyed on the root `package-lock.json`
-3. `npm ci` at the repository root
+3. `npm ci` at the repository root, then `node scripts/check-platform-packages.ts`, which installs once more when npm skipped a platform package
4. `npm run typecheck` - every TypeScript project: backend, backend tests, frontend, frontend tooling and tests, site, site build files and tests, scripts
5. `npm run lint` - ESLint over the whole repository
6. `npm test` - backend, frontend, then site tests
@@ -41,7 +41,7 @@ Nothing compiles TypeScript ahead of time: Wrangler and Vite strip the types whi
**What it does:**
1. Checkout repo
2. `actions/setup-node@v4` with Node 24 and the npm cache keyed on the root `package-lock.json`
-3. `npm ci` at the repository root, which installs every workspace, including Wrangler
+3. `npm ci` at the repository root, which installs every workspace, including Wrangler, then `node scripts/check-platform-packages.ts`, which installs once more when npm skipped a platform package
4. `npm run typecheck --workspace backend` - checks the Worker source and the backend tests
5. `npm test --workspace backend`
6. Run `wrangler deploy` via `cloudflare/wrangler-action@v4` with `workingDirectory: backend`. The action finds the Wrangler installed from the lockfile (3.114.17) and uses it instead of installing its own default version.
@@ -65,7 +65,7 @@ The workflow does not set the Worker's own secrets (`SUPABASE_*`, `FRONTEND_URL`
**What it does:**
1. Checkout repo
2. `actions/setup-node@v4` with Node 24 and the npm cache keyed on the root `package-lock.json`
-3. `npm ci` at the repository root, which installs every workspace
+3. `npm ci` at the repository root, which installs every workspace, then `node scripts/check-platform-packages.ts`, which installs once more when npm skipped a platform package
4. `npm run typecheck --workspace frontend` - checks `frontend/src` (`tsconfig.json`) and `vite.config.ts` plus the frontend tests (`tsconfig.node.json`)
5. `npm test --workspace frontend`
6. `npm run build --workspace frontend` - Vite builds to `frontend/dist/`
@@ -91,7 +91,7 @@ The workflow does not set the Worker's own secrets (`SUPABASE_*`, `FRONTEND_URL`
**What it does:**
1. Checkout repo
2. `actions/setup-node@v4` with Node 24 and the npm cache keyed on the root `package-lock.json`
-3. `npm ci` at the repository root, which installs every workspace, including Wrangler
+3. `npm ci` at the repository root, which installs every workspace, including Wrangler, then `node scripts/check-platform-packages.ts`, which installs once more when npm skipped a platform package
4. `npm run typecheck --workspace site` - checks `site/src` (`tsconfig.json`) and `vite.config.ts`, `site/build` and the site tests (`tsconfig.node.json`)
5. `npm test --workspace site`
6. `npm run build --workspace site` - Vite builds to `site/dist/`, and the docs plugin adds `sitemap.xml` and `llms.txt`
@@ -170,11 +170,15 @@ Open `https://twiligent.ujjwal.fyi` - verify the home page renders, then open `h
**Publisher:**
Trigger `publish-scheduled.yml` manually via GitHub Actions UI -> Actions -> "Instagram Scheduled Publisher" -> "Run workflow" -> check the run log for expected output.
+## Platform Packages After Install
+
+Native binaries such as workerd, esbuild, rollup, lightningcss and Tailwind's oxide are optional dependencies, one package per platform. npm skips an optional package it fails to download and still reports a successful install, so a run could reach the Worker bundle without `@cloudflare/workerd-linux-64` (this happened once, on PR #81). `scripts/check-platform-packages.ts` reads the root `package-lock.json`, keeps the optional packages whose `os`, `cpu` and libc match the machine (the glibc and musl builds are told apart by name when the lockfile has no `libc` field), and exits 1 naming any that are missing. Every workflow runs it after `npm ci` and, if it fails, runs `npm ci` and the check once more; a second failure stops the job. Run it locally with `node scripts/check-platform-packages.ts`.
+
## Adding a New Workflow
1. Create `.github/workflows/my-workflow.yml`
2. Add appropriate path filters to avoid unnecessary runs
-3. If the workflow needs project dependencies, run `actions/setup-node` with Node 24, `cache-dependency-path: package-lock.json` and `npm ci` at the repository root; there are no lockfiles inside `backend/`, `frontend/` or `site/`
+3. If the workflow needs project dependencies, run `actions/setup-node` with Node 24, `cache-dependency-path: package-lock.json` and the install step the other workflows use (`npm ci` at the repository root, then `node scripts/check-platform-packages.ts`, installing again once if it fails); there are no lockfiles inside `backend/`, `frontend/` or `site/`
4. If it ships code, run `npm run typecheck` (or the workspace's `typecheck` script) before the deploy step
5. Document it in `docs/architecture/cloudflare/CI_CD.md` (this file)
6. Add any required secrets via GitHub repo -> Settings -> Secrets -> Actions
diff --git a/docs/architecture/cloudflare/PAGES.md b/docs/architecture/cloudflare/PAGES.md
index 5d4a765..d814e88 100644
--- a/docs/architecture/cloudflare/PAGES.md
+++ b/docs/architecture/cloudflare/PAGES.md
@@ -59,7 +59,7 @@ Vite exposes them at runtime as `import.meta.env.VITE_*`.
## Deployment
-Cloudflare Pages deploys automatically on every push to `main` that changes files in `frontend/` or `shared/`, `tsconfig.base.json`, the root `package.json` or the root `package-lock.json`. This is configured in `.github/workflows/deploy-frontend.yml`, which runs `npm ci` at the root, type-checks and tests the frontend, builds with `npm run build --workspace frontend` and uploads `frontend/dist` with the Wrangler version from the lockfile.
+Cloudflare Pages deploys automatically on every push to `main` that changes files in `frontend/` or `shared/`, `tsconfig.base.json`, the root `package.json` or the root `package-lock.json`. This is configured in `.github/workflows/deploy-frontend.yml`, which runs `npm ci` at the root and checks the platform packages (`scripts/check-platform-packages.ts`, installing once more if one is missing), type-checks and tests the frontend, builds with `npm run build --workspace frontend` and uploads `frontend/dist` with the Wrangler version from the lockfile.
Manual deployment (emergency or first setup), from the repository root:
diff --git a/docs/features/NEW_SCHEDULED_TASK.md b/docs/features/NEW_SCHEDULED_TASK.md
index 848777e..d22b566 100644
--- a/docs/features/NEW_SCHEDULED_TASK.md
+++ b/docs/features/NEW_SCHEDULED_TASK.md
@@ -175,7 +175,9 @@ jobs:
cache: 'npm'
cache-dependency-path: package-lock.json
# one install at the root; @supabase/supabase-js is already in the root lockfile
- - run: npm ci
+ - run: |
+ npm ci
+ node scripts/check-platform-packages.ts || (npm ci && node scripts/check-platform-packages.ts)
- name: Run task
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
@@ -183,7 +185,7 @@ jobs:
run: node scripts/my-task.ts
```
-Install from the root lockfile with `npm ci`, as the deploy workflows do. Do not run `npm install <pkg>` in the workflow: at the root it would add the package to the root `package.json`, and there is no lockfile inside `backend/` or `frontend/` to install from. If the script needs a package that is not in the lockfile yet, add it to the workspace that owns it (with approval) and commit the root lockfile. `scripts/publish-scheduled.ts` is the exception by design: it has no dependencies, so its workflow skips the install.
+Install from the root lockfile with `npm ci` and check the platform packages, as the deploy workflows do. Do not run `npm install <pkg>` in the workflow: at the root it would add the package to the root `package.json`, and there is no lockfile inside `backend/` or `frontend/` to install from. If the script needs a package that is not in the lockfile yet, add it to the workspace that owns it (with approval) and commit the root lockfile. `scripts/publish-scheduled.ts` is the exception by design: it has no dependencies, so its workflow skips the install.
### Step 3: Add Required Secrets
diff --git a/docs/workflows/DEPLOYMENT.md b/docs/workflows/DEPLOYMENT.md
index 17a7414..1c3451c 100644
--- a/docs/workflows/DEPLOYMENT.md
+++ b/docs/workflows/DEPLOYMENT.md
@@ -19,7 +19,7 @@ A pull request merged into `main` -> GitHub Actions deploys automatically. `main
Monitor deployment status at:
`https://github.com/spacesdrive/twiligent/actions`
-Each deploy workflow sets up Node 24, runs `npm ci` once at the repository root (the root `package-lock.json` is the only lockfile), type-checks and tests its workspace (`npm run typecheck --workspace <name>`, `npm test --workspace <name>`), and only then deploys with the Wrangler version pinned in that lockfile. A type error or failing test stops the deploy. Before code reaches `main`, `ci.yml` runs the full type check, lint, tests, the frontend and site builds and a Worker dry-run bundle on every pull request and branch push. See `docs/architecture/cloudflare/CI_CD.md`.
+Each deploy workflow sets up Node 24, runs `npm ci` once at the repository root (the root `package-lock.json` is the only lockfile) and checks that every platform package arrived (`scripts/check-platform-packages.ts`, installing once more if one is missing), type-checks and tests its workspace (`npm run typecheck --workspace <name>`, `npm test --workspace <name>`), and only then deploys with the Wrangler version pinned in that lockfile. A type error or failing test stops the deploy. Before code reaches `main`, `ci.yml` runs the full type check, lint, tests, the frontend and site builds and a Worker dry-run bundle on every pull request and branch push. See `docs/architecture/cloudflare/CI_CD.md`.
## Manual Deployment (Local)