vargai 0.4.0-alpha23 → 0.4.0-alpha24
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.
- package/package.json +1 -1
- package/src/cli/commands/render.tsx +27 -12
package/package.json
CHANGED
|
@@ -36,29 +36,44 @@ async function loadComponent(filePath: string): Promise<VargElement> {
|
|
|
36
36
|
const resolvedPath = resolve(filePath);
|
|
37
37
|
const source = await Bun.file(resolvedPath).text();
|
|
38
38
|
|
|
39
|
-
const hasAnyImport = source.includes(" from ");
|
|
40
39
|
const hasVargaiImport =
|
|
41
40
|
source.includes("from 'vargai") ||
|
|
42
41
|
source.includes('from "vargai') ||
|
|
43
|
-
source.includes("
|
|
44
|
-
source.includes('from "@vargai');
|
|
45
|
-
|
|
46
|
-
const hasJsxPragma =
|
|
47
|
-
source.includes("@jsxImportSource") || source.includes("@jsx ");
|
|
42
|
+
source.includes("@jsxImportSource vargai");
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const mod = await import(resolvedPath);
|
|
52
|
-
return mod.default;
|
|
53
|
-
}
|
|
44
|
+
const hasRelativeImport =
|
|
45
|
+
source.includes("from './") || source.includes('from "./');
|
|
54
46
|
|
|
55
|
-
// no imports - inject auto-imports and jsx pragma
|
|
56
47
|
const pkgDir = new URL("../../..", import.meta.url).pathname;
|
|
57
48
|
const tmpDir = `${pkgDir}/.cache/varg-render`;
|
|
49
|
+
|
|
58
50
|
if (!existsSync(tmpDir)) {
|
|
59
51
|
mkdirSync(tmpDir, { recursive: true });
|
|
60
52
|
}
|
|
61
53
|
|
|
54
|
+
if (hasRelativeImport) {
|
|
55
|
+
const mod = await import(resolvedPath);
|
|
56
|
+
return mod.default;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (hasVargaiImport) {
|
|
60
|
+
const tmpFile = `${tmpDir}/${Date.now()}.tsx`;
|
|
61
|
+
await Bun.write(tmpFile, source);
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const mod = await import(tmpFile);
|
|
65
|
+
return mod.default;
|
|
66
|
+
} finally {
|
|
67
|
+
(await Bun.file(tmpFile).exists()) && (await Bun.write(tmpFile, ""));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const hasAnyImport = source.includes(" from ");
|
|
72
|
+
if (hasAnyImport) {
|
|
73
|
+
const mod = await import(resolvedPath);
|
|
74
|
+
return mod.default;
|
|
75
|
+
}
|
|
76
|
+
|
|
62
77
|
const tmpFile = `${tmpDir}/${Date.now()}.tsx`;
|
|
63
78
|
await Bun.write(tmpFile, AUTO_IMPORTS + source);
|
|
64
79
|
|