unplugin-saykit 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { relative } from "node:path";
3
- import { assembleCatalogueRecord, resolveCatalogueSources } from "@saykit/config/features/catalogue";
4
- import { resolveConfig } from "@saykit/config/features/loader";
5
- import { createUnplugin } from "unplugin";
6
- //#region src/index.ts
7
- var src_default = createUnplugin((_options) => {
8
- const config = resolveConfig();
9
- return {
10
- name: "saykit",
11
- enforce: "pre",
12
- transform: {
13
- filter: { id: { exclude: /node_modules/ } },
14
- handler: (code, id_) => {
15
- const id = relative(process.cwd(), id_).replaceAll("\\", "/").split("?")[0];
16
- return config.buckets.find((b) => b.match(id))?.transformer.transform(code, id) ?? code;
17
- }
18
- },
19
- load: {
20
- filter: { id: { exclude: /node_modules/ } },
21
- handler: async function(id_) {
22
- const id = relative(process.cwd(), id_).replaceAll("\\", "/").split("?")[0];
23
- const bucket = config.buckets.find((b) => b.output.match(id));
24
- if (!bucket) return;
25
- const { sources } = resolveCatalogueSources(config, bucket, id);
26
- const contents = await Promise.all(sources.map((source) => readFile(source, "utf8").catch(() => "")));
27
- for (const source of sources) this.addWatchFile?.(source);
28
- const record = assembleCatalogueRecord(bucket, contents);
29
- if (id.endsWith(".json")) return JSON.stringify(record);
30
- return `export default ${JSON.stringify(record)}`;
31
- }
32
- }
33
- };
34
- });
35
- //#endregion
36
- export { src_default as t };