Skip to content

signals

Minified15.71 KBMinzipped4.82 KB

A fork of @preact/signals-core with a series of useful additions and a stronger focus on debugging tools.

Meta

This library features an unplugin that decorates code with additional metadata and hot module reloading setups, using the fast Oxidation Compiler.

In combination with debugging events this can greatly help with debugging, or things such as measuring performance.

ts
import { signal } from "@monstermann/signals";

const count = signal(0);

console.log(count.meta);
ts
type Meta = {
    // A name for this entity, as determined by unplugin-signals.
    // It will derive this by looking at variable names, object keys, etc.,
    // but it can also be manually configured.
    name: string;
    // The file path to this entity.
    path: string;
    // The line number of this entity.
    line: number;
    // A globally incremented id that can be used to reference this entity.
    id: number;
    // Whether this entity should be considered to be an implementation detail.
    // If set to `true`, it will not emit any debugging events, and will not be
    // accessible by eg. `getSignals()`. Takes precedence over `silent`.
    internal: boolean;
    // Whether this entity should emit any debugging events.
    silent: boolean;
    // A generic name for this entity, eg. `Signal`, `Memo`, `Effect`.
    kind: string;
};

Installation

sh
npm install @monstermann/signals
sh
pnpm add @monstermann/signals
sh
yarn add @monstermann/signals
sh
bun add @monstermann/signals

Unplugin

Installation

sh
npm install -D @monstermann/unplugin-signals
sh
pnpm -D add @monstermann/unplugin-signals
sh
yarn -D add @monstermann/unplugin-signals
sh
bun -D add @monstermann/unplugin-signals

Usage

ts
// vite.config.ts
import signals from "@monstermann/unplugin-signals/vite";

export default defineConfig({
    plugins: [signals()],
});
ts
// rollup.config.js
import signals from "@monstermann/unplugin-signals/rollup";

export default {
    plugins: [signals()],
};
ts
// rolldown.config.js
import signals from "@monstermann/unplugin-signals/rolldown";

export default {
    plugins: [signals()],
};
ts
// webpack.config.js
const signals = require("@monstermann/unplugin-signals/webpack");

module.exports = {
    plugins: [signals()],
};
ts
// rspack.config.js
const signals = require("@monstermann/unplugin-signals/rspack");

module.exports = {
    plugins: [signals()],
};
ts
// esbuild.config.js
import { build } from "esbuild";
import signals from "@monstermann/unplugin-signals/esbuild";

build({
    plugins: [signals()],
});

Options

See @monstermann/meta for a description of these options.

ts
{
    enforce?: "post" | "pre" | undefined
    exclude?: FilterPattern
    include?: FilterPattern
    hmr?: boolean;
    getName?: (name: string, node: Node, meta: Meta) => string;
    getPath?: (path: string, meta: Meta) => string;
}