This guide walks you through publishing @wasmworker/sdk to npm.
- npm Account: Create an account at npmjs.com
- npm CLI: Ensure npm is installed (comes with Node.js)
- Authentication: Log in to npm via CLI
npm login
# Enter your username, password, and emailVerify you're logged in:
npm whoamiIf you want to publish under @wasmworker scope, you need to:
- Create an organization at npmjs.com/org/create
- Name it
wasmworker - Invite collaborators if needed
Alternative: Publish without a scope by changing the package name from @wasmworker/sdk to wasmworker-sdk in package.json.
Before publishing, ensure:
- All tests pass:
pnpm test - Code builds successfully:
pnpm build - Version number is updated in
packages/sdk/package.json - README.md is up to date
- LICENSE file exists
- Repository URL is correct in package.json
- Author information is correct
cd packages/sdkPreview what will be published:
npm pack --dry-runThis shows all files that will be included. Verify that:
dist/folder is includedREADME.mdis includedLICENSEis included- Source files (
src/,tests/) are NOT included
Update the version in package.json following semantic versioning:
- Patch (0.1.0 → 0.1.1): Bug fixes
- Minor (0.1.0 → 0.2.0): New features, backward compatible
- Major (0.1.0 → 1.0.0): Breaking changes
# Option 1: Manual edit
# Edit packages/sdk/package.json and change "version": "0.1.0"
# Option 2: Use npm version command
npm version patch # for 0.1.0 -> 0.1.1
npm version minor # for 0.1.0 -> 0.2.0
npm version major # for 0.1.0 -> 1.0.0The prepublishOnly script will automatically run, but you can test manually:
pnpm run clean
pnpm run build
pnpm run testFor first-time publish with scoped package:
npm publish --access publicFor subsequent publishes:
npm publishCheck your package on npm:
# View package info
npm view @wasmworker/sdk
# Or visit
# https://www.npmjs.com/package/@wasmworker/sdkcd ../.. # back to repo root
git tag v0.1.0
git push origin v0.1.0After publishing, test installation in a fresh project:
mkdir test-wasmworker
cd test-wasmworker
npm init -y
npm install @wasmworker/sdk
# Verify it installs correctly
node -e "console.log(require('@wasmworker/sdk'))"For pre-release versions:
# Update version to something like "0.2.0-beta.1"
npm version 0.2.0-beta.1
# Publish with beta tag
npm publish --tag betaUsers can install with:
npm install @wasmworker/sdk@betaYou can unpublish within 72 hours of publishing:
npm unpublish @wasmworker/sdk@0.1.0Warning: Unpublishing is discouraged and may be blocked for packages with high download counts.
Solution:
- Ensure you're logged in:
npm whoami - If using a scope (@wasmworker), ensure the organization exists
- Add
--access publicflag
Solution:
- You cannot republish the same version
- Increment the version number
- Use
npm version patch/minor/major
Solution:
- Choose a different package name
- Or use a scope:
@yourname/wasmworker
Solution:
- Check the
filesarray in package.json - Use
npm pack --dry-runto preview - Verify symlinks are working for README/LICENSE
Create .github/workflows/publish.yml:
name: Publish to npm
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v2
with:
version: 8
- run: pnpm install
- run: pnpm build
- run: pnpm test
- name: Publish to npm
run: |
cd packages/sdk
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}Then add your npm token to GitHub secrets:
- Create npm token:
npm token create - Add to GitHub: Settings → Secrets → New repository secret
- Name:
NPM_TOKEN, Value: your token
- Always test before publishing: Run
pnpm testandpnpm build - Use semantic versioning: Follow semver for version numbers
- Maintain a changelog: Document changes in CHANGELOG.md (or git tags)
- Tag releases: Create git tags for each published version
- Test installation: Install your package in a test project
- Use
.npmignore: Already configured in the SDK package - Monitor downloads: Check npm stats periodically
If you encounter issues:
- Check npm status
- Search npm support
- Ask in the npm community forums