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 🙏

© 2025 – Pkg Stats / Ryan Hefner

npm-packagr

v1.0.71

Published

Utility for build and publish npm package.

Downloads

21

Readme

npm packagr

build: success d.ts: ✔ license: MIT

The utility to build and publish a npm package.

Why?

If your package sources transpile before publishing. This utility helps you to build your package step by step and publish it.

Example

For example, the package has structure:

.
├── src
│   └── index.ts
├── LICENSE
├── npm-packagr.ts
├── package.json
├── README.md
└── tsconfig.json

File npm-packagr.ts contains:

import { npmPackagr } from "npm-packagr";
import { assets, doIf, packageJSON } from "npm-packagr/pipes";

npmPackagr({
    packageDirectory: "some/path", // "package" by default
    pipeline: [
        // some manipulations with package.json
        packageJSON((packageJson) => {
            delete packageJson.scripts;
            delete packageJson.devDependencies;

            packageJson.types = "types/";
        }),

        doIf("build", [
            ({ exec }) => {
                exec("tsc");
            },

            // needs to copy files to package
            assets("LICENSE", "README.md"),
        ]),

        doIf("dev", [
            ({ exec }) => {
                exec("tsc --watch");
            },
        ]),
    ],
});

Now, execute in the shell:

npx packagr --target build

It creates package directory that will seem like this:

.
├── package
│   ├── LICENSE
│   ├── index.d.ts
│   ├── index.js
│   ├── package.json
│   └── README.md
├── src
│   └── index.ts
├── LICENSE
├── npm-packagr.ts
├── package.json
├── README.md
└── tsconfig.json

Also you can see publisher.ts file of npm-packagr. It has been published by npm-packagr!)

Pipes

assets

Copy files to root of package directory.

assets("a", "b/c"); // same as cp -R a b/c package

Also can copy file to some target path in package directory.

assets({ from: "a", to: "b" }); // same as cp -R x package/b

badge

Create badges and add links to README.md. Using a package-badges

doIf

Run pipeline by the target option.

doIf("target-name", [
    () => {
        console.log("show if run:");
        console.log("npx packagr --target target-name");
    },
]);

file

Write a file.

file(() => ({
    name: "cli.js",
    content: `
        #!/usr/bin/env node

        require("..");
    `,
}));

git

Git actions and conditions.

git("branch", "brunchName"); // stop if the current brunch is not a "brunchName"
git("check-status"); // stop if "git status" returns some changes
git("commit", "message"); // git commit -m "message"
git("push"); // git push

npx

Run npx.

npx("tsc")
// equals
({ exec }) => exec("npx tsc")

packageJSON

Manipulations with a package.json.

publish

Publish a package.

publish(); // npm publish

// or you can provide the npm account
publish({ account: "name", email: "e@mail" });

tsc

tsc(), // same as ({ exec, packageDirectory }) => exec(`tsc --outDir ${packageDirectory}`)

test

Run a test.

version

Bump a package version.

Custom pipeline

Pipeline is just a function. The fisrt argument is the context that is an object contains some functions from shelljs and

  • exec
  • packageDirectory path to package directory.
  • sh
  • target target option.
import { Pipeline } from "./package/pipelines";

const myPipeline: Pipeline = ({
    cp, // shelljs
    exec,
    exit, // shelljs
    ls, // shelljs
    mkdir, // shelljs
    mv, // shelljs
    packageDirectory,
    rm, // shelljs
    sed, // shelljs
    sh,
    target,
    test, // shelljs
    touch, // shelljs
}) => {
    /* ... */
};

exec

Executes a command with output to console (or silent) and returns true if success.

const success: boolean = exec("tsc");
// or
const success: boolean = exec("tsc", { silent: true });

sh

Executes a command with no output to console and returns string of the output.

const version: string = sh("node --version");