|
| 1 | +# Schema Package Publishing |
| 2 | + |
| 3 | +This document explains how to publish the `@runtimed/schema` package to both npm and JSR. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `@runtimed/schema` package is published to two registries: |
| 8 | +- **npm**: https://www.npmjs.com/package/@runtimed/schema |
| 9 | +- **JSR**: https://jsr.io/@runtimed/schema |
| 10 | + |
| 11 | +Both registries are kept in sync with matching version numbers. |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +### For Automated Publishing (GitHub Actions) |
| 16 | + |
| 17 | +1. **NPM_TOKEN**: npm access token with publish permissions |
| 18 | + - Generate at: https://www.npmjs.com/settings/tokens |
| 19 | + - Add to GitHub repository secrets |
| 20 | + |
| 21 | +2. **JSR_TOKEN**: JSR access token with publish permissions |
| 22 | + - Generate at: https://jsr.io/account/tokens |
| 23 | + - Add to GitHub repository secrets |
| 24 | + |
| 25 | +### For Manual Publishing |
| 26 | + |
| 27 | +1. **npm**: Authenticated with `npm login` |
| 28 | +2. **JSR**: JSR CLI installed (`npm install -g jsr`) |
| 29 | + |
| 30 | +## Automated Publishing (Recommended) |
| 31 | + |
| 32 | +Publishing is automated via GitHub Actions when you push a git tag: |
| 33 | + |
| 34 | +### 1. Update Version |
| 35 | + |
| 36 | +Use the provided script to update both `package.json` and `jsr.json`: |
| 37 | + |
| 38 | +```bash |
| 39 | +# Bump to a new version (e.g., 0.1.3) |
| 40 | +pnpm bump-schema 0.1.3 |
| 41 | +``` |
| 42 | + |
| 43 | +This script: |
| 44 | +- Updates version in both `package.json` and `jsr.json` |
| 45 | +- Validates version format |
| 46 | +- Stages changes for git commit |
| 47 | + |
| 48 | +### 2. Test Locally |
| 49 | + |
| 50 | +Before publishing, test that everything works: |
| 51 | + |
| 52 | +```bash |
| 53 | +pnpm test-publish |
| 54 | +``` |
| 55 | + |
| 56 | +This runs: |
| 57 | +- Version consistency check |
| 58 | +- Type checking |
| 59 | +- Linting |
| 60 | +- Format checking |
| 61 | +- Dry run publishing to both registries |
| 62 | + |
| 63 | +### 3. Commit and Tag |
| 64 | + |
| 65 | +```bash |
| 66 | +git commit -m "Bump schema version to v0.1.3" |
| 67 | +git tag v0.1.3 |
| 68 | +git push origin HEAD --tags |
| 69 | +``` |
| 70 | + |
| 71 | +### 4. GitHub Actions Takes Over |
| 72 | + |
| 73 | +The workflow (`.github/workflows/publish.yml`) automatically: |
| 74 | +1. Validates version consistency |
| 75 | +2. Runs all checks (type, lint, format) |
| 76 | +3. Tests dry run publishing |
| 77 | +4. Publishes to npm |
| 78 | +5. Publishes to JSR |
| 79 | +6. Creates GitHub release |
| 80 | + |
| 81 | +## Manual Publishing |
| 82 | + |
| 83 | +If you need to publish manually: |
| 84 | + |
| 85 | +### 1. Prepare and Test |
| 86 | + |
| 87 | +```bash |
| 88 | +# Update versions |
| 89 | +pnpm bump-schema 0.1.3 |
| 90 | + |
| 91 | +# Test everything |
| 92 | +pnpm test-publish |
| 93 | +``` |
| 94 | + |
| 95 | +### 2. Publish to npm |
| 96 | + |
| 97 | +```bash |
| 98 | +pnpm --filter schema publish --access public --no-git-checks |
| 99 | +``` |
| 100 | + |
| 101 | +### 3. Publish to JSR |
| 102 | + |
| 103 | +```bash |
| 104 | +pnpm --filter schema exec jsr publish --allow-slow-types |
| 105 | +``` |
| 106 | + |
| 107 | +## Workflow Details |
| 108 | + |
| 109 | +### Version Management |
| 110 | + |
| 111 | +- Both `package.json` and `jsr.json` must have matching version numbers |
| 112 | +- Use semantic versioning (e.g., `0.1.3`, `1.0.0`, `2.1.0-beta.1`) |
| 113 | +- The `bump-schema` script ensures consistency |
| 114 | + |
| 115 | +### Validation Steps |
| 116 | + |
| 117 | +The publishing process includes several validation steps: |
| 118 | + |
| 119 | +1. **Version Consistency**: Both files have matching versions |
| 120 | +2. **Tag Validation**: Git tag matches package version |
| 121 | +3. **Type Check**: TypeScript compilation without errors |
| 122 | +4. **Lint Check**: ESLint passes with no warnings |
| 123 | +5. **Format Check**: Prettier formatting is correct |
| 124 | +6. **Publish Dry Run**: Both registries accept the package |
| 125 | + |
| 126 | +### Publishing Strategy |
| 127 | + |
| 128 | +- **Tags trigger publishing**: Only git tags starting with `v` trigger the workflow |
| 129 | +- **Both registries**: Package is published to npm and JSR simultaneously |
| 130 | +- **Failure handling**: If either registry fails, the workflow stops |
| 131 | +- **GitHub Release**: Automatically created with links to both registries |
| 132 | + |
| 133 | +## Troubleshooting |
| 134 | + |
| 135 | +### Version Mismatch |
| 136 | + |
| 137 | +```bash |
| 138 | +❌ Version mismatch: package.json (0.1.2) != jsr.json (0.1.1) |
| 139 | +``` |
| 140 | + |
| 141 | +**Solution**: Use `pnpm bump-schema <version>` to sync versions. |
| 142 | + |
| 143 | +### JSR Slow Types Warning |
| 144 | + |
| 145 | +``` |
| 146 | +Warning Publishing a library with slow types is not recommended. |
| 147 | +``` |
| 148 | + |
| 149 | +This is expected. The schema package uses complex TypeScript types that JSR considers "slow types". We use `--allow-slow-types` to publish anyway. |
| 150 | + |
| 151 | +### npm Authentication |
| 152 | + |
| 153 | +```bash |
| 154 | +npm error code ENEEDAUTH |
| 155 | +``` |
| 156 | + |
| 157 | +**Solution**: Run `npm login` or ensure `NPM_TOKEN` is set correctly. |
| 158 | + |
| 159 | +### JSR Authentication |
| 160 | + |
| 161 | +```bash |
| 162 | +error: Unauthorized |
| 163 | +``` |
| 164 | + |
| 165 | +**Solution**: Ensure `JSR_TOKEN` is set correctly in GitHub secrets or run `jsr auth` for manual publishing. |
| 166 | + |
| 167 | +### Git Tag Issues |
| 168 | + |
| 169 | +```bash |
| 170 | +❌ Tag version (0.1.3) doesn't match package version (0.1.2) |
| 171 | +``` |
| 172 | +
|
| 173 | +**Solution**: Ensure you've committed the version bump before tagging, or update the tag to match the package version. |
| 174 | + |
| 175 | +## Scripts Reference |
| 176 | + |
| 177 | +| Script | Command | Purpose | |
| 178 | +|--------|---------|---------| |
| 179 | +| Version Bump | `pnpm bump-schema <version>` | Update package versions consistently | |
| 180 | +| Test Publish | `pnpm test-publish` | Validate everything before publishing | |
| 181 | +| Manual npm | `pnpm --filter schema publish --access public` | Publish to npm only | |
| 182 | +| Manual JSR | `pnpm --filter schema exec jsr publish --allow-slow-types` | Publish to JSR only | |
| 183 | + |
| 184 | +## Package Structure |
| 185 | + |
| 186 | +``` |
| 187 | +packages/schema/ |
| 188 | +├── package.json # npm package configuration |
| 189 | +├── jsr.json # JSR package configuration |
| 190 | +├── README.md # Package documentation |
| 191 | +├── src/ |
| 192 | +│ ├── index.ts # Main export |
| 193 | +│ ├── tables.ts # Database schema |
| 194 | +│ ├── types.ts # TypeScript types |
| 195 | +│ └── queries/ # Query helpers |
| 196 | +└── tsconfig.json # TypeScript configuration |
| 197 | +``` |
| 198 | +
|
| 199 | +## Release Checklist |
| 200 | +
|
| 201 | +- [ ] Version numbers match in `package.json` and `jsr.json` |
| 202 | +- [ ] `pnpm test-publish` passes all checks |
| 203 | +- [ ] Changes committed to git |
| 204 | +- [ ] Git tag created and pushed |
| 205 | +- [ ] GitHub Actions workflow completes successfully |
| 206 | +- [ ] Both npm and JSR packages are live |
| 207 | +- [ ] GitHub release is created |
| 208 | +
|
| 209 | +## Support |
| 210 | +
|
| 211 | +For issues with the publishing process: |
| 212 | +1. Check GitHub Actions logs for detailed error messages |
| 213 | +2. Test locally with `pnpm test-publish` |
| 214 | +3. Verify authentication tokens are valid |
| 215 | +4. Ensure version numbers are consistent |
0 commit comments