vargai 0.4.0-alpha7 → 0.4.0-alpha8
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 +10 -4
package/package.json
CHANGED
|
@@ -19,21 +19,27 @@ async function loadComponent(filePath: string): Promise<VargElement> {
|
|
|
19
19
|
source.includes("from '@vargai") ||
|
|
20
20
|
source.includes('from "@vargai');
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const hasJsxPragma =
|
|
23
|
+
source.includes("@jsxImportSource") || source.includes("@jsx ");
|
|
24
|
+
|
|
25
|
+
if (hasImports && hasJsxPragma) {
|
|
23
26
|
const mod = await import(resolvedPath);
|
|
24
27
|
return mod.default;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
const tmpDir =
|
|
30
|
+
const tmpDir = `${process.cwd()}/.cache/varg-render`;
|
|
28
31
|
if (!existsSync(tmpDir)) {
|
|
29
32
|
mkdirSync(tmpDir, { recursive: true });
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
const prepended = hasImports
|
|
36
|
+
? `/** @jsxImportSource vargai */\n`
|
|
37
|
+
: AUTO_IMPORTS;
|
|
32
38
|
const tmpFile = `${tmpDir}/${Date.now()}.tsx`;
|
|
33
|
-
await Bun.write(tmpFile,
|
|
39
|
+
await Bun.write(tmpFile, prepended + source);
|
|
34
40
|
|
|
35
41
|
try {
|
|
36
|
-
const mod = await import(
|
|
42
|
+
const mod = await import(tmpFile);
|
|
37
43
|
return mod.default;
|
|
38
44
|
} finally {
|
|
39
45
|
(await Bun.file(tmpFile).exists()) && (await Bun.write(tmpFile, ""));
|