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

@ronmu/trace-inject

v1.0.2-20260824-1746.0

Published

基于 AST 的 JavaScript 代码追踪注入工具(CLI):bun 编译原生二进制,跨平台分发

Readme

trace-inject

基于 AST 逻辑动态注入追踪代码的 CLI 工具。源码为 TypeScript,通过 bun 交叉编译为各平台原生二进制,以 npm 包形式分发。

安装

npm install -g @ronmu/trace-inject

主包会自动安装当前平台对应的二进制包(optionalDependencies),无需关心平台细节。

使用

trace-inject --input-file <密文文件> [--output-folder=<输出目录>]

示例:

trace-inject --input-file ./sample/index.js --output-folder=./output

参数说明:

| 参数 | 必填 | 说明 | | --- | --- | --- | | --input-file(-i) | 是 | 需要注入追踪代码的 JS/TS 文件 | | --output-folder(-o) | 否 | 输出目录,默认与输入文件同目录 |

输出文件为 <文件名>.trace.cjs,包含 __TRACE 运行时与注入的函数/分支/循环等追踪点。

平台支持

| 平台 | 架构 | 二进制包 | | --- | --- | --- | | macOS | arm64 | @ronmu/trace-inject-darwin-arm64 | | macOS | x64 | @ronmu/trace-inject-darwin-x64 | | Linux | x64 | @ronmu/trace-inject-linux-x64 | | Linux | arm64 | @ronmu/trace-inject-linux-arm64 | | Windows | x64 | @ronmu/trace-inject-win32-x64 |

本地构建与发布

# 编译全部平台二进制到 build/
bun run scripts/build.mjs

# 只编译本机平台(快速验证)
bun run scripts/build.mjs --local

# 编译 + UPX 压缩 + 发布全部包(先平台包后主包)
bun run scripts/publish.mjs

发布脚本会自动递增版本号(npm version prepatch --preid=<时间戳> --force --no-git-tag-version,如 1.0.1-20260824-1730.0),保证每次发布的版本唯一,无需手动改版本,也避免「无法覆盖已发布版本」的 403 错误。

npm 认证二选一(token 均不写入仓库):

  • 将 NPM_TOKEN=<你的 token> 写入项目根 .env(已被 gitignore,bun 自动加载)
  • 或执行 npm login(凭据存于 ~/.npmrc)

发布时 scripts/publish.mjs 会自动用 UPX(--lzma)压缩 linux/win32 二进制(体积可缩减约 75%),macOS 的 Mach-O 不受 UPX 支持、保持原样。本机未安装 UPX 时跳过压缩(brew install upx)。

压缩后的 linux 二进制可用 Docker 验证(需先启动 Docker):

docker run --rm -v "$PWD/build:/b" -v "$PWD/sample:/s" alpine \
  /b/trace-inject-linux-x64 --input-file=/s/index.js --output-folder=/out

从源码运行

bun run trace-inject.ts --input-file ./sample/index.js --output-folder=./output

原理

使用 @babel/parser 解析源码为 AST,遍历函数、条件、循环、try/catch 等节点,注入 __TRACE(file, line, column, type, extra) 调用,最后用 @babel/generator 重新生成代码并拼接运行时。