Project template for TypeScript libraries
-
Enable Corepack
-
Run these commands:
β― gh repo clone jasonkuhrt/template-typescript-lib <directory> && \ cd <directory> && \ pnpm install && \ pnpm ts-node scripts/bootstrap.mts -
Setup a repo secret called
NPM_TOKENcontaining an npm token for CI package publishing.
Example:
β― gh repo clone jasonkuhrt/template-typescript-lib alge && \
cd alge && \
pnpm install && \
pnpm ts-node scripts/bootstrap
Cloning into 'alge'...
remote: Enumerating objects: 954, done.
remote: Counting objects: 100% (613/613), done.
remote: Compressing objects: 100% (353/353), done.
remote: Total 954 (delta 391), reused 419 (delta 219), pack-reused 341
Receiving objects: 100% (954/954), 1.80 MiB | 3.41 MiB/s, done.
Resolving deltas: 100% (577/577), done.
β€ YN0000: β Resolution step
β€ YN0000: β Completed in 0s 205ms
β€ YN0000: β Fetch step
β€ YN0013: β yargs-parser@npm:20.2.9 can't be found in the cache and will be fetched from the remote registry
β€ YN0013: β yargs@npm:16.2.0 can't be found in the cache and will be fetched from the remote registry
β€ YN0013: β yauzl@npm:2.10.0 can't be found in the cache and will be fetched from the remote registry
β€ YN0013: β yazl@npm:2.5.1 can't be found in the cache and will be fetched from the remote registry
β€ YN0013: β yn@npm:3.1.1 can't be found in the cache and will be fetched from the remote registry
β€ YN0000: β Completed in 26s 82ms
β€ YN0000: β Link step
β€ YN0007: β playwright@npm:1.19.1 must be built because it never has been before or the last one failed
β€ YN0000: β Completed in 6s 767ms
β€ YN0000: Done in 33s 170ms
? What is the name of your package? alge
? What is your name? This will be used in places needing a package author name. Jason Kuhrt
? What is the name of your GitHub repository? alge
? Who is the repository owner of your GitHub repository? jasonkuhrt
? Should the GitHub repository be created now? (Note for this to work there must be an environment variable called 'GITHUB_TOKEN' set with sufficient permissions.) Yes
s 34 β Now Running the bootstrapper based on the answers you gave...
1 β Replacing file fields with new values
4 β Uninstalling bootstrap deps
2040 β Removing bootstrap command
1 β Removing bootstrap script
2 β Running formatter
2432 β Creating a new git project
23 β Creating initial commit
75 β Creating repo on GitHub (you will need the gh CLI setup for this to work) -- url: 'https://github.com/jasonkuhrt/alge'
1826 β Pushing main branch and commit to GitHub
TypeScript for Type Safety & Productivity
-
Optimal settings for the safety of your implementation
strictmode enabled.- All lint flags enabled:
-
.tsbuildinfocache setup, output discretely intonode_modules/.cache -
Inherit settings from
@tsconfig/recommended(Node 14 flavour) -
Base
tsconfig.jsonshared acrosstests,src, andts-node. -
Optimal output setup for your users
- Target ES2020 which Node as low as version 14 has good support for (Kangax compatibility table).
declarationso your users can power their intellisense with your packages typings.declarationMapenabled to make your published source code be navigated to when your users use "go to definition".package.jsontypeVersionsused to emit only one set of declaration files shared by both CJS and ESM builds.sourceMapenabled to allow your users' tools to base off the source for e.g. stack traces instead of the less informative derived built JS.- Publish
srcwith dist files so that jump-to-definition tools work optimally for users.
-
ts-nodefor running TypeScript scripts/modules.- Setup to use SWC for maximum speed.
ESLint For Linting
- TypeScript integration
- TS type-checker powered eslint checks enabled
- Prettier integration using just
eslint-config-prettier.eslint-plugin-prettieris not used to avoid lint noise and slower run time. Prettier is expected to be run by your IDE and your CI and if really needed you manually viapnpm format. - Setup as a CI check for PRs
- Always display as warning to keep IDE error feedback for TypeScript (CI enforces warnings).
- Auto-fixable import sorting
Vitest for Testing
Just Works :)
Dripip for Releasing
- Emojis
βοΈ - Feature / bug / docs / something-else
- Config to display discussions link right in new issue type listing UI
Prettier for code formatting
- Prisma Labs config preset, 110 line width
- Setup as a CI check for PRs
- VSCode extension in recommended extensions list so that when collaborators open the project they'll get prompted to install it if they haven't already.
- npm script
cleanto remove cache and dist filesbuildthat runscleanbeforehandprepublishOnlythat runsbuildbeforehandformatto quickly runprettierover whole codebaselintto quickly runeslintover whole codebase
- Separate trunk and pull-request (PR) workflows.
- Dependency install cache enabled.
- On PR:
- Prettier Check
- Lint Check
- Type Check
- Tests across matrix of mac/linux/windows for Node 14/16
- On trunk:
- Tests across matrix of mac/linux/windows for Node 14/16
- Automated canary release
Renovate configuration
- JSON Schema setup for optimal intellisense
- Group all non-major devDependency updates into single PR (which "chore" conventional commit type)
- Group all major devDependency updates into single PR (with "chore" conventional commit type)
- Group all non-major dependency updates into single PR (with "deps" conventional commit type)
- Each major dependency update in own PR (with "deps" conventional commit type)
PnPM for package management
- Using Corepack. This means the PnPM specified in
package.jsonwill be used. And note this is a PnPM binary shipped with Node now. In a future version of Node you will not need to even opt-in into Corepack. Make sure you've donecorepack enableat least once.
- Use
exportsfield to give support to both modernimportand legacyrequireconsumers using Node 14.x and up. For details about theexportsfield refer to the Official Node.js Docs about it.
References:
- https://nodejs.org/api/packages.html#packages_package_json_and_file_extensions
- https://devblogs.microsoft.com/typescript/announcing-typescript-4-7
- https://kulshekhar.github.io/ts-jest/docs/guides/esm-support / https://jestjs.io/docs/ecmascript-modules
- https://typestrong.org/ts-node/docs/imports
- Optimize project search by recursively (ready for monorepo) ignoring
dist-*/, snapshots, lock files, and more. - On-Save actions for optimal editing experience (e.g. ESLint auto-fix to organize imports automatically)
- List of VSCode extensions that users who open the project will be prompted to install if they don't already.
- Enable
typescript.enablePromptUseWorkspaceTsdkso that oneself and collaborators will get prompted to use the workspace version of TypeScript instead of the one in the editor.
- Using
markdown-toc
Here are some TypeScript libraries you might want to use for your new project: