Skip to content

Commit b3b0a00

Browse files
committed
feat (vs-code-ext): build async and save the previews on the os's temp folder
1 parent b0820b2 commit b3b0a00

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

vs-code-extension/src/renderOpenEmailFile.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22

33
import * as crypto from "crypto";
44
import { basename, join } from "path";
5+
import { tmpdir } from "os";
56
import * as esbuild from "esbuild";
67

78
import { render } from "@react-email/render";
@@ -33,8 +34,8 @@ export async function renderOpenEmailFile(
3334
const currentlyOpenTabFilePath = activeEditor.document.fileName; // actually a path not the name of the file
3435
const currentlyOpenTabFilename = basename(currentlyOpenTabFilePath, ".tsx");
3536

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);
3839

3940
// this hash is needed so the the import doesn't get from its cache
4041
const renderingHash = crypto.randomBytes(20).toString("hex");
@@ -45,23 +46,14 @@ export async function renderOpenEmailFile(
4546
);
4647

4748
try {
48-
const buildResult = esbuild.buildSync({
49+
await esbuild.build({
4950
bundle: true,
5051
entryPoints: [currentlyOpenTabFilePath],
5152
platform: 'node',
5253
write: true,
5354
tsconfig: join(__dirname, '..', 'tsconfig.emails.json'),
5455
outfile: builtFileWithCurrentContents,
5556
});
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-
}
6557

6658
// for future people debugging this: if this doesnt update the preview, might be because import keeps a cache
6759
// and the hash is not being unique (unlikely though)

0 commit comments

Comments
 (0)