@@ -2,6 +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 { tmpdir } from "os" ;
5
6
import * as esbuild from "esbuild" ;
6
7
7
8
import { render } from "@react-email/render" ;
@@ -33,8 +34,8 @@ export async function renderOpenEmailFile(
33
34
const currentlyOpenTabFilePath = activeEditor . document . fileName ; // actually a path not the name of the file
34
35
const currentlyOpenTabFilename = basename ( currentlyOpenTabFilePath , ".tsx" ) ;
35
36
36
- const emailsDirectory = join ( currentlyOpenTabFilePath , ".." ) ;
37
- const previewDirectory = join ( emailsDirectory , extensionPreviewFolder ) ;
37
+ // saves the temporary previews generated in the tmp folder
38
+ const previewDirectory = join ( tmpdir ( ) , extensionPreviewFolder ) ;
38
39
39
40
// this hash is needed so the the import doesn't get from its cache
40
41
const renderingHash = crypto . randomBytes ( 20 ) . toString ( "hex" ) ;
@@ -45,23 +46,14 @@ export async function renderOpenEmailFile(
45
46
) ;
46
47
47
48
try {
48
- const buildResult = esbuild . buildSync ( {
49
+ await esbuild . build ( {
49
50
bundle : true ,
50
51
entryPoints : [ currentlyOpenTabFilePath ] ,
51
52
platform : 'node' ,
52
53
write : true ,
53
54
tsconfig : join ( __dirname , '..' , 'tsconfig.emails.json' ) ,
54
55
outfile : builtFileWithCurrentContents ,
55
56
} ) ;
56
- if ( buildResult . warnings . length > 0 ) {
57
- console . warn ( buildResult . warnings ) ;
58
- }
59
- if ( buildResult . errors . length > 0 ) {
60
- console . error ( buildResult . errors ) ;
61
- throw new Error (
62
- `esbuild bundling process for email at ${ currentlyOpenTabFilePath } \n\n${ buildResult . errors } ` ,
63
- ) ;
64
- }
65
57
66
58
// for future people debugging this: if this doesnt update the preview, might be because import keeps a cache
67
59
// and the hash is not being unique (unlikely though)
0 commit comments