@@ -6,6 +6,12 @@ import { bundleReactEmail } from './react-email-bundler';
66import { renderReactEmail } from './react-email-renderer' ;
77import { createSpinner } from './spinner' ;
88
9+ function cleanupTmpDir ( tmpDir : string | undefined ) {
10+ if ( tmpDir ) {
11+ rmSync ( tmpDir , { recursive : true , force : true } ) ;
12+ }
13+ }
14+
915/**
1016 * Bundles and renders a React Email template (.tsx) to an HTML string.
1117 * Shows spinners for each phase and exits with the appropriate error code on failure.
@@ -42,9 +48,11 @@ export async function buildReactEmailHtml(
4248 try {
4349 const html = await renderReactEmail ( result . cjsPath ) ;
4450 renderSpinner . stop ( 'Rendered React Email template' ) ;
51+ cleanupTmpDir ( tmpDir ) ;
4552 return html ;
4653 } catch ( err ) {
4754 renderSpinner . fail ( 'Failed to render React Email template' ) ;
55+ cleanupTmpDir ( tmpDir ) ;
4856 return outputError (
4957 {
5058 message : errorMessage ( err , 'Failed to render React Email template' ) ,
@@ -55,16 +63,13 @@ export async function buildReactEmailHtml(
5563 }
5664 } catch ( err ) {
5765 spinner . fail ( 'Failed to bundle React Email template' ) ;
66+ cleanupTmpDir ( tmpDir ) ;
5867 return outputError (
5968 {
6069 message : errorMessage ( err , 'Failed to bundle React Email template' ) ,
6170 code : 'react_email_build_error' ,
6271 } ,
6372 { json : globalOpts . json } ,
6473 ) ;
65- } finally {
66- if ( tmpDir ) {
67- rmSync ( tmpDir , { recursive : true , force : true } ) ;
68- }
6974 }
7075}
0 commit comments