MCPcopy Create free account
hub / github.com/Borrus-sudo/tinypages / pluginKit

Function pluginKit

packages/vite/src/node/plugin.ts:3–51  ·  view source on GitHub ↗
(plugins: FrameworkModule[])

Source from the content-addressed store, hash-verified

1import type { FrameworkModule, TinyPagesConfig } from "../../types/types";
2
3export function pluginKit(plugins: FrameworkModule[]) {
4 const pre: FrameworkModule[] = [];
5 const post: FrameworkModule[] = [];
6 const mainplugins: FrameworkModule[] = [];
7 plugins.forEach((p) => {
8 if (p.enforce === "pre") {
9 pre.push(p);
10 } else if (p.enforce === "post") {
11 post.push(p);
12 } else {
13 mainplugins.push(p);
14 }
15 });
16 const modules: FrameworkModule[] = [...pre, ...mainplugins, ...post];
17 return {
18 async defineConfig(c: TinyPagesConfig) {
19 for (let m of modules) {
20 await m?.defineConfig(c);
21 }
22 },
23 resolveComponentPath(path: string): string {
24 for (let m of modules) {
25 const new_path = m?.resolveComponentPath(path);
26 if (new_path) {
27 return new_path;
28 }
29 }
30 return "";
31 },
32 async editEntryFile(id: string, code: string) {
33 for (let m of modules) {
34 const new_code = await m?.editEntryFile(id, code);
35 if (new_code) {
36 code = new_code;
37 }
38 }
39 return code;
40 },
41 async renderComponent(c, extra) {
42 for (let m of modules) {
43 const stringifiedComponent = await m?.renderComponent(c, extra);
44 if (stringifiedComponent) {
45 return stringifiedComponent;
46 }
47 }
48 return "";
49 },
50 };
51}

Callers 2

createDevContextFunction · 0.90
createBuildContextFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected