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

rolldown-plugin-access-privates

v0.1.3

Published

Rolldown Plugin to add accessors for class Private Fields

Readme

rolldown-plugin-access-privates

A Rolldown plugin that enables access to class private members (#field, #method()) during bundling by transforming matched modules. This might be useful to set up a specific condition for testing (for example with vitest).

Installation

# npm
npm install -D rolldown-plugin-access-privates
# pnpm
pnpm add -D rolldown-plugin-access-privates
# yarn
yarn add -D rolldown-plugin-access-privates

Usage with vitest

This setup ensures that the plugin is only active during testing.

// vitest.config.ts
import { defineConfig } from 'vitest/config';
import accessPrivates from 'rolldown-plugin-access-privates';

export default defineConfig(({mode}) => {
  plugins: mode === 'test' ? [accessPrivates()] : [],
});

Options

An optional object to configure the plugin's behavior. All options are optional and have sensible defaults.

type options = {
  /**
   * Whether to export all top-level variables, functions, and classes in the module.
   * Can be an array of "variable", "function", and "class", or a function that will
   * be called with the module ID and AST node of each variable, function, or class
   * declaration.
   * @default true
   */
  exports?: ("variable" | "function" | "class")[] | boolean | ((id: string, astNode: ESTree.VariableDeclaration | ESTree.Function | ESTree.Class) => boolean) | undefined;
  /**
   * Which class members to generate accessors for.
   * Can be an array of "method", "get", "set", and "property", or a function that will
   * be called with the module ID and AST node of each method or property definition.
   * @default true
   */
  classMembers?: ("method" | "get" | "set" | "property")[] | boolean | ((id: string, astNode: ESTree.MethodDefinition | ESTree.PropertyDefinition) => boolean) | undefined;
  /**
   * The suffix to use for the generated accessors.
   * For example, if you have a private field `#foo`, the plugin will generate
   * `fooPrivate` getter and setter.
   * @default "Private"
   */
  suffix?: string | ((name: string) => string) | undefined;
  /**
   * Filter for which modules the plugin should apply.
   * Can be a string, a RegExp, an array of strings and RegExps, or an object with an
   * `include` and `exclude` property, each of which can be a string, a RegExp, or an
   * array of strings and RegExps.
   * The filter will be applied to the module ID.
   * @default /\.[jt]sx?$/
   */
  idFilter?: HookFilter["id"] | undefined;
};

/**
 * From Rolldown:
 * A filter based on the module `id`.
 *
 * If the value is a string, it is treated as a glob pattern.
 * The string type is not available for {@linkcode Plugin.resolveId | resolveId} hook.
 *
 * @example
 * Include all `id`s that contain `node_modules` in the path.
 * ```js
 * { id: '**'+'/node_modules/**' }
 * ```
 * @example
 * Include all `id`s that contain `node_modules` or `src` in the path.
 * ```js
 * { id: ['**'+'/node_modules/**', '**'+'/src/**'] }
 * ```
 * @example
 * Include all `id`s that start with `http`
 * ```js
 * { id: /^http/ }
 * ```
 * @example
 * Exclude all `id`s that contain `node_modules` in the path.
 * ```js
 * { id: { exclude: '**'+'/node_modules/**' } }
 * ```
 * @example
 * Formal pattern to define includes and excludes.
 * ```js
 * { id : {
 *   include: ['**'+'/foo/**', /bar/],
 *   exclude: ['**'+'/baz/**', /qux/]
 * }}
 * ```
 */
type GeneralHookFilter =
  | string
  | RegExp
  | (string | RegExp)[]
  | {
      include?: string | RegExp | (string | RegExp)[];
      exclude?: string | RegExp | (string | RegExp)[];
    };

Example

With the default configuration, the plugin will transform code like this:

let globalCounter = 0;
function reset() {
  globalCounter = 0;
}
class Counter {
  #value = 0;
  #reset() {
    this.#value = 0;
  }
  inc() {
    this.#value++;
    globalCounter++;
  }
}

Into this:

export let globalCounter = 0;
export function reset() {
  globalCounter = 0;
}
export class Counter {
  static get #globalCounter() {
    return globalCounter;
  }
  static get globalCounterPrivate() {
    return this.#globalCounter;
  }
  #value = 0;
  get valuePrivate() {
    return this.#value;
  }
  set valuePrivate(value) {
    this.#value = value;
  }
  #reset() {
    this.#value = 0;
  }
  get resetPrivate() {
    return this.#reset;
  }
  inc() {
    this.#value++;
    globalCounter++;
  }
}