npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@warstekhun/typescript-npm-package-template

v1.1.1

Published

Typescript NPM package template that is ready for NPM and Github Packages publish.

Downloads

3

Readme

Typescript NPM package template

Test Static Badge

Based on Tom Chen's amazing template

Features

  • Building for severeal enviroments:
    • ESM
    • CommonJS
    • UMD
  • Your to be published package'll can be ran both in browsers and with NodeJS
    • Tested on:
      • NodeJS: 16.x | 17.x | 18.x
      • Webpack: 5
      • (Qwik: 1.26)
  • Creates d.ts by default
  • Supports tests with coverage with JEST
    • Outputs coverage badges automatically on build
  • Github Actions tests

Usage

  • After cloning the repo simply run npm install to install the required dependencies.
  • Configurate package.json for your needs
  • Write your code
  • Publish your package!

It is really that simple!

Detailed Usage

  • All the tests are located in the ./test folder.
    • You can run them with:
      • npm run test for simple testing
      • npm run test:cov for coverage testing. Will also open the coverage test results in your default browser.
  • Format youre code with Prettier:
    • npm run format:fix: Automatically fixes formatting.
    • npm run format:check: "Does not fix, only checks if fixing is needed, outputs results"
  • Build your project with:
    • npm run build: Builds the whole project
    • npm run build:esm: Builds only the ESM version
    • npm run build:cjs: Builds only the CommonJS version
    • npm run build:umd: Builds only the UMD version
    • npm run build:types: Builds only the types (d.ts)
  • Release your project:
    • npm run release:
      • Builds the project
      • Increments version automatically.
        • Asks for new package version or level of incrementing
          • Just like using npm version. Default: patch
          • Asks for custom commit message. Default: incremented version number
      • Creates new commit and tag
      • Pushes to repository
      • Creates new Github Release
        • You can set your release notes in CHANGELOG.md

Try your package before publishing

Try it before publishing

Run:

npm link

npm link will create a symlink in the global folder, which may be {prefix}/lib/node_modules/example-typescript-package or C:\Users<username>\AppData\Roaming\npm\node_modules\example-typescript-package.

Create an empty folder elsewhere, you don't even need to npm init (to generate package.json because your linked package won't show up in package.json). Open the folder with VS Code, open a terminal and just run:

npm link typescript-npm-package-template

This will create a symbolic link from globally-installed example-typescript-package to node_modules/ of the current folder. Then you'll be able to import your project by using its name property's value from package.json

import { Num } from 'typescript-npm-package-template';
console.log(new Num(5).add(new Num(6)).val() === 11)

CI Testing

Every commit and pull request is tested automatically on Node 16.x, 17.x and 18.x. You can set which node versions the tests should run on here: .github/workflows/test.yml:30.

Publishing your package

Using a Github Release (CI):

  • Publish your package to NPM and Github Packages at the same time!

Creating a Github Release

On every npm run release a Github Release will be automatically created, but in order to achieve that, you need to generate a Personal Access Token. And set it as a repository secret with the name PAT.

You can generate two types of tokens:

  • Tokens (classic) | I personally recommend this because you can set it to never expire.
    • You must select these scopes:
      • write:packages
  • Fine-grained tokens | Although this will expire max a year later and has to be renewed, you can set which repo it will work with.
    • You must select these repository permissions:
      • Actions
      • Contents
      • Pull requests

TIP: If the token does not show up after generating, try deleting all Github's saved data from your browser. This is also true with NPM.

Publishing to NPM

Follow npm's official instruction to create an npm token. Choose "Publish" from the website, or use npm token create without argument with the CLI. If you use 2FA, then make sure it's enabled for authorization only instead of authorization and publishing (Edit Profile -> Modify 2FA).

On the page of your newly created or existing GitHub repo, click Settings -> Secrets -> New repository secret, the Name should be NPM_TOKEN and the Value should be your npm token.

Publishing to Github Packages

The default configuration of this example package assumes you publish package with an unscoped name to npm. GitHub Packages must be named with a scope name such as "@warstekhun/typescript-npm-package-template".

Change scope: '@warstekhun' to your own scope in .github/workflows/publish.yml.

If you want to publish your package with a scoped name, change the name property in package.json and the scope from @warstekhun to yours at .github/workflows/publish.yml:49.

(You might have noticed secret.GITHUB_TOKEN in .github/workflows/publish.yml. You don't need to set up a secret named GITHUB_TOKEN actually, it is automatically created)

Manual publishing only to NPM

If you publish your package to npm only, and don't want to publish to GitHub Packages, then delete the lines from - name: Setup .npmrc file to publish to GitHub Packages to the end of the file in .github/workflows/publish.yml.

Log in:

npm adduser

And publish:

npm publish

References

This template project is a remastered version of Tom Scott's, if you want to publish a Python package, you should definetly start your project with his Example PyPI (Python Package Index) Package & Tutorial / Instruction / Workflow for 2021 template.