Skip to content

Instantly share code, notes, and snippets.

@sorrycc
Created November 28, 2025 04:49
Show Gist options
  • Select an option

  • Save sorrycc/5624f889f477e9a73ef8aa001b73b88a to your computer and use it in GitHub Desktop.

Select an option

Save sorrycc/5624f889f477e9a73ef8aa001b73b88a to your computer and use it in GitHub Desktop.
# TypeScript Project Setup Prompt
Set up a modern TypeScript project with the following structure and configurations:
## Project Requirements
1. **Package Manager**: pnpm@10.24.0
2. **Runtime Management**: Volta for Node.js version pinning
3. **Build Tool**: Bun for fast bundling
4. **Code Quality**: Biome for formatting and linting
5. **Git Hooks**: Husky + lint-staged for pre-commit checks
6. **Testing**: Vitest
7. **Type Checking**: TypeScript with strict configuration
## Directory Structure
```
project-root/
├── src/
│ └── index.ts
├── dist/
├── .editorconfig
├── .gitignore
├── .npmrc
├── biome.json
├── LICENSE
├── package.json
├── tsconfig.json
├── vitest.config.ts
└── .husky/
└── pre-commit
```
## Configuration Files
### package.json
```json
{
"name": "my-package",
"version": "1.0.0",
"type": "module",
"files": [
"dist"
],
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"dev": "bun src/index.ts",
"build": "rm -rf dist && bun build src/index.ts --minify --outfile dist/index.mjs --target=node && tsc --emitDeclarationOnly --declarationDir dist",
"test": "vitest run",
"test:watch": "vitest",
"typecheck": "tsc --noEmit",
"format": "biome format .",
"format:write": "biome format --write .",
"lint": "biome lint .",
"ci": "npm run typecheck && npm run format && npm run test",
"prepare": "husky"
},
"keywords": [],
"authors": [
"Your Name <your.email@example.com> (https://github.com/yourusername)"
],
"license": "MIT",
"devDependencies": {
"@biomejs/biome": "^2.3.6",
"husky": "^9.1.7",
"lint-staged": "^16.2.7",
"typescript": "^5.9.3",
"vitest": "^4.0.10"
},
"volta": {
"node": "22.11.0",
"pnpm": "10.24.0"
},
"packageManager": "pnpm@10.24.0",
"lint-staged": {
"*.{js,jsx,ts,tsx,json,css}": "biome format --write"
}
}
```
### tsconfig.json
```json
{
"compilerOptions": {
"target": "ES2020",
"module": "esnext",
"moduleResolution": "bundler",
"declaration": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist",
"rootDir": "src",
"resolveJsonModule": true,
"verbatimModuleSyntax": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
```
### biome.json
```json
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": true
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single"
}
},
"json": {
"formatter": {
"enabled": true
}
}
}
```
### .editorconfig
```ini
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
```
### .gitignore
```gitignore
node_modules
dist
.env
*.log
.DS_Store
coverage
```
### .npmrc
```
registry=https://registry.npmjs.org
```
### vitest.config.ts
```typescript
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
include: ['src/**/*.test.ts'],
exclude: ['node_modules', 'dist'],
testTimeout: 30000,
},
});
```
### LICENSE
```
The MIT License (MIT)
Copyright (c) 2025-present Your Name (your.email@example.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```
### src/index.ts
```typescript
export function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet('World'));
```
### .husky/pre-commit
```bash
pnpm lint-staged -q
```
## Setup Instructions
1. **Install Volta** (if not already installed):
```bash
curl https://get.volta.sh | bash
```
2. **Initialize the project**:
```bash
mkdir my-project && cd my-project
git init
```
3. **Create all configuration files** with the content shown above.
4. **Install dependencies**:
```bash
pnpm install
```
5. **Initialize Husky**:
```bash
pnpm exec husky init
```
6. **Create the pre-commit hook**:
```bash
echo "pnpm lint-staged -q" > .husky/pre-commit
```
7. **Verify the setup**:
```bash
pnpm run ci
```
## Available Scripts
- `pnpm dev` - Run the project in development mode with Bun
- `pnpm build` - Build the project (bundle + type definitions)
- `pnpm test` - Run tests once
- `pnpm test:watch` - Run tests in watch mode
- `pnpm typecheck` - Type check without emitting files
- `pnpm format` - Check formatting
- `pnpm format:write` - Format all files
- `pnpm lint` - Run linter
- `pnpm ci` - Run all checks (typecheck, format, test)
## Notes
- The build script creates both `dist/index.mjs` (bundled code) and `dist/index.d.ts` (type definitions)
- Biome handles both formatting and linting (replaces Prettier + ESLint)
- Husky + lint-staged automatically formats files before commit
- Volta ensures consistent Node.js and pnpm versions across environments
- Package is configured as ESM (`"type": "module"`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment