Skip to main content

NPM Package Publishing Setup

This document explains how to set up automated NPM package publishing for the Supernal TTS family.

Overviewโ€‹

The project includes several publishable NPM packages:

  • supernal-tts-server - Production-ready TTS API server
  • supernal-tts-widget - Embeddable JavaScript widget
  • @supernal-tts/core - Core TTS functionality and providers
  • @supernal-tts/client - Client SDK for the TTS API
  • @supernal-tts/types - TypeScript type definitions
  • @supernal/api-usage-tracker - API usage tracking utilities

GitHub Secrets Setupโ€‹

1. Create NPM Access Tokenโ€‹

  1. Log in to npmjs.com
  2. Go to your profile โ†’ Access Tokens
  3. Click "Generate New Token"
  4. Choose "Automation" token type (for CI/CD)
  5. Copy the generated token

2. Add NPM_TOKEN to GitHub Secretsโ€‹

  1. Go to your GitHub repository
  2. Navigate to Settings โ†’ Secrets and variables โ†’ Actions
  3. Click "New repository secret"
  4. Name: NPM_TOKEN
  5. Value: Paste your NPM access token
  6. Click "Add secret"

Publishing Workflowโ€‹

The project uses GitHub Actions to automatically publish packages when you create a version tag:

# Create and push a version tag
./scripts/release.sh 1.2.3

# For pre-release versions
./scripts/release.sh 1.2.3-beta.1

# Dry run to test
./scripts/release.sh 1.2.3 --dry-run

Manual Publishingโ€‹

You can also trigger publishing manually:

  1. Go to GitHub Actions โ†’ "Publish NPM Packages"
  2. Click "Run workflow"
  3. Optionally specify a version or enable dry-run mode

Package Publishing Detailsโ€‹

Change Detectionโ€‹

The workflow automatically detects which packages have changed and only publishes those packages. This prevents unnecessary publishes and version bumps.

Version Managementโ€‹

  • Tagged releases: The version is extracted from the git tag (e.g., v1.2.3 โ†’ 1.2.3)
  • Manual workflow: You can specify a version in the workflow dispatch
  • Default: Uses the version in each package's package.json

Publishing Orderโ€‹

Packages are published in dependency order:

  1. @supernal-tts/types (base types)
  2. @supernal-tts/core (depends on types)
  3. @supernal-tts/client (depends on types)
  4. @supernal/api-usage-tracker (independent)
  5. supernal-tts-server (independent)
  6. supernal-tts-widget (independent)

Access Controlโ€‹

All packages are published with --access public to ensure they're publicly available on NPM.

Release Processโ€‹

1. Prepare Releaseโ€‹

# Ensure you're on main branch
git checkout main
git pull origin main

# Run tests
npm test

# Build packages
npm run build:packages

2. Create Releaseโ€‹

# Use the release script (recommended)
./scripts/release.sh 1.2.3

# Or manually create tag
git tag v1.2.3
git push origin v1.2.3

3. Monitor Publishingโ€‹

  1. Check GitHub Actions workflow: https://github.com/your-org/supernal-tts/actions
  2. Verify packages on NPM:

Troubleshootingโ€‹

Publishing Failsโ€‹

  1. NPM Token Issues:

    • Verify NPM_TOKEN secret is set correctly
    • Ensure token has publishing permissions
    • Check token hasn't expired
  2. Version Conflicts:

    • Ensure version doesn't already exist on NPM
    • Use semantic versioning format (x.y.z)
  3. Build Failures:

    • Check TypeScript compilation errors
    • Verify all dependencies are installed
    • Ensure tests pass

Package Not Publishingโ€‹

  1. No Changes Detected:

    • The workflow only publishes packages with changes
    • Use manual workflow dispatch to force publishing
  2. Dependency Issues:

    • Ensure workspace dependencies are properly configured
    • Check that built packages exist in dist/ directories

Package Configurationโ€‹

Each package includes:

  • Repository URL: Points to the monorepo with directory specification
  • Publishing Config: "access": "public" for public packages
  • Files Array: Specifies which files to include in the published package
  • Proper Metadata: Description, keywords, author, license

Security Notesโ€‹

  • NPM tokens are stored as GitHub secrets and never exposed in logs
  • Packages are published with public access
  • All packages include proper repository and bug tracking URLs
  • License information is included in all packages