@presetter/preset-essentials
๐๐ป A collection of opinionated configurations for a TypeScript project
The essentials preset is the foundation of the Presetter ecosystem, providing all the core development tools and configurations you need to build modern TypeScript projects. It's designed to get you from zero to productive development in seconds.
๐ฏ Purposeโ
@presetter/preset-essentials eliminates the tedious setup of TypeScript development environments by providing:
- Instant productivity: Start coding immediately without configuration overhead
- Best practices: Pre-configured tools following community standards
- Type safety: Strict TypeScript configuration for robust development
- Quality assurance: Automated linting, formatting, and testing
- Developer experience: Git hooks, hot reloading, and helpful scripts
๐ Featuresโ
Core Development Toolsโ
- ๐ ๏ธ TypeScript 6 - Type-safe JavaScript with a strict configuration targeting ES2024, including
noUncheckedIndexedAccessfor safer indexed access - ๐จ ESLint 9 - Code quality enforcement with TypeScript support
- ๐ Prettier 3 - Consistent code formatting
- ๐งช Vitest 4 - Fast unit testing with coverage reporting
- ๐ฐ git-cliff - Automated semantic versioning and changelogs
- ๐ง zx - Cross-platform shell scripting
Quality Assuranceโ
- Git hooks with Husky for pre-commit quality checks
- Lint-staged for efficient linting of changed files
- Coverage reporting with comprehensive test metrics
- Automatic .gitignore integration with ESLint
- Nearest ESLint config lookup for package-level overrides
Developer Experienceโ
- Hot reloading for development workflow
- Watch mode for continuous testing
- Cross-platform script compatibility
- Path mapping support for clean imports
๐ซ Installationโ
Quick Startโ
# Install the preset
npm install --save-dev presetter @presetter/preset-essentials
# Create configuration
echo "export { default } from '@presetter/preset-essentials';" > presetter.config.ts
# Bootstrap your project
npm install
Package.json Setupโ
Add these scripts to your package.json:
{
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"prepare": "run prepare",
"build": "run build",
"lint": "run lint --",
"test": "run test --",
"test:coverage": "run test:coverage --",
"test:watch": "run test:watch --",
"typecheck": "run typecheck --"
}
}
๐ Configuration Files Generatedโ
After bootstrapping, your project will include:
tsconfig.json- TypeScript compiler configurationtsconfig.build.json- Production build configurationeslint.config.ts- ESLint rules and plugins.prettierrc.json- Code formatting preferencesvitest.config.ts- Test runner configuration.lintstagedrc.json- Pre-commit hook configuration.npmignore- NPM packaging exclusions.husky/- Git hook scripts
๐ Project Structureโ
The preset expects this project structure:
(root)
โโ .git
โโ .husky/
โโ .lintstagedrc.json
โโ .npmignore
โโ .prettierrc.json
โโ presetter.config.ts
โโ node_modules/
โโ src/
โ โโ index.ts # Main entry point
โ โโ (other files)
โโ spec/
โ โโ *.spec.ts # Test files
โโ package.json
โโ eslint.config.ts
โโ tsconfig.json
โโ tsconfig.build.json
โโ vitest.config.ts
๐ Available Scriptsโ
Build & Developmentโ
run buildโ
Transpile TypeScript source code and replace any mapped paths.
npm run build
# or
run build
run cleanโ
Clean up any previously transpiled code.
run clean
run startโ
Watch source files and rebuild on change (development service).
run start
Testingโ
run testโ
Run all tests with Vitest.
run test
# With options
run test -- --watch
run test -- --ui
run test:unitโ
Run unit tests only (files matching *:UNIT pattern).
run test:unit
run test:intโ
Run integration tests only (files matching *:INT pattern).
run test:int
run test:e2eโ
Run end-to-end tests only (files matching *:E2E pattern).
run test:e2e
run typecheckโ
Run TypeScript type checking without emitting files.
run typecheck
run test:watchโ
Continuously run unit tests whenever source code changes.
run test:watch
run test:coverageโ
Run all tests with coverage reporting.
run test:coverage
Release Managementโ
run releaseโ
Bump the version and generate the changelog with git-cliff, then commit and tag the release.
run release
# With a prerelease tag
PRERELEASE=alpha run release
๐ฉ Customizationโ
Basic Customizationโ
// presetter.config.ts
import { preset } from 'presetter';
import essentials from '@presetter/preset-essentials';
export default preset('my-project', {
extends: [essentials],
variables: {
source: 'lib', // Change from default 'src'
output: 'dist', // Change from default 'lib'
test: 'tests', // Change from default 'spec'
target: 'ES2020' // Change TypeScript target
}
});
Advanced Configuration Overrideโ
// presetter.config.ts
import { preset } from 'presetter';
import essentials from '@presetter/preset-essentials';
export default preset('custom-project', {
extends: [essentials],
override: {
assets: {
'tsconfig.json': {
compilerOptions: {
strict: false, // Relax TypeScript strictness
experimentalDecorators: true // Enable decorators
}
},
'eslint.config.ts': (current) => ({
...current,
rules: {
...current.rules,
'no-console': 'warn', // Allow console with warning
'@typescript-eslint/no-explicit-any': 'off' // Allow any type
}
}),
'vitest.config.ts': {
test: {
globals: true, // Enable global test functions
environment: 'jsdom' // Use jsdom for DOM testing
}
}
}
}
});
Combining with Other Presetsโ
// presetter.config.ts
import { preset } from 'presetter';
import essentials from '@presetter/preset-essentials';
import strict from '@presetter/preset-strict';
export default preset('production-ready', {
extends: [essentials, strict], // Add strict quality rules
variables: {
target: 'ES2022'
}
});
๐ป Included Dependenciesโ
Core Toolsโ
typescript(^6.0.0) - TypeScript compilereslint(^9.18.0) - Linting utilityprettier(^3.0.0) - Code formattervitest(^4.0.0) - Test framework
ESLint Pluginsโ
typescript-eslint(^8.0.0) - TypeScript parser and ruleseslint-plugin-import- Import/export syntax checkingeslint-plugin-jsdoc- JSDoc comment validation@eslint-community/eslint-plugin-eslint-comments- ESLint directive validation
Build & Developmentโ
tsx(^4.0.0) - TypeScript execution and REPLtsc-alias(^1.0.0) - Path mapping resolutiontsc-esm-fix(^3.0.0) - ESM compatibility fixescross-env(^10.0.0) - Cross-platform environment variablesjiti(^2.4.0) - Runtime TypeScript and ESM support
Quality & Toolingโ
husky(^9.0.0) - Git hook managementlint-staged(^16.0.0) - Run linters on staged filesgit-cliff(^2.12.0) - Version calculation and changelog generation@vitest/coverage-v8(^4.0.0) - Test coverage reportingzx(^8.0.0) - Shell scripting utilities
๐ง Common Use Casesโ
Node.js Applicationโ
// presetter.config.ts
export { default } from '@presetter/preset-essentials';
// package.json
{
"type": "module",
"main": "lib/index.js",
"bin": {
"my-cli": "lib/cli.js"
}
}
NPM Libraryโ
// presetter.config.ts
import { preset } from 'presetter';
import essentials from '@presetter/preset-essentials';
export default preset('my-library', {
extends: [essentials],
variables: {
target: 'ES2018' // Broader compatibility for libraries
},
override: {
assets: {
'package.json': {
files: ['lib'],
exports: {
'.': {
types: './lib/index.d.ts',
import: './lib/index.js'
}
}
}
}
}
});
Workspace Packageโ
// presetter.config.ts
import { preset } from 'presetter';
import essentials from '@presetter/preset-essentials';
export default preset('workspace-package', {
extends: [essentials],
variables: {
source: 'src',
output: 'dist'
}
});
โก Performance Tipsโ
Faster Buildsโ
- Use
--skipLibCheckin TypeScript for faster compilation - Enable
incrementalcompilation for large projects - Consider
--transpileOnlyfor development builds
Efficient Testingโ
- Use test patterns to run specific test suites
- Enable coverage only when needed
- Utilize watch mode for development
Optimized Lintingโ
- Use lint-staged to lint only changed files
- Configure ESLint cache for faster subsequent runs
- Set appropriate ignore patterns
๐ Troubleshootingโ
Common Issuesโ
TypeScript compilation errors:
# Check TypeScript configuration
cat tsconfig.json
# Verify target compatibility
npx tsc --showConfig
ESLint configuration conflicts:
# Test ESLint configuration
npx eslint --print-config src/index.ts
# Debug rules
npx eslint src/index.ts --debug
Test failures:
# Run tests with verbose output
run test -- --reporter=verbose
# Check Vitest configuration
cat vitest.config.ts
Performance Issuesโ
Slow builds:
- Enable TypeScript incremental compilation
- Use
--skipLibCheckfor faster compilation - Consider excluding large dependencies from type checking
Slow tests:
- Use test patterns to run specific suites
- Enable test parallelization
- Mock expensive operations
๐ Integration Examplesโ
CI/CD Pipelineโ
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run test
- run: npm run build
VS Code Integrationโ
// .vscode/settings.json
{
"typescript.preferences.includePackageJsonAutoImports": "on",
"eslint.format.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
๐ Migration Guideโ
From Manual Setupโ
# 1. Remove existing tool configurations
rm .eslintrc.* prettier.config.* jest.config.* tsconfig.json
# 2. Install presetter
npm install --save-dev presetter @presetter/preset-essentials
# 3. Create preset configuration
echo "export { default } from '@presetter/preset-essentials';" > presetter.config.ts
# 4. Bootstrap
npm install
From Create React Appโ
# 1. Eject first (if needed)
npm run eject
# 2. Install presetter
npm install --save-dev presetter @presetter/preset-essentials
# 3. Create configuration
echo "export { default } from '@presetter/preset-essentials';" > presetter.config.ts
# 4. Bootstrap and clean up
npm install
rm -rf config/ scripts/ # Remove CRA configs
๐ฐ๏ธ Next Stepsโ
After setting up the essentials preset:
- Choose module system: Add ESM, CJS, or Hybrid
- Enhance quality: Consider Strict preset for additional rules
- Add framework support: Integrate React or Web tools
- Bundle for distribution: Use Rollup preset for libraries
๐ Related Resourcesโ
- Configuration Guide - Deep dive into customization
- CLI Reference - Command usage and options
- Module System Presets - ESM, CJS, and Hybrid configurations
- GitHub Repository - Source code and issues