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

@mochi-css/plugins

v7.0.0

Published

This package is part of the [Mochi-CSS project](https://github.com/Niikelion/mochi-css). It provides `createExtractorsPlugin` — the standard bridge between `StyleExtractor` instances and the `Builder` pipeline — along with re-exports of commonly needed bu

Downloads

502

Readme

🧁 Mochi-CSS/plugins

This package is part of the Mochi-CSS project. It provides createExtractorsPlugin — the standard bridge between StyleExtractor instances and the Builder pipeline — along with re-exports of commonly needed builder types for plugin authors.

Note: You only need this package when building custom integrations or writing plugins that wire extractors into the builder. Normal users configure extractors via mochi.config.ts using packages like @mochi-css/vanilla/config.


Installation

npm i @mochi-css/plugins --save-dev

createExtractorsPlugin

Packages a list of StyleExtractor instances as a MochiPlugin. When loaded, the plugin:

  • Registers the analysis pipeline stages needed for the given extractors
  • Registers a sourceTransforms hook that sets up per-build generators and injects them as eval-time globals
  • Registers an emitHook that calls generateStyles() on each generator and emits CSS via context.emitChunk(); also applies any AST arg replacements returned by getArgReplacements()
import { createExtractorsPlugin } from "@mochi-css/plugins"
import { mochiCssFunctionExtractor, mochiGlobalCssFunctionExtractor, mochiKeyframesFunctionExtractor } from "@mochi-css/vanilla/config"
import { FullContext } from "@mochi-css/config"
import { Builder, RolldownBundler, VmRunner } from "@mochi-css/builder"

const extractors = [mochiCssFunctionExtractor, mochiGlobalCssFunctionExtractor, mochiKeyframesFunctionExtractor]
const ctx = new FullContext(onDiagnostic)
createExtractorsPlugin(extractors).onLoad(ctx)

const builder = new Builder({
    roots: ["./src"],
    stages: [...ctx.stages.getAll()],
    bundler: new RolldownBundler(),
    runner: new VmRunner(),
    sourceTransforms: [...ctx.sourceTransforms.getAll()],
    emitHooks: [...ctx.emitHooks.getAll()],
    emitDir: "./dist/mochi",
    cleanup: () => ctx.cleanup.runAll(),
})

When integrations load mochi.config.ts, createExtractorsPlugin is typically called inside a higher-level plugin (e.g. the one returned by @mochi-css/vanilla/config's defineConfig) — you don't need to call it manually.


PluginContextCollector

A lightweight alternative to FullContext (from @mochi-css/config) for collecting plugin hooks without the file pre-process pipeline. Useful for unit-testing plugins or building minimal integrations.

import { PluginContextCollector } from "@mochi-css/plugins"

const collector = new PluginContextCollector(onDiagnostic)
myPlugin.onLoad(collector)

const builder = new Builder({
    stages: [...collector.getStages()],
    sourceTransforms: [...collector.getSourceTransforms()],
    emitHooks: [...collector.getEmitHooks()],
    cleanup: () => collector.runCleanup(),
    // ...
})

| Method | Returns | | ----------------------- | -------------------------------------- | | getStages() | readonly StageDefinition[] | | getSourceTransforms() | AstPostProcessor[] | | getEmitHooks() | EmitHook[] | | runCleanup() | calls all registered cleanup functions |


StyleExtractor and StyleGenerator

Implement these to support a new style function. StyleGenerator is an abstract class — all subclasses must implement mockFunction, which is called during bundle execution to produce the runtime return value.

import type { StyleExtractor, StyleGenerator } from "@mochi-css/plugins"
import type { OnDiagnostic } from "@mochi-css/core"

class MyGenerator extends StyleGenerator {
    override mockFunction(...args: unknown[]): unknown {
        return args[0]
    }

    collectArgs(source: string, args: unknown[]): void { ... }

    async generateStyles() {
        return { global: "..." }
    }
}

const myExtractor: StyleExtractor = {
    importPath: "my-css-lib",
    symbolName: "myStyle",
    extractStaticArgs(call) { return call.arguments.map((a) => a.expression) },
    startGeneration(onDiagnostic?: OnDiagnostic) { return new MyGenerator() },
}

Stage definitions

The default analysis pipeline stages are exported as static const values:

import {
    importStageDef,
    derivedStageDef,
    styleExprStageDef,
    bindingStageDef,
    crossFileDerivedStageDef,
    exportsStage,
} from "@mochi-css/plugins"

exportsStage tracks per-file reexports and is registered automatically by createExtractorsPlugin.


Utilities

import {
    extractRelevantSymbols,
    propagateUsagesFromRef,
    propagateUsagesFromExpr,
    getOrInsert,
    isLocalImport,
} from "@mochi-css/plugins"
import type { ReexportResolver } from "@mochi-css/plugins"
  • propagateUsagesFromExpr / propagateUsagesFromRef — walk an expression or a binding ref and mark all reachable bindings as used. Accept an optional ReexportResolver for cross-barrel propagation.
  • getOrInsertMap helper: return existing value or compute and insert a new one.
  • isLocalImport — returns true for ./ and ../ import paths.

Re-exports from @mochi-css/builder

Commonly needed builder types re-exported for convenience:

  • AstPostProcessor, EmitHook, BuilderOptions, RootEntry, StageDefinition