|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This is an Octoherd script that queries GitHub repositories to check if a specific npm library meets a version requirement. It's used to drive Renovate's major library update process by identifying repositories that need dependency updates. |
| 8 | + |
| 9 | +The script: |
| 10 | +1. Fetches lockfiles (pnpm-lock.yaml or yarn.lock) from repositories |
| 11 | +2. Extracts version information for a specified library |
| 12 | +3. Checks if the version satisfies a semver requirement |
| 13 | +4. Reports compliance status |
| 14 | + |
| 15 | +## Key Commands |
| 16 | + |
| 17 | +### Running the Script |
| 18 | + |
| 19 | +```bash |
| 20 | +# Use the appropriate Node version |
| 21 | +nvm use |
| 22 | + |
| 23 | +# Run the script with options |
| 24 | +node cli.js \ |
| 25 | + -R time-loop/\*-cdk \ |
| 26 | + -T ghp_YOUR_TOKEN \ |
| 27 | + --octoherd-bypass-confirms true \ |
| 28 | + --library @time-loop/cdk-ecs-fargate \ |
| 29 | + --versionRequirement \>=5.15.2 | \ |
| 30 | +tee raw.txt | grep NOT | sort | tee non-compliant.txt && wc -l non-compliant.txt |
| 31 | +``` |
| 32 | + |
| 33 | +### Testing |
| 34 | + |
| 35 | +```bash |
| 36 | +pnpm test # Runs the script directly |
| 37 | +``` |
| 38 | + |
| 39 | +### Package Management |
| 40 | + |
| 41 | +This repository uses **pnpm** - respect this choice and use `pnpm` commands, not `npm` or `yarn`. |
| 42 | + |
| 43 | +```bash |
| 44 | +pnpm install # Install dependencies |
| 45 | +``` |
| 46 | + |
| 47 | +## Architecture |
| 48 | + |
| 49 | +### Core Components |
| 50 | + |
| 51 | +**script.js** - Main octoherd script logic |
| 52 | +- `script()` function is the entry point called by octoherd-cli for each repository |
| 53 | +- Parameters: `octokit` (GitHub API client), `repository` (repo metadata), `options` (CLI flags) |
| 54 | +- Required options: |
| 55 | + - `--versionRequirement`: semver range (e.g., `>=5.15.2`, `^12`) |
| 56 | + - `--library`: npm package name to check (default: `@time-loop/cdk-library`) |
| 57 | + - `--reduce`: optional `min` or `max` to reduce multiple versions to single value |
| 58 | + |
| 59 | +**cli.js** - Simple wrapper that imports and runs the script via octoherd's CLI |
| 60 | + |
| 61 | +### Lockfile Parsing Strategy |
| 62 | + |
| 63 | +The script tries lockfiles in order: |
| 64 | +1. **pnpm-lock.yaml** (parsed with `yaml` package) |
| 65 | + - Dependency format: `/packageName@version(peer-deps)` |
| 66 | + - Regex: `/^(?<packageName>(@[^\/]+\/)?[^@]+)@(?<version>[0-9]+\.[0-9]+\.[0-9]+).*/` |
| 67 | +2. **yarn.lock** (parsed with `@yarnpkg/lockfile`) |
| 68 | + - Key format: `packageName@versionRange` |
| 69 | + - Extracts version from nested `version` field |
| 70 | + |
| 71 | +### Version Reduction |
| 72 | + |
| 73 | +When `--reduce` is specified: |
| 74 | +- `min`: Returns smallest version using semver comparison |
| 75 | +- `max`: Returns largest version using semver comparison |
| 76 | +- Useful when a repo has multiple versions of the same library |
| 77 | + |
| 78 | +### Output Format |
| 79 | + |
| 80 | +- **INFO log**: Version satisfies requirement |
| 81 | +- **WARN log**: Version does NOT satisfy requirement (these are filtered with `grep NOT`) |
| 82 | +- **DEBUG log**: Repository skipped or processing details |
| 83 | + |
| 84 | +## Development Notes |
| 85 | + |
| 86 | +- Node.js version: 22.14.0 (specified in .nvmrc, but package.json requires `>= 18.17.1`) |
| 87 | +- Uses ES modules (`"type": "module"` in package.json) |
| 88 | +- TypeScript checking via JSDoc comments (`// @ts-check`) |
| 89 | +- Skips archived repositories automatically |
| 90 | +- Uses pnpm lockfile format version 9.0 |
| 91 | + |
| 92 | +## Limitations (from README) |
| 93 | + |
| 94 | +- Written in JavaScript instead of TypeScript (time constraints) |
| 95 | +- Not projen-ified |
| 96 | +- Not published to npmjs.com (runs locally only) |
0 commit comments