|
| 1 | +# Publishing Guide for slskd-client |
| 2 | + |
| 3 | +This guide explains how to publish the `slskd-client` package to npm. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. **npm account**: Create one at [npmjs.com](https://www.npmjs.com/signup) |
| 8 | +2. **npm CLI login**: Run `npm login` in your terminal |
| 9 | +3. **Git repository**: Push your code to GitHub first |
| 10 | + |
| 11 | +## Pre-Publishing Checklist |
| 12 | + |
| 13 | +### 1. Update package.json |
| 14 | + |
| 15 | +Replace the placeholder URLs with your actual GitHub repository: |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "repository": { |
| 20 | + "type": "git", |
| 21 | + "url": "https://github.com/YOUR_USERNAME/slskd-client.git" |
| 22 | + }, |
| 23 | + "bugs": { |
| 24 | + "url": "https://github.com/YOUR_USERNAME/slskd-client/issues" |
| 25 | + }, |
| 26 | + "homepage": "https://github.com/YOUR_USERNAME/slskd-client#readme" |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Verify package name availability |
| 31 | + |
| 32 | +Check if the name `slskd-client` is available: |
| 33 | + |
| 34 | +```bash |
| 35 | +npm view slskd-client |
| 36 | +``` |
| 37 | + |
| 38 | +If the package exists, you'll need to either: |
| 39 | + |
| 40 | +- Use a scoped package: `@your-username/slskd-client` |
| 41 | +- Choose a different name |
| 42 | + |
| 43 | +To use a scoped package, update `package.json`: |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "name": "@your-username/slskd-client" |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +### 3. Build and test locally |
| 52 | + |
| 53 | +```bash |
| 54 | +# Install dependencies |
| 55 | +npm install |
| 56 | + |
| 57 | +# Run all checks |
| 58 | +npm run typecheck |
| 59 | +npm run lint |
| 60 | +npm run format:check |
| 61 | +npm run build |
| 62 | + |
| 63 | +# Verify the build output |
| 64 | +ls -la dist/ |
| 65 | +``` |
| 66 | + |
| 67 | +### 4. Test the package locally |
| 68 | + |
| 69 | +```bash |
| 70 | +# Create a test tarball |
| 71 | +npm pack |
| 72 | + |
| 73 | +# This creates a file like slskd-client-1.0.0.tgz |
| 74 | +# Install it in a test project: |
| 75 | +cd /path/to/test-project |
| 76 | +npm install /path/to/slskd-js-client/slskd-client-1.0.0.tgz |
| 77 | +``` |
| 78 | + |
| 79 | +## Publishing Steps |
| 80 | + |
| 81 | +### First-time Publishing |
| 82 | + |
| 83 | +1. **Login to npm**: |
| 84 | + |
| 85 | +```bash |
| 86 | +npm login |
| 87 | +``` |
| 88 | + |
| 89 | +2. **Verify you're logged in**: |
| 90 | + |
| 91 | +```bash |
| 92 | +npm whoami |
| 93 | +``` |
| 94 | + |
| 95 | +3. **Publish the package**: |
| 96 | + |
| 97 | +```bash |
| 98 | +# For public package (free) |
| 99 | +npm publish --access public |
| 100 | + |
| 101 | +# For scoped package |
| 102 | +npm publish --access public |
| 103 | +``` |
| 104 | + |
| 105 | +### Subsequent Updates |
| 106 | + |
| 107 | +1. **Update the version** in `package.json`: |
| 108 | + |
| 109 | +```bash |
| 110 | +# Patch version (1.0.0 -> 1.0.1) |
| 111 | +npm version patch |
| 112 | + |
| 113 | +# Minor version (1.0.0 -> 1.1.0) |
| 114 | +npm version minor |
| 115 | + |
| 116 | +# Major version (1.0.0 -> 2.0.0) |
| 117 | +npm version major |
| 118 | +``` |
| 119 | + |
| 120 | +This will: |
| 121 | + |
| 122 | +- Update `package.json` |
| 123 | +- Create a git tag |
| 124 | +- Commit the changes |
| 125 | + |
| 126 | +2. **Push the changes**: |
| 127 | + |
| 128 | +```bash |
| 129 | +git push origin main --tags |
| 130 | +``` |
| 131 | + |
| 132 | +3. **Publish**: |
| 133 | + |
| 134 | +```bash |
| 135 | +npm publish |
| 136 | +``` |
| 137 | + |
| 138 | +## Automated Publishing with GitHub Actions (Optional) |
| 139 | + |
| 140 | +Create `.github/workflows/publish.yml`: |
| 141 | + |
| 142 | +```yaml |
| 143 | +name: Publish to npm |
| 144 | + |
| 145 | +on: |
| 146 | + release: |
| 147 | + types: [created] |
| 148 | + |
| 149 | +jobs: |
| 150 | + publish: |
| 151 | + runs-on: ubuntu-latest |
| 152 | + steps: |
| 153 | + - uses: actions/checkout@v4 |
| 154 | + |
| 155 | + - name: Setup Node.js |
| 156 | + uses: actions/setup-node@v4 |
| 157 | + with: |
| 158 | + node-version: '18.x' |
| 159 | + registry-url: 'https://registry.npmjs.org' |
| 160 | + |
| 161 | + - name: Install dependencies |
| 162 | + run: npm install |
| 163 | + |
| 164 | + - name: Run checks |
| 165 | + run: | |
| 166 | + npm run typecheck |
| 167 | + npm run lint |
| 168 | + npm run format:check |
| 169 | +
|
| 170 | + - name: Build |
| 171 | + run: npm run build |
| 172 | + |
| 173 | + - name: Publish |
| 174 | + run: npm publish --access public |
| 175 | + env: |
| 176 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 177 | +``` |
| 178 | +
|
| 179 | +To use this: |
| 180 | +
|
| 181 | +1. Generate an npm access token at [npmjs.com/settings/tokens](https://www.npmjs.com/settings/tokens) |
| 182 | +2. Add it as a secret `NPM_TOKEN` in your GitHub repository settings |
| 183 | +3. Create a GitHub release, and the package will be published automatically |
| 184 | + |
| 185 | +## What Gets Published |
| 186 | + |
| 187 | +The `files` field in `package.json` controls what's included: |
| 188 | + |
| 189 | +```json |
| 190 | +{ |
| 191 | + "files": ["dist", "README.md", "LICENSE"] |
| 192 | +} |
| 193 | +``` |
| 194 | + |
| 195 | +Everything else is excluded via `.npmignore`. |
| 196 | + |
| 197 | +## Verify Publication |
| 198 | + |
| 199 | +After publishing, check: |
| 200 | + |
| 201 | +1. **npm registry**: Visit `https://www.npmjs.com/package/slskd-client` |
| 202 | +2. **Install test**: |
| 203 | + |
| 204 | +```bash |
| 205 | +npm install slskd-client |
| 206 | +``` |
| 207 | + |
| 208 | +## Unpublishing (Emergency Only) |
| 209 | + |
| 210 | +If you need to unpublish within 72 hours: |
| 211 | + |
| 212 | +```bash |
| 213 | +npm unpublish slskd-client@1.0.0 |
| 214 | +``` |
| 215 | + |
| 216 | +⚠️ **Warning**: Unpublishing is permanent and not recommended. Consider deprecating instead: |
| 217 | + |
| 218 | +```bash |
| 219 | +npm deprecate slskd-client@1.0.0 "This version has critical bugs, use 1.0.1+" |
| 220 | +``` |
| 221 | + |
| 222 | +## Common Issues |
| 223 | + |
| 224 | +### "You do not have permission to publish" |
| 225 | + |
| 226 | +- Check if the package name is already taken |
| 227 | +- Use a scoped package: `@username/slskd-client` |
| 228 | +- Verify you're logged in: `npm whoami` |
| 229 | + |
| 230 | +### "Package name too similar to existing package" |
| 231 | + |
| 232 | +- Choose a more unique name |
| 233 | +- Use a scoped package |
| 234 | + |
| 235 | +### "No README data" |
| 236 | + |
| 237 | +- Ensure `README.md` is in the `files` array in `package.json` |
| 238 | + |
| 239 | +## Post-Publishing |
| 240 | + |
| 241 | +1. **Add badges to README**: |
| 242 | + |
| 243 | +```markdown |
| 244 | +[](https://www.npmjs.com/package/slskd-client) |
| 245 | +[](https://www.npmjs.com/package/slskd-client) |
| 246 | +``` |
| 247 | + |
| 248 | +2. **Update CHANGELOG.md** for each release |
| 249 | + |
| 250 | +3. **Monitor issues** on GitHub and npm |
| 251 | + |
| 252 | +## Quick Reference |
| 253 | + |
| 254 | +```bash |
| 255 | +# Check current version |
| 256 | +npm version |
| 257 | +
|
| 258 | +# Login |
| 259 | +npm login |
| 260 | +
|
| 261 | +# Test build |
| 262 | +npm run build && npm pack |
| 263 | +
|
| 264 | +# Publish (patch update) |
| 265 | +npm version patch |
| 266 | +git push origin main --tags |
| 267 | +npm publish |
| 268 | +
|
| 269 | +# Check publication |
| 270 | +npm view slskd-client |
| 271 | +``` |
| 272 | + |
| 273 | +## Resources |
| 274 | + |
| 275 | +- [npm Documentation](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry) |
| 276 | +- [npm Publishing Guide](https://docs.npmjs.com/cli/v10/commands/npm-publish) |
| 277 | +- [Semantic Versioning](https://semver.org/) |
0 commit comments