Skip to content

yeasin2002/npm-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

65 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NPM Starter

A production-ready starter template for creating modern NPM packages with TypeScript, featuring comprehensive tooling for testing, formatting, type-checking, and automated releases.

CI License: MIT

⭐ Show Your Support

Give a ⭐️ if this project helped you build better NPM packages!

✨ Features

Build & Type System

  • πŸ“¦ TypeScript 5.9+ - Proper TypeScript support
  • ⚑ tsdown - Rust based Lightning-fast builds
  • πŸ” Export Validation - Ensure package exports work correctly with @arethetypeswrong/cli
  • πŸ“š Dual Module Format - Full CommonJS and ESM support for maximum compatibility

Testing & Quality

  • πŸ§ͺ Vitest
  • 🎨 Prettier - Consistent code formatting with all necessary rules
  • πŸ”§ ESLint - TypeScript-aware linting with type-checked rules
  • πŸ“ size-limit - Monitor and control bundle size

Automation & Workflow

  • πŸͺ Husky + lint-staged - Pre-commit hooks for automatic formatting and linting
  • βœ… Commitlint - Enforce conventional commits for better changelogs
  • πŸ“ Changesets - Automated version management and changelog generation
  • πŸ€– GitHub Actions - Complete CI/CD pipeline for testing and releases
  • πŸ”„ Dependabot - Weekly automated dependency updates with proper grouping

Documentation & Developer Experience

  • πŸ“– TypeDoc - Auto-generated API documentation from JSDoc comments
  • πŸ› VS Code Integration - Debug configurations and recommended extensions
  • πŸ”’ Security Audits - Automated dependency scanning

πŸš€ Quick Start

Installation

# Clone this repository
git clone https://github.com/yeasin2002/npm-starter.git

# Navigate to the directory
cd npm-starter

# Install dependencies (supports npm, yarn, pnpm, or bun)
pnpm install

Development

# Run tests in watch mode
pnpm run dev

# Build the package
pnpm run build

# Run type checking
pnpm run lint

# Run tests
pnpm run test

πŸ“‹ Available Scripts

Development

Script Description
pnpm run dev Run tests in watch mode
pnpm run build Build the package (CJS + ESM + types)
pnpm run clean Remove build artifacts and caches
pnpm run typecheck Run TypeScript type checking
pnpm run typecheck:watch Run type checking in watch mode

Testing

Script Description
pnpm run test Run all tests once
pnpm run test:watch Run tests in watch mode
pnpm run test:coverage Run tests with coverage report

Code Quality

Script Description
pnpm run lint Run ESLint and TypeScript checks
pnpm run lint:fix Auto-fix linting issues
pnpm run format:write Format code with Prettier
pnpm run format:check Check code formatting
pnpm knip Declutter unused dependencies

Documentation

Script Description
pnpm run docs Generate API documentation
pnpm run docs:watch Generate docs in watch mode

Security & Size

Script Description
pnpm run audit Run security audit on dependencies
pnpm run size Check bundle size
pnpm run size:why Analyze bundle size with details

Release & CI

Script Description
pnpm run check-exports Validate package exports
pnpm run ci Run full CI pipeline
pnpm run local-release Version and publish locally
pnpm run release Publish to npm (used by CI)

πŸ“ Project Structure

npm-starter/
β”œβ”€β”€ .changeset/              # Changeset configuration and pending changes
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ workflows/
β”‚   β”‚   β”œβ”€β”€ ci.yml          # CI/CD pipeline
β”‚   β”‚   β”œβ”€β”€ release.yml     # Automated releases
β”‚   β”‚   └── security.yml    # Security audits
β”‚   └── dependabot.yml      # Dependency update configuration
β”œβ”€β”€ .husky/                  # Git hooks (pre-commit, commit-msg)
β”œβ”€β”€ .kiro/                   # Kiro AI assistant configuration
β”‚   └── steering/           # Project-specific AI guidance
β”œβ”€β”€ .vscode/                 # VS Code settings and debug configs
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts            # Main entry point (re-exports all public APIs)
β”‚   └── utils.ts            # Example utilities
β”œβ”€β”€ test/
β”‚   └── utils.test.ts       # Vitest test files
β”œβ”€β”€ dist/                    # Build output (generated, gitignored)
β”‚   β”œβ”€β”€ index.cjs           # CommonJS bundle
β”‚   β”œβ”€β”€ index.js            # ESM bundle
β”‚   └── index.d.ts          # TypeScript declarations
β”œβ”€β”€ docs/                    # Generated API documentation (gitignored)
β”œβ”€β”€ coverage/                # Test coverage reports (gitignored)
β”œβ”€β”€ package.json             # Package metadata and scripts
β”œβ”€β”€ tsconfig.json            # TypeScript compiler options
β”œβ”€β”€ tsdown.config.ts         # Build configuration
β”œβ”€β”€ vitest.config.ts         # Test configuration
β”œβ”€β”€ eslint.config.js         # Linting rules
β”œβ”€β”€ .prettierrc              # Code formatting rules
β”œβ”€β”€ .lintstagedrc.json       # Pre-commit hook configuration
β”œβ”€β”€ commitlint.config.js     # Commit message linting
└── README.md

πŸ“¦ Publishing

Using Changesets (Recommended)

# 1. Create a changeset
npx changeset

# 2. Version packages
pnpm run local-release

# The package will be automatically published when you push

Manual Publishing

# Build and verify
pnpm run ci

# Publish to npm
pnpm publish

Note: The prepublishOnly script ensures all checks pass before publishing.

πŸ› οΈ Customization

1. Update Package Metadata

Edit package.json:

{
  "name": "your-package-name",
  "version": "0.0.1",
  "description": "Your package description",
  "keywords": ["keyword1", "keyword2"],
  "author": "Your Name <your.email@example.com>",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/username/repo.git"
  },
  "homepage": "https://github.com/username/repo"
}

2. Customize Build & TypeScript

Build settings (tsdown.config.ts):

  • Add/remove output formats
  • Configure external dependencies
  • Adjust bundling options

TypeScript options (tsconfig.json):

  • Change target/lib versions
  • Adjust strictness levels
  • Modify path mappings

3. Configure Code Quality

ESLint (eslint.config.js):

  • Add custom rules
  • Configure type-checking behavior
  • Adjust ignore patterns

Prettier (.prettierrc):

  • Change formatting preferences
  • Adjust line width, quotes, semicolons

4. Add Dependencies

# Production dependencies (bundled with your package)
pnpm add package-name

# Development dependencies (build tools, testing)
pnpm add -D package-name

# Peer dependencies (required by consumers)
# Add to peerDependencies in package.json

πŸ”§ Troubleshooting

Build Issues

# Clean all build artifacts and caches
pnpm run clean

# Reinstall dependencies
rm -rf node_modules pnpm-lock.yaml
pnpm install

Type Errors

# Run type checking with detailed output
pnpm run typecheck

# Check for export issues
pnpm run check-exports

Test Failures

# Run tests with verbose output
pnpm run test -- --reporter=verbose

# Run specific test file
pnpm run test

πŸ“š Resources

πŸ“„ License

MIT License - see the LICENSE file for details.

πŸ‘€ Author

Md Kawsar Islam Yeasin

🀝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feat/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

See the issues page for known issues and feature requests.

About

Starter Template for creating NPM Packages

Topics

Resources

License

Code of conduct

Contributing

Stars

31 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors