Read the whole story.

Every text file that makes pkgs.win run, straight from the current build. The tree is rendered with Trees. No external forge, no detour.

Commit
f21338e6
Files
70
Lines
16,255
Size
467 KiB
pkgs-win.git
main · f21338e6
README.md
Markdown · 230 lines · 13 KiB
# pkgs.win
Browse ~13,500 winget packages with instant client-side search, and build JSON lists for `winget import`.
[![Live site](https://img.shields.io/badge/live-pkgs.win-2185d0)](https://pkgs.win)
[![Source explorer](https://img.shields.io/badge/source-pkgs.win%2Fsource-2185d0?logo=git&logoColor=white)](https://pkgs.win/source/)
[![Forgejo Runner](https://img.shields.io/badge/CI-Forgejo%20Runner-2185d0)](#deployment)
A static website for browsing [Windows Package Manager (winget)](https://learn.microsoft.com/en-us/windows/package-manager/) packages and assembling [WinGet Package Lists](https://learn.microsoft.com/en-us/windows/package-manager/winget/import) for batch install. Built with [Astro](https://astro.build), deployed on [Cloudflare Pages](https://pages.cloudflare.com). Live at [pkgs.win](https://pkgs.win), with a searchable, syntax-highlighted source explorer at [pkgs.win/source](https://pkgs.win/source/).
## Contents
- [Prerequisites](#prerequisites)
- [Quickstart](#quickstart)
- [Project Structure](#project-structure)
- [Commands](#commands)
- [How It Works](#how-it-works)
- [Source Explorer](#source-explorer)
- [WinGet Package Lists](#winget-package-lists)
- [Data Lifecycle](#data-lifecycle)
- [Deployment](#deployment)
- [Troubleshooting](#troubleshooting)
- [Tech Stack](#tech-stack)
## Screenshots
<p align="center">
<img src="public/images/screenshot_desktop.png" alt="Desktop package search and results view" width="70%">
<img src="public/images/screenshot_mobile.png" alt="Mobile package details and navigation view" width="25%">
</p>
## Prerequisites
- Node.js 26 (see `.nvmrc`)
- pnpm 12.15: `npm install -g --allow-scripts=pnpm [email protected]`
## Quickstart
```sh
pnpm install
pnpm setup
pnpm ingest # if src/data/winget-pkgs/ exists but is empty: INGEST_USE_BARE_REPO=1 pnpm ingest
pnpm dev # http://localhost:4321
```
To produce a production build instead of the dev server, run `pnpm build:site` (requires a prior `pnpm ingest`).
## Project Structure
```
src/
├── components/ Astro components (Search, PackageCard, InstallerTable, VersionList)
├── data/ winget source + generated JSON (see Data Lifecycle)
├── layouts/ Base.astro — header, search, SEO meta, theme toggle
├── lib/ Package loading, source-tree loading, search query parser, WinGet package-list helpers, stats, types
├── middleware.ts URL rewrites/redirects for `/stats/build/…`
├── pages/ Routes (see table below)
├── scripts/ Client scripts (search, package-list builder, source browser, stats, copy)
└── styles/ Design tokens + base/utilities/components/pages/source CSS
scripts/
└── ingest.ts Parses winget-pkgs YAML manifests into JSON
public/ Static assets (favicon, logo)
```
### Routes
| Route | File | Purpose |
| :--- | :--- | :--- |
| `/` | `pages/index.astro` | Homepage with featured packages |
| `/search` | `pages/search.astro` | Client-side search (MiniSearch) |
| `/package-lists` | `pages/package-lists/index.astro` | Build JSON / scripts for `winget import` |
| `/packages/[letter]` | `pages/packages/[letter].astro` | Per-letter package listings |
| `/packages/[letter]/[id]` | `pages/packages/[letter]/[id].astro` | Package detail page |
| `/stats` | `pages/stats/` | Build statistics pages |
| `/licenses`, `/publishers`, `/tags` | `pages/{licenses,publishers,tags}.astro` | Browse-by pages |
| `/about`, `/help` | `pages/{about,help}.astro` | Static info pages |
| `/source` | `pages/source.astro` | Searchable project source tree rendered with Trees |
| `/search-index.json` | `pages/search-index.json.ts` | Static search index endpoint |
| `/package-versions.json` | `pages/package-versions.json.ts` | Compact version lists for the package-list builder |
| `/rss.xml` | `pages/rss.xml.ts` | RSS feed |
## Commands
| Command | Action |
| :--- | :--- |
| `pnpm dev` | Start dev server at `localhost:4321` |
| `pnpm build` | Full build: setup bare repo, ingest packages, build site |
| `pnpm build:site` | Build Astro site only (requires data from a prior ingest) |
| `pnpm build:filtered` | Build and only show routes slower than 200ms |
| `pnpm preview` | Preview the built site locally |
| `pnpm ingest` | Run the ingest script to parse winget-pkgs manifests |
| `pnpm ingest:dry` | Validate ingest results without writing package data, indexes, hashes, or stats |
| `pnpm setup` | Init/update the bare winget-pkgs clone (`src/data/winget-pkgs.git`) |
| `pnpm astro` | Run Astro CLI commands |
| `pnpm deploy` | Deploy `dist/` to Cloudflare Pages |
| `pnpm stats:backup` | Checkpoint and gzip the stats database to `stats.db.gz` |
| `pnpm stats:restore` | Restore `stats.db.gz` if the local stats database is missing |
| `pnpm stats:upload` | Upload `stats.db.gz` to the Forgejo `stats` release |
| `pnpm stats:download` | Download the latest `stats.db.gz` release asset |
## How It Works
1. **Bare Repository** -- `microsoft/winget-pkgs` is cloned as a **bare shallow repo** (`--depth=1`) into `src/data/winget-pkgs.git`. No working tree is checked out (would be ~500k files). The ingest reads manifests directly via `git ls-tree -r` and `git cat-file --batch`.
2. **Ingest** -- `scripts/ingest.ts` discovers manifest paths in the bare repo, parses YAML, and writes one JSON file per package to `src/data/packages/`. It also generates auxiliary index files:
- `packages-by-letter/*.json` -- pre-grouped and sorted packages for fast Astro builds
- `search-index.json` -- compact search index for MiniSearch
- `package-versions.json` -- id → versions[] (newest first) for the package-list builder
- `licenses.json`, `tags.json`, `publishers.json` -- pre-aggregated lists
- `package-info.json` -- lightweight id → name/publisher mapping
A `.hashes.json` file tracks file hashes for incremental rebuilds, and `stats.db` stores build statistics.
3. **Build** -- Astro generates a static page for every package (`/packages/<PackageIdentifier>`), a homepage with featured packages, search, package-list builder, and JSON endpoints (`/search-index.json`, `/package-versions.json`).
4. **Search** -- Client-side search powered by [MiniSearch](https://lucaong.github.io/minisearch/). The search index is a single JSON file (~2.6 MB, ~785 KB gzipped) loaded on demand when visiting `/search` or `/package-lists`. Queries support filters: `tag:` / `tags:`, `publisher:`, `id:` (combinable, e.g. `firefox tag: browser`).
5. **Source explorer** -- `/source` reads the repository's tracked text files at build time, embeds them in the page, and renders them through [Trees](https://trees.software/). Syntax highlighting is handled by [Shiki](https://shiki.style/) in the separate code viewer.
## Source Explorer
- File tree starts with every folder collapsed.
- Built-in tree search, plus `/` as a keyboard shortcut.
- Selected files are highlighted with Shiki using matching light and dark themes.
- Long code lines wrap instead of forcing horizontal scrolling.
- Line numbers stay aligned with wrapped lines.
- Deep links use the file path as the URL hash, for example `/source/#src/lib/source.ts`.
- The copy button copies the whole file; generated data, binary assets, and `pnpm-lock.yaml` are omitted.
## WinGet Package Lists
`/package-lists` builds a [schema 2.0](https://aka.ms/winget-packages.schema.2.0.json) JSON file for [`winget import`](https://learn.microsoft.com/en-us/windows/package-manager/winget/import):
1. Search the same MiniSearch index (including `tag:` / `publisher:` / `id:` filters) and add packages.
2. Optionally pin a version (from `/package-versions.json`; default is latest).
3. Import an existing `winget export` JSON, or start from the homepage featured set.
4. Export JSON, a chained `winget install` one-liner, or a PowerShell script.
Drafts stay in `localStorage` only. This is **not** [WinGet Configuration](https://learn.microsoft.com/en-us/windows/package-manager/configuration/) (`winget configure` YAML) — that format is not supported yet.
## Data Lifecycle
- **Source-controlled** -- Site code, styles, scripts.
- **Bare repo cache** -- `src/data/winget-pkgs.git` is a shallow bare clone created during setup and kept on the CI runner's persistent volume (git-ignored).
- **Generated** -- everything else under `src/data/` (the `packages/` and `packages-by-letter/` JSON, `search-index.json`, `package-versions.json`, the aggregated `*.json` indexes, `.hashes.json`, `.last-commit`, `.last-deploy-commit`, and `stats.db*`) is produced by ingest/build workflows and kept on the persistent volume. The stats database is also uploaded as a release asset after every deploy.
- **Stats snapshot** -- after a successful deploy, `stats.db` is checkpointed, vacuumed, gzipped, and uploaded as `stats.db.gz` to the Forgejo `stats` release. Deploy and CI restore the latest release asset before building. Stats blobs never enter the Git repository.
## Deployment
Deployed to Cloudflare Pages via Direct Upload. Forgejo Actions workflows run on a self-hosted Forgejo Runner with the `docker` label and a persistent data volume:
- Host directory: `/srv/pkgs-win-ci`
- Container mount: `/cache/pkgs-win`
- Stored state: `src/data` (bare winget repository, generated packages, indexes, stats) and the pnpm store
Create the host directory and allow it in the runner configuration:
```sh
sudo mkdir -p /srv/pkgs-win-ci
```
```yaml
container:
valid_volumes:
- /srv/pkgs-win-ci
```
Workflows:
- **`.forgejo/workflows/ci.yml`** -- runs on `push`, `pull_request`, and manual dispatch
- Installs dependencies from the persistent pnpm store
- Runs tests and `astro check`
- Updates the bare winget repo and validates ingest in dry-run mode
- Does not write package data, hashes, last-commit markers, or stats
- Restores the latest stats snapshot only when the cached stats database is missing
- Builds the site from the existing cached package data
- **`.forgejo/workflows/deploy.yml`** -- runs hourly and on manual dispatch
- Updates the bare winget repository
- Compares the upstream head with `src/data/.last-deploy-commit`
- Skips build and deploy when there are no manifest changes
- Manual dispatch always forces a deployment
- Restores the latest stats snapshot from the Forgejo release asset
- Deploys `dist/` with `wrangler pages deploy`
- Uploads the updated stats snapshot to the `stats` release
- **`.forgejo/workflows/maintenance.yml`** -- runs weekly and on manual dispatch
- Prunes the persistent pnpm store
- Compacts the bare winget repository
All workflows share the `pkgs-win-data` concurrency group so CI and deployment never write the volume at the same time.
Required repository secrets: `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID`, `POSTHOG_KEY`, and `STATS_TOKEN`.
`STATS_TOKEN` must be an access token with `write:repository` scope. The automatic `FORGEJO_TOKEN` supplied by Forgejo Actions can read release metadata, but it cannot download release attachments or write release assets because the synthetic action user has no repository permission on those routes.
## Stats Persistence
The SQLite stats database remains the working copy on the persistent volume. After every successful deploy, the deploy workflow:
1. Runs `PRAGMA wal_checkpoint(TRUNCATE)` and `VACUUM`.
2. Gzips the database to `stats.db.gz` (currently about 5–7 MB).
3. Replaces the `stats.db.gz` asset on the Forgejo `stats` release.
Deploy restores the latest release asset into the persistent data directory before every run. CI only restores it when the cached stats database is missing, so it never rewrites stats during a normal run. This keeps the complete stats history available even if the runner volume is recreated.
Stats snapshots are not committed to Git, so the main history and Git storage do not grow with each deploy. Release assets are versioned separately and only the latest snapshot is kept.
CI never creates new stats entries. It runs a dry ingest and builds from the existing package data.
## Troubleshooting
- **`src/data/winget-pkgs.git` missing**: run `pnpm setup` to initialize the bare clone.
- **Ingest appears stale**: rerun `pnpm ingest` and ensure the bare repo is up to date.
- **Letter pages show no packages** (`/packages/t` empty): the `packages-by-letter/*.json` auxiliary files are only generated during ingest. Run `pnpm ingest` locally first.
- **Package-list version dropdowns empty**: `/package-versions.json` is generated during ingest. Run `pnpm ingest` locally first.
- **Build fails after ingest changes**: run `pnpm build:site` locally to validate the Astro output before CI runs.
- **`node_modules` issues in CI**: the project keeps `nodeLinker: hoisted` configured in `pnpm-workspace.yaml` for reliable dependency layouts inside containerized Forgejo Actions jobs.
## Tech Stack
- **Astro 7** -- static site generator
- **MiniSearch** -- client-side full-text search
- **View Transitions API** -- smooth page navigation
- **Cloudflare Pages** -- hosting (Direct Upload)
- **Self-hosted Forgejo + Forgejo Runner** -- source control and CI/CD
- **@astrojs/sitemap** -- auto-generated sitemap
- **@pierre/trees** -- searchable source-code tree on `/source`
- **Shiki** -- syntax highlighting for the source explorer
- **tsx** -- TypeScript execution for the ingest script