This is a template for creating a TypeScript library.
It was created on the basis of the UserUtils library.
- TypeScript with tslib import helper
- Building with tsup and esbuild
- Linting with ESLint
- CI and CD via GitHub Actions
- Changesets for versioning, changelogs, releases and continuous deployment
- Testing with Vitest
- Coverage by v8
- pnpm as the package manager
- Create a repo based on this template
- Go to settings > secrets and add
NPM_TOKEN
with a token that has access to publish packages - Make sure to sign in with GitHub on https://jsr.io/, so that the workflow has rights to publish
- Clone the new repo
- Install dependencies with
pnpm i
- Search for
editme-
(case insensitive) to find all places that need to be edited - Create files inside
lib/
and re-export them inlib/index.ts
- Run
pnpm build-all
to build the full library including types
- Building:
The library is built with tsup. It is only intended for code bundles though and the types it generates aren't suitable for production.
So instead, when usingpnpm build-all
, the types are generated withtsc
inside thedist/
folder. This however trims all trailing whitespace, messing up TSDoc comment formatting. So the tool attools/fix-dts.mts
is called to fix that. - Publishing on npm:
Publishing on npm happens automatically when the pull request created by the changesets action is merged.
First, the publish to JSR should be tested though by runningpnpm check-jsr
- Publishing on JSR:
After runningpnpm check-jsr
, merging the changesets pull request and with the publish to npm finished, thebuild-and-publish-jsr.yml
workflow can be manually triggered through the "Actions" tab in the GitHub repo.
This will also trigger the tool attools/update-jsr-version.mts
, which will copy the version number frompackage.json
over tojsr.json
, so you don't have to worry about keeping them in sync manually.
Unfortunately triggering the publish to JSR automatically didn't work due to technical constraints. - Testing:
The tests are run automatically on every push and pull request.
You can run the tests locally withpnpm test
.
Runpnpm test-coverage
to generate a coverage report atcoverage/lcov-report/index.html
. - Linting:
Linting is also run automatically on every push and pull request.
You can run the linter locally withpnpm lint
.
Make ESLint fix all auto-fixable issues withpnpm format
.