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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bun-build-userscript

v2.1.6

Published

Building index.ts and header.txt into one js-file via bun

Readme

Builds index.ts and header.txt (configurable) into a single js-file.

Replaces {version} in header.txt by version from package.json.

Install

bun add -D bun-build-userscript
# or
npm i -D bun-build-userscript

Usage

From package.json

{
  "scripts": {
    "build": "build-userscript",
    "watch": "build-userscript --watch"
  }
}

Globally

bun add --global bun-build-userscript

# build
build-userscript
# watch
build-userscript --watch

Globally (without installing)

# build
bunx bun-build-userscript
# watch
bunx bun-build-userscript --watch

Options

--version -v

Prints the current package version.

--watch

Listens for changes in the source file(s) and rebuilds.

--cfg

Path to your config.

build-userscript --cfg my_config.ts
# JavaScript is also supported
build-userscript --cfg my_config.js

Example config:

// EXPORTING BOTH `userscript` AND `bun` IS OPTIONAL.
// ALL OPTIONS ARE OPTIONAL

import type { BuildConfigs } from "bun-build-userscript";

export const userscript: BuildConfigs['userscript'] = {
  // may be useful in watch mode
  before: async ({ bun, userscript }) => {
    // you can add additional entrypoints
    bun.entrypoints.push(additionalFile);
    // or redefine some variables
    bun.define = JSON.parse(await readFile("constants.json", "utf8"));
  },
  transform: (code) => code;
  // default options (simplified)
  logErrors: process.argv.includes("--log-errors"),
  clearTerminal: !(isBuild || process.argv.includes("--no-clear")),
  header: getArg("--header") || "header.txt",
  entry: getArg("--entry") ||  "index.ts",
};

// BuildConfigs["bun"] is an alias to import("bun").BuildConfig
export const bun: BuildConfigs["bun"] = {
  // default options (simplified)
  // if you want to change entrypoints, it's better to use `userscript.before` instead
  entrypoints: [getIndexTs(userscript.entry)],
  naming: "script.user.js",
  outdir: ".",
};

--out

Output file path.

Default: user.script.js

Config: bun.naming (can be combined with bun.outdir)

build-userscript --out index.js

--log-errors

Do print errors to the browser console.

Default: false

Config: bun.logErrors

Recommended:

{
  logErrors: !process.argv.includes("--build"),
}

--no-clear

Disables clearing terminal in watch mode.

Default: false

Config: userscript.clearTerminal

--header

Path to your header file.

Default: header.txt or src/header.txt

Config: userscript.header

--entry

Path to your source file/dir.

If it's a directory, entry point is resolved to index.ts in this directory, but all files are watched in watch mode.

Default: index.ts or src/index.ts

Config: userscript.entry

--delay

Delay (milliseconds) between file change and build in watch mode.

Introduced because of the issue with bun not being able to find the changed file.

Default: 100

Config: not available

userscript.transform

NOT AVAILABLE IN CLI

Function to transform the code after it's built.

Async: not supported.

Default: undefined

userscript.before

NOT AVAILABLE IN CLI

Function to run before the build.

Takes modified bun and userscript objects, returns nothing.

Async: supported.

Default: undefined