@@ -2,7 +2,7 @@ import * as vscode from "vscode";
2
2
3
3
import * as crypto from "crypto" ;
4
4
import { basename , join } from "path" ;
5
- import { unlink , writeFile } from "fs/promises " ;
5
+ import { unlinkSync , writeFileSync } from "fs" ;
6
6
import * as esbuild from "esbuild" ;
7
7
8
8
import { render } from "@react-email/render" ;
@@ -18,19 +18,15 @@ export type BuiltEmail =
18
18
}
19
19
| { valid : false } ;
20
20
21
- let isBuilding = false ;
22
-
23
- export async function renderOpenEmailFile (
21
+ export function renderOpenEmailFile (
24
22
activeEditor : vscode . TextEditor | undefined ,
25
- ) : Promise < BuiltEmail | undefined > {
26
- if ( typeof activeEditor !== "undefined" && ! isBuilding ) {
27
- isBuilding = true ;
23
+ ) : BuiltEmail | undefined {
24
+ if ( typeof activeEditor !== "undefined" ) {
28
25
if (
29
26
typeof activeEditor . document . fileName === "undefined" ||
30
27
activeEditor . document . fileName . length === 0 ||
31
28
activeEditor . document . getText ( ) . length === 0
32
29
) {
33
- isBuilding = false ;
34
30
return { valid : false } ;
35
31
}
36
32
@@ -51,7 +47,7 @@ export async function renderOpenEmailFile(
51
47
`${ currentlyOpenTabFilename } -${ renderingHash } .vscpreview.tsx` ,
52
48
) ;
53
49
const currentContents = activeEditor . document . getText ( ) ;
54
- await writeFile (
50
+ writeFileSync (
55
51
currentlyOpenTabFilesPathWithCurrentContents ,
56
52
currentContents ,
57
53
) ;
@@ -62,23 +58,19 @@ export async function renderOpenEmailFile(
62
58
) ;
63
59
64
60
try {
65
- await esbuild . build ( {
61
+ esbuild . buildSync ( {
66
62
bundle : true ,
67
63
entryPoints : [ currentlyOpenTabFilesPathWithCurrentContents ] ,
68
64
platform : "node" ,
69
65
write : true ,
70
66
outfile : builtFileWithCurrentContents ,
71
67
} ) ;
72
68
73
- await unlink ( currentlyOpenTabFilesPathWithCurrentContents ) ;
74
-
75
69
delete require . cache [ builtFileWithCurrentContents ] ;
76
70
// we need to use require since it has a way to programatically invalidate its cache
77
71
const email = require ( builtFileWithCurrentContents ) ;
78
72
79
73
if ( typeof email . default === "undefined" ) {
80
- isBuilding = false ;
81
-
82
74
// this means there is no "export default ..." in the file
83
75
return { valid : false } ;
84
76
}
@@ -91,9 +83,8 @@ export async function renderOpenEmailFile(
91
83
92
84
const emailAsHTML = render ( comp , { pretty : false } ) ;
93
85
94
- await unlink ( builtFileWithCurrentContents ) ;
95
-
96
- isBuilding = false ;
86
+ unlinkSync ( builtFileWithCurrentContents ) ;
87
+ unlinkSync ( currentlyOpenTabFilesPathWithCurrentContents ) ;
97
88
98
89
return {
99
90
filename : currentlyOpenTabFilename ,
@@ -102,8 +93,6 @@ export async function renderOpenEmailFile(
102
93
valid : true ,
103
94
} ;
104
95
} catch ( exception ) {
105
- isBuilding = false ;
106
-
107
96
console . warn (
108
97
"Exception happenned on rendering or building of an email, but maybe its because it just was invalid anyways" ,
109
98
exception ,
@@ -113,7 +102,5 @@ export async function renderOpenEmailFile(
113
102
}
114
103
}
115
104
116
- isBuilding = false ;
117
-
118
105
return undefined ;
119
106
}
0 commit comments