Skip to content

jasonkuhrt/template-typescript-lib

Β 
Β 

Repository files navigation

template-typescript-lib

trunk

Project template for TypeScript libraries

Quick Start

  1. Enable Corepack

  2. Run these commands:

    ❯ gh repo clone jasonkuhrt/template-typescript-lib <directory> && \
        cd <directory> && \
        pnpm install && \
        pnpm ts-node scripts/bootstrap.mts
    
  3. Setup a repo secret called NPM_TOKEN containing 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

Features

TypeScript for Type Safety & Productivity

  1. Optimal settings for the safety of your implementation

    1. strict mode enabled.
    2. All lint flags enabled:
  2. .tsbuildinfo cache setup, output discretely into node_modules/.cache

  3. Inherit settings from @tsconfig/recommended (Node 14 flavour)

  4. Base tsconfig.json shared across tests, src, and ts-node.

  5. Optimal output setup for your users

    1. Target ES2020 which Node as low as version 14 has good support for (Kangax compatibility table).
    2. declaration so your users can power their intellisense with your packages typings.
    3. declarationMap enabled to make your published source code be navigated to when your users use "go to definition".
    4. package.json typeVersions used to emit only one set of declaration files shared by both CJS and ESM builds.
    5. sourceMap enabled to allow your users' tools to base off the source for e.g. stack traces instead of the less informative derived built JS.
    6. Publish src with dist files so that jump-to-definition tools work optimally for users.
  6. ts-node for running TypeScript scripts/modules.

    1. Setup to use SWC for maximum speed.

ESLint For Linting

  1. TypeScript integration
  2. TS type-checker powered eslint checks enabled
  3. Prettier integration using just eslint-config-prettier. eslint-plugin-prettier is 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 via pnpm format.
  4. Setup as a CI check for PRs
  5. Always display as warning to keep IDE error feedback for TypeScript (CI enforces warnings).
  6. Auto-fixable import sorting

Vitest for Testing

Just Works :)

Dripip for Releasing

Simple succinct friendly low-barrier issue templates

  1. Emojis ✈️
  2. Feature / bug / docs / something-else
  3. Config to display discussions link right in new issue type listing UI

Prettier for code formatting

  1. Prisma Labs config preset, 110 line width
  2. Setup as a CI check for PRs
  3. 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.
  4. npm script

npm scripts for development lifecycle

  1. clean to remove cache and dist files
  2. build that runs clean beforehand
  3. prepublishOnly that runs build beforehand
  4. format to quickly run prettier over whole codebase
  5. lint to quickly run eslint over whole codebase

CI with GitHub Actions

  1. Separate trunk and pull-request (PR) workflows.
  2. Dependency install cache enabled.
  3. On PR:
    1. Prettier Check
    2. Lint Check
    3. Type Check
    4. Tests across matrix of mac/linux/windows for Node 14/16
  4. On trunk:
    1. Tests across matrix of mac/linux/windows for Node 14/16
    2. Automated canary release

Renovate configuration

  1. JSON Schema setup for optimal intellisense
  2. Group all non-major devDependency updates into single PR (which "chore" conventional commit type)
  3. Group all major devDependency updates into single PR (with "chore" conventional commit type)
  4. Group all non-major dependency updates into single PR (with "deps" conventional commit type)
  5. Each major dependency update in own PR (with "deps" conventional commit type)

PnPM for package management

  1. Using Corepack. This means the PnPM specified in package.json will 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 done corepack enable at least once.

CJS+ESM Hybrid package build

  1. Use exports field to give support to both modern import and legacy require consumers using Node 14.x and up. For details about the exports field refer to the Official Node.js Docs about it.

References:

VSCode Settings

  1. Optimize project search by recursively (ready for monorepo) ignoring dist-*/, snapshots, lock files, and more.
  2. On-Save actions for optimal editing experience (e.g. ESLint auto-fix to organize imports automatically)
  3. List of VSCode extensions that users who open the project will be prompted to install if they don't already.
  4. Enable typescript.enablePromptUseWorkspaceTsdk so that oneself and collaborators will get prompted to use the workspace version of TypeScript instead of the one in the editor.

Readme Table of Contents

  1. Using markdown-toc

Useful TypeScript Libraries

Here are some TypeScript libraries you might want to use for your new project:

https://github.com/stars/jasonkuhrt/lists/typescript

Alt

About

πŸŽ›οΈ Project template for TypeScript libraries

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •