aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-plugin-yaml/index.ts
blob: e8b2ae6cd925daf30b39a4944b46eb2680e5e2e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { BunPlugin } from "bun";
import { readFileSync } from "fs";
import { load } from "js-yaml";

function YamlPlugin(): BunPlugin {
  return {
    name: "bun-plugin-yaml",
    setup(builder) {
      builder.onLoad({ filter: /\.(yaml|yml)$/ }, args => {
        const text = readFileSync(args.path, "utf8");
        const exports = load(text) as Record<string, any>;
        return {
          exports,
          loader: "object",
        };
      });
    },
  };
}

export default YamlPlugin;