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