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

@nativewrappers/protogen

v0.0.1

Published

Protocol Buffer code generator for TypeScript with esbuild and Vite plugins

Readme

@nativewrappers/protogen

A Protocol Buffer code generator for TypeScript. Generates static encode/decode functions from .proto files as an esbuild plugin.

Installation

pnpm add @nativewrappers/protogen protobufjs

Usage

esbuild Plugin

import esbuild from "esbuild";
import { protogenPlugin } from "@nativewrappers/protogen";

await esbuild.build({
  entryPoints: ["src/**/*.ts"],
  outdir: "dist",
  plugins: [
    protogenPlugin({
      protoDirs: ["./src/protos"],
      watch: true, // Enable watching .proto files
    }),
  ],
});

Vite Plugin

import { defineConfig } from "vite";
import { protogenVitePlugin } from "@nativewrappers/protogen/vite";

export default defineConfig({
  plugins: [
    protogenVitePlugin({
      protoDirs: ["./src/protos"],
    }),
  ],
});

Both plugins generate _pb.ts files from .proto files at build start. In watch/dev mode, they automatically regenerate when proto files change.

Generated Code

For proto files:

message ProtoVec3 {
  float x = 1;
  float y = 2;
  float z = 3;
}

message ProtoNetVehicle {
  int32 net_id = 1;
}

The generator produces:

import { Reader, Writer } from "protobufjs/minimal.js";

export type Vec3 = {
  x: number;
  y: number;
  z: number;
};

export const ProtoVec3 = {
  name: "ProtoVec3" as const,
  encode: (msg: Vec3): Uint8Array => { ... },
  decode: (bytes: Uint8Array): Vec3 => { ... },
  create: (data?: Partial<Vec3>): Vec3 => ({ ... }),
};

export type NetVehicle = {
  net_id: number;
};

export const ProtoNetVehicle = {
  name: "ProtoNetVehicle" as const,
  encode: (msg: NetVehicle): Uint8Array => { ... },
  decode: (bytes: Uint8Array): NetVehicle => { ... },
  create: (data?: Partial<NetVehicle>): NetVehicle => ({ ... }),
};

Importing Generated Code

import { ProtoVec3, ProtoNetVehicle } from "./protos/Types_pb";

const bytes = ProtoVec3.encode({ x: 1.0, y: 2.5, z: 3.0 });
const position = ProtoVec3.decode(bytes);

Configuration

Plugin Options

protogenPlugin({
  // Directories containing .proto files
  protoDirs: ["./src/protos"],

  // Output file suffix (default: "_pb.ts")
  suffix: "_pb.ts",

  // Include 'name' field in output (default: true)
  generateName: true,

  // Include 'create' method (default: true)
  generateCreate: true,

  // Field naming: "snake" or "camel" (default: "snake")
  fieldCase: "snake",

  // Custom decode transforms
  transforms: {},
});

Minimal Output

protogenPlugin({
  protoDirs: ["./src/protos"],
  generateName: false,
  generateCreate: false,
});

Generates only encode and decode:

export const ProtoVec3 = {
  encode: (msg: Vec3): Uint8Array => { ... },
  decode: (bytes: Uint8Array): Vec3 => { ... },
};

Transforms

Wrap decoded messages in custom classes:

protogenPlugin({
  protoDirs: ["./src/protos"],
  transforms: {
    ProtoVec3: {
      import: "@nativewrappers/common",
      importName: "Vector3",
      returnType: "Vector3",
      transform: (msg) => `new Vector3(${msg}.x, ${msg}.y, ${msg}.z)`,
    },
    ProtoNetVehicle: {
      import: "@nativewrappers/redm",
      importName: "Vehicle",
      returnType: "Vehicle | null",
      transform: (msg) => `Vehicle.fromNetId(${msg}.net_id)`,
    },
  },
});

With transforms, the generated code changes to:

import { Reader, Writer } from "protobufjs/minimal.js";
import { Vector3 } from "@nativewrappers/common";
import { Vehicle } from "@nativewrappers/redm";

export const ProtoVec3 = {
  name: "ProtoVec3" as const,
  encode: (msg: Vec3): Uint8Array => { ... },
  decode: (bytes: Uint8Array): Vector3 => {
    // ... decodes to raw Vec3, then:
    return new Vector3(message.x, message.y, message.z);
  },
};

export const ProtoNetVehicle = {
  name: "ProtoNetVehicle" as const,
  encode: (msg: NetVehicle): Uint8Array => { ... },
  decode: (bytes: Uint8Array): Vehicle | null => {
    // ... decodes to raw NetVehicle, then:
    return Vehicle.fromNetId(message.net_id);
  },
};

Build Setup

For projects needing .d.ts declarations:

{
  "scripts": {
    "build": "node build.js && tsc --emitDeclarationOnly"
  }
}

Supported Types

| Proto Type | TypeScript Type | |------------|-----------------| | double, float | number | | int32, uint32, sint32, fixed32, sfixed32 | number | | int64, uint64, sint64, fixed64, sfixed64 | bigint | | bool | boolean | | string | string | | bytes | Uint8Array | | enum | enum | | message | type | | repeated T | T[] |

License

This is free and unencumbered software released into the public domain. See LICENSE for details.