Skip to content

wrapWithMeta

A preset that can be used to find call expressions such as foo(), new Foo(), or foo.bar.baz() and wrap them using withMeta.

source.ts
ts
import { getMeta } from "@monstermann/meta";

function runExample() {
    const meta = getMeta();
    // { path: "source.ts", line: 9, name: "example" }
    console.log(meta);
}

const example = runExample();
Rolldown
ts
import meta, { wrapWithMeta } from "@monstermann/unplugin-meta/rolldown";

export default {
    plugins: [
        meta({
            resolve: wrapWithMeta(["runExample"]),
        }),
    ],
};
Output
ts
import { getMeta } from "@monstermann/meta";
import { withMeta } from "@monstermann/meta";
const path = "source.ts";
const meta = { path, line: 9, name: "example" };

function runExample() {
    const meta = getMeta();
    // { path: "source.ts", line: 10, name: "example" }
    console.log(meta);
}

const example = runExample();
const example = withMeta(meta, () => runExample());