@bitfab/transform

中文文档
0.1.8发布于 2026/10/15MITTypeScriptESM + CJS近 30 天下载 5537

Experimental build adapters for Bitfab automatic call tracing

此软件包已被标记为弃用

Deprecated: use @bitfab/sdk/transform/* instead (e.g. @bitfab/sdk/transform/next). Remove @bitfab/transform from your dependencies.

原始使用文档
文档目录6 节
  1. Next.js
  2. NestJS
  3. Explicit Bitfab spans
  4. Unplugin build tools
  5. Direct TypeScript execution
  6. Idle-path benchmark

@bitfab/transform compatibility package

Compatibility package for the experimental build integrations that produce automatic first-party call spans beneath @bitfab.trace() and bitfab.withTrace() roots. Discovered calls configured with @bitfab.node() or bitfab.withNode() remain transform-eligible because the enclosing subtree trace still owns their spans.

The adapters now ship in @bitfab/sdk. New installations need only the SDK and should import adapters from @bitfab/sdk/transform/*. Existing @bitfab/transform imports remain supported during migration.

Install @bitfab/sdk, then add one bundled adapter where original server TypeScript or JavaScript is first compiled:

ToolPackage export
Next.js 16, Turbopack, or Next webpack@bitfab/sdk/transform/next
NestJS with the webpack builder@bitfab/sdk/transform/nest
Vite@bitfab/sdk/transform/vite
Rollup@bitfab/sdk/transform/rollup
Rolldown@bitfab/sdk/transform/rolldown
esbuild@bitfab/sdk/transform/esbuild
Bun@bitfab/sdk/transform/bun
webpack@bitfab/sdk/transform/webpack
Rspack@bitfab/sdk/transform/rspack
Rsbuild@bitfab/sdk/transform/rsbuild
Babel@bitfab/sdk/transform/babel
Programmatic SWC@bitfab/sdk/transform/swc
Direct Node TypeScript or tsx@bitfab/sdk/transform/register

Next.js

import type { NextConfig } from "next"
import withBitfabTrace from "@bitfab/sdk/transform/next"

const nextConfig: NextConfig = {}
export default withBitfabTrace(nextConfig)

The wrapper instruments Node server modules in Turbopack and webpack builds. It does not instrument client or Edge bundles.

Instrumentation is scoped to the directory Next runs in, so sibling packages in a monorepo are left to add their own adapter. Pass cwd to widen or narrow that scope.

NestJS

Select Nest's webpack builder and point it at a normal custom webpack config:

{
  "compilerOptions": {
    "builder": "webpack",
    "webpackConfigPath": "webpack.config.cjs"
  }
}
const bitfabNestTrace = require("@bitfab/sdk/transform/nest").default

module.exports = bitfabNestTrace()

The wrapper preserves the webpack configuration generated by Nest and appends the shared Bitfab transform. Nest projects using the tsc or SWC builder still emit the rich trace() root, but need a corresponding compiler integration to discover child calls.

Explicit Bitfab spans

The transform does not instrument Bitfab's SDK implementation or the withSpan()/withTrace() call itself. It also recognizes inline and referenced functions passed to those wrappers and leaves their bodies alone, so an explicit withSpan() produces exactly one rich span instead of an additional automatic child. Named functions called from inside that explicit body remain eligible for automatic child spans.

The adapter rewrites eligible first-party functions because a build cannot reliably predict runtime calls through imports, dependency injection, callbacks, or virtual dispatch. Each rewritten function first checks the call-scoped runtime context. Outside trace() or withTrace(), it executes its original body directly without constructing span metadata, captured inputs, or an invocation closure. Destructured or defaulted arrow functions use a narrow function proxy so rich capture receives the original call arguments without rewriting parameter semantics; outside an active root, its apply trap invokes the original target immediately. Disabled or missing-key roots never request capture policy or activate the call-scoped context.

When server policy selects a function for rich capture, its input is the original argument array supplied at the call boundary. Object and array destructuring therefore preserve the complete argument rather than recording reconstructed bindings or a placeholder.

Unplugin build tools

All bundler exports are generated from the same Unplugin implementation and use the build tool's normal plugin array:

import bitfabTrace from "@bitfab/sdk/transform/vite"
import { defineConfig } from "vite"

export default defineConfig({ plugins: [bitfabTrace()] })

Use the corresponding subpath for Rollup, Rolldown, esbuild, Bun, webpack, Rspack, or Rsbuild. Vite-based React Router, Astro, Nuxt, and SvelteKit server modules use the Vite adapter. Functions embedded directly in .astro, .vue, or .svelte files are not yet instrumented.

Direct TypeScript execution

The registration hook instruments and transpiles ESM and CommonJS first-party modules inside the current working directory and enables their inline source maps:

node --import @bitfab/sdk/transform/register src/server.ts
node --import tsx --import @bitfab/sdk/transform/register src/server.ts

The Node loader resolves its injected runtime from the SDK available to the transform installation, including when shared packages do not depend on the SDK. To select a different application SDK installation, set BITFAB_SDK_RESOLVE_FROM to that application's package.json path:

BITFAB_SDK_RESOLVE_FROM=./packages/actor/package.json node --import @bitfab/sdk/transform/register packages/actor/src/server.ts

Run from the repository root to include shared packages in capture. This setting changes runtime resolution; the working directory still defines capture scope and relative function IDs. Both ESM and CommonJS use their respective SDK exports.

Projects that build with plain tsc should run the build through one of the bundler adapters or start Node with @bitfab/sdk/transform/register. Every adapter parses with Babel and needs Node 22.18 or later at build time.

Without an adapter, the root APIs remain valid and emit their normal rich root span. They simply cannot discover nested repository calls. The SDK prints one [bitfab] warning when a root finishes on Node in a build no adapter touched, naming the root and linking the documented installation steps. All adapters are experimental, and the generated function identity protocol may change.

Idle-path benchmark

Run pnpm bench:idle to compare an ordinary function with the common generated inactive in-body fast path. The benchmark alternates samples and reports median nanoseconds per call; it intentionally has no machine-dependent pass/fail threshold. It reports the destructured/defaulted-arrow proxy path separately from the common path so its additional inactive-call cost stays visible.

版本与发布记录

@bitfab/transform 共发布 7 个版本,首次发布于 2026/09/08;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.1.8latest2026/10/1524 天前
0.1.72026/10/1326 天前
0.1.62026/09/221 个月前
0.1.52026/09/191 个月前
0.1.42026/09/181 个月前
0.1.32026/09/082 个月前

关于 @bitfab/transform 的常见问题

@bitfab/transform 是什么?

Experimental build adapters for Bitfab automatic call tracing注意:该包已被作者标记为弃用——Deprecated: use @bitfab/sdk/transform/* instead (e.g. @bitfab/sdk/transform/next). Remove @bitfab/transform from your dependencies.

如何安装 @bitfab/transform?

在项目目录运行 npm install @bitfab/transform,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bitfab/sdk(>=0.60.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bitfab/transform 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bitfab/transform 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bitfab/transform 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bitfab/transform 可以商用吗?

@bitfab/transform 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bitfab/transform 的下载量有多少?

根据 npm 官方下载统计,@bitfab/transform 在 2026/10/08 – 2026/11/06 这 30 天内被下载 5,537 次,日均约 185 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bitfab/transform 还在维护吗?

最新版本 0.1.8 发布于 2026/10/15(24 天前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/09/08。作者已将其标记为弃用,新项目建议寻找替代方案。