A npm package template with typescript.
pnpm | npm | yarn | |
---|---|---|---|
Install dependencies | pnpm install |
npm install |
yarn |
Generate documentation | pnpm run docs |
npm run docs |
yarn run docs |
Run unit tests | pnpm run test |
npm run test |
yarn run test |
Build | pnpm run build |
npm run build |
yarn run build |
Lint | pnpm run lint[:fix] |
npm run lint[:fix] |
yarn run lint[:fix] |
Format | pnpm run format[:fix] |
npm run format[:fix] |
yarn run format[:fix] |
- TypeScript: TypeScript is JavaScript with syntax for types.
- tsup: Bundle your TypeScript library with no config, powered by esbuild.
Install
pnpm add -D typescript tsup
Configure
tsconfig.json
:
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
tsup.config.ts
:
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
target: "es2020",
format: ["cjs", "esm"],
splitting: false,
sourcemap: true,
clean: true,
dts: true,
});
- Prettier: Prettier is an opinionated code formatter.
- ESLint: ESLint statically analyzes your code to quickly find problems.
Install
pnpm add -D @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint eslint-config-prettier prettier
Configure
.eslintrc.cjs
:
/* eslint-env node */
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
root: true,
};
.prettierrc
(see .editorconfig
):
{}
- TypeDoc: TypeDoc converts comments in TypeScript source code into rendered HTML documentation or a JSON model.
Install
pnpm add -D typedoc @mxssfd/typedoc-theme
Configure
typedoc.config.cjs
:
/* eslint-env node */
/** @type {import('typedoc').TypeDocOptions} */
module.exports = {
entryPoints: ["./src/index.ts"],
out: "docs",
plugin: ["@mxssfd/typedoc-theme"],
theme: "my-theme",
cleanOutputDir: true,
};
- Jest: Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
- ts-jest: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
Install
pnpm add -D jest ts-jest @types/jest && \
npx ts-jest config:init
Configure
jest.config.cjs
:
/* eslint-env node */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
collectCoverage: true,
coverageDirectory: "coverage",
coveragePathIgnorePatterns: ["/node_modules/"],
coverageProvider: "v8",
coverageReporters: ["json", "text", "lcov", "clover"],
};
- Husky: Modern native git hooks made easy.
- lint-staged: Run linters against staged git files.
- Commitizen: Simple commit conventions for internet citizens.
- cz-conventional-changelog: Part of the commitizen family. Prompts for conventional changelog standard.
- semantic-release: Automates the whole package release workflow including: determining the next version number, generating the release notes, and publishing the package.
Install
see: https://prettier.io/docs/en/precommit.html#option-1-lint-stagedhttpsgithubcomokonetlint-staged
npx mrm@2 lint-staged
Configure
.lintstagedrc
:
{
"*.js": "eslint --cache --fix",
"*.--check": "prettier --write"
}
.husky/pre-commit
:
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
Install
npm install commitizen -g && \
commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact && \
pnpm add -D semantic-release conventional-changelog-conventionalcommits
Incorporate Commitizen into the existing git commit workflow.
.husky/prepare-commit-msg
:
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
exec </dev/tty && npx cz --hook || true
Configure
.czrc
:
{
"path": "cz-conventional-changelog"
}
.releaserc
:
{
"branches": ["main"],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"type": "build",
"scope": "deps",
"release": "patch"
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "build",
"section": "Dependencies and Other Build Updates",
"hidden": false
}
]
}
}
],
"@semantic-release/npm",
"@semantic-release/github"
]
}