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

@erdbeerheld1990/my-example-lib

v0.0.4

Published

This project demonstrates an example npm library with an hello world function

Downloads

6

Readme

build ci publish example library

This example project shows how to deploy a library and publish it. It uses pnpm changesets and tsup for building the project.

Steps

  1. Set noEmit: true in tsconfig.json for disabling generate any JavaScript source code, source-maps or declarations. Tsup is a separate transpiler from typescript. It is a task runner that can handle the bundling and transpilation of various formats. tsup can perform more advanced transpilation tasks than TypeScript. It can handle things like tree-shaking, code splitting, and minification, which can significantly improve the performance and size of your compiled code. By setting noEmit: true, you give tsup complete control over the transpilation process, allowing it to optimize the output for your specific needs.

  2. Add a build script with tsup and a lint check. tsc can be used here because of noEmit: true the Typescript code is still analyzed and typechecked.

"build": "tsup src/index.ts --format cjs,esm --dts",
"lint": "tsc",
  1. add ci pipeline with test in ./github/workflows/main.yml. Since this is currently a mono repo, also the nodejs setup github action must be configured with a cache dependency path:
- uses: actions/setup-node@v3
    with:
      node-version: 20.x
      cache: "pnpm"
      cache-dependency-path: "build-ci-publish-example/pnpm-lock.yaml"
  1. Adjust and set the index modules, index file and types in package.json:
  "main": "./dist/index.js",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.ts",
  1. create npm account if not already done on https://www.npmjs.com/
  2. Create an access token in the npm profile top right and => access token and safe it in the guithub repo as a github repo secret
  3. Add changeset library and initialize it for release changes: pnpm add -D @changesets/cli && pnpm changeset init. Whenever you want to publish new changes do pnpm changeset and give it a name.
  4. Add a release script, which will lint, test, build and publish the libary to package.json
"release": "pnpm run lint && pnpm run test && pnpm run build && changeset publish"
  1. Add .github/workflows/publish.yml as a new github action, which uses the github action changesets
  2. Add an .nvmrc file containing the node version
  3. Add a vite.config.mts (CJS is deprecated) file and import it vitest/dist/config. This will make Node interpret the file as an ESM file using TypeScript syntax. The vitest/config import from the video is therefore also deprecated. So the vite config should look like this:
import { defineConfig } from "vitest/config";

// vite.config.js
export default defineConfig({
  test: {},
  // config options
});
  1. if you want to publish it to public npmjs set in package.json
private: false
  1. In the created .changeset/config.json set "access": "public" for publishing these changesets
  2. In your github repo settings choose Settings -> Actions -> General -> workflow permissions and set it to Read and write permissions and check the box Allow GitHub Actions to create and approve pull requests
  3. add .npmignore in order just to deploy a dist folder.

Here are additional helpful docs for this project:

  • https://tsup.egoist.dev/#typescript--javascript
  • https://vitest.dev/guide/debugging
  • https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md
  • https://github.com/changesets/action?tab=readme-ov-file#custom-publishing
  • https://stackoverflow.com/questions/72376229/github-actions-is-not-permitted-to-create-or-approve-pull-requests-createpullre
  • https://docs.npmjs.com/creating-and-publishing-scoped-public-packages
  • https://www.youtube.com/watch?v=aKTSC4D1GL8&list=PLEBCKcboIbaC7NeJ_C8kXjafGoI6_RAQI&index=30&t=6028s
  • https://prettier.io/docs/en/install