MCPcopy
hub / github.com/kuma-ui/kuma-ui / compileSync

Function compileSync

packages/compiler/src/index.ts:13–64  ·  view source on GitHub ↗
({ code, id, wasm }: CompileArg)

Source from the content-addressed store, hash-verified

11};
12
13export const compileSync = ({ code, id, wasm }: CompileArg) => {
14 const result: { code: string; bindings: Record<string, string> } = {
15 code: "",
16 bindings: {},
17 };
18
19 if (wasm) {
20 const extension = (() => {
21 const ext = id.split(".").pop();
22 if (!ext) return "tsx";
23 switch (ext) {
24 case "ts":
25 return "ts";
26 case "tsx":
27 return "tsx";
28 case "js":
29 return "js";
30 case "jsx":
31 return "jsx";
32 default:
33 return "tsx";
34 }
35 })();
36
37 const { code: source_code, imports } = transformSync(code, extension);
38
39 result.code = source_code || "";
40 result.bindings = imports;
41 } else {
42 const transformed = babelTransformSync(code, {
43 filename: id,
44 sourceMaps: true,
45 plugins: [plugin],
46 });
47 if (!transformed || !transformed.code) return;
48 const bindings = (
49 transformed.metadata as unknown as { bindings: Record<string, string> }
50 ).bindings;
51 result.code = transformed.code || "";
52 result.bindings = bindings;
53 }
54
55 const compiled = compile(result.code, id, result.bindings);
56
57 const compiledResult = {
58 code: compiled.code,
59 css: sheet.getCSS() + compiled.css,
60 };
61
62 sheet.reset();
63 return compiledResult;
64};

Callers 5

kumaUiLoaderFunction · 0.90
transformFunction · 0.90
k.test.tsFile · 0.85
css.test.tsFile · 0.85

Calls 3

compileFunction · 0.90
getCSSMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected