Prepare and publish npm package
✓Works with OpenClaudeYou are an npm package maintainer. The user wants to prepare a local npm package and publish it to the npm registry.
What to check first
- Run
npm whoamito verify you're logged into npm registry - Check
package.jsonexists and hasname,version, anddescriptionfields - Run
npm listto ensure all dependencies are installed - Verify
.npmignoreorfilesfield inpackage.jsonto control what gets published
Steps
- Update the
versionfield inpackage.jsonusing semantic versioning (e.g.,1.0.0,1.2.3) - Run
npm testto ensure all tests pass before publishing - Run
npm run buildif your package has a build step (checkscripts.buildinpackage.json) - Run
npm packto create a tarball and preview exactly what will be published - Review the tarball contents with
tar -tzf <package-name>-<version>.tgzto confirm no sensitive files are included - Run
npm publishto push the package to the npm registry - Verify publication with
npm view <package-name>@<version>to confirm the version exists on npm - Create a git tag matching the version:
git tag v<version>and push withgit push --tags
Code
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
function publishPackage() {
const packageJsonPath = path.join(process.cwd(), 'package.json');
// Read current package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
console.log(`📦 Current version: ${packageJson.version}`);
// Verify npm login
try {
execSync('npm whoami', { stdio: 'inherit' });
} catch (error) {
console.error('❌ Not logged into npm. Run: npm login');
process.exit(1);
}
// Run tests
console.log('\n🧪 Running tests...');
try {
execSync('npm test', { stdio: 'inherit' });
} catch (error) {
console.error('❌ Tests failed. Fix issues before publishing.');
process.exit(1);
}
// Run build if script exists
if (packageJson.scripts && packageJson.scripts.build) {
console.log('\n🔨 Building package...');
try {
execSync('npm run build', { stdio: 'inherit' });
} catch (error) {
console.error('❌ Build failed.');
process.exit(1);
}
}
// Create tarball preview
console.log('\n📋 Creating preview tar
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related General / Utility Skills
Other Claude Code skills in the same category — free to download.
Env Setup
Set up development environment from scratch
Gitignore Generator
Generate .gitignore for any project type
Error Boundary
Create error boundary components
Feature Flag
Implement feature flag system
Config Manager
Create application configuration manager
Date Time Helper
Create date/time utility functions
String Utils
Create string manipulation utilities
File Utils
Create file system utility functions
Want a General / Utility skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.