@@ -12,17 +12,17 @@ export function get_global_types(
1212 typesPath : string ,
1313 hiddenFolderPath ?: string
1414) : string [ ] {
15- const svelteHtmlPath = isSvelte3 ? undefined : join ( sveltePath , 'svelte-html.d.ts' ) ;
16- const svelteHtmlPathExists = svelteHtmlPath && tsSystem . fileExists ( svelteHtmlPath ) ;
17- const svelteHtmlFile = svelteHtmlPathExists ? svelteHtmlPath : './svelte-jsx-v4.d.ts' ;
15+ let svelteHtmlPath = isSvelte3 ? undefined : join ( sveltePath , 'svelte-html.d.ts' ) ;
16+ svelteHtmlPath =
17+ svelteHtmlPath && tsSystem . fileExists ( svelteHtmlPath ) ? svelteHtmlPath : undefined ;
1818
1919 let svelteTsxFiles : string [ ] ;
2020 if ( isSvelte3 ) {
2121 svelteTsxFiles = [ './svelte-shims.d.ts' , './svelte-jsx.d.ts' , './svelte-native-jsx.d.ts' ] ;
2222 } else {
2323 svelteTsxFiles = [ './svelte-shims-v4.d.ts' , './svelte-native-jsx.d.ts' ] ;
24- if ( ! svelteHtmlPathExists ) {
25- svelteTsxFiles . push ( svelteHtmlPath ) ;
24+ if ( ! svelteHtmlPath ) {
25+ svelteTsxFiles . push ( './svelte-jsx-v4.d.ts' ) ;
2626 }
2727 }
2828 svelteTsxFiles = svelteTsxFiles . map ( ( f ) => tsSystem . resolvePath ( resolve ( typesPath , f ) ) ) ;
@@ -53,19 +53,29 @@ export function get_global_types(
5353 for ( const f of svelteTsxFiles ) {
5454 const hiddenFile = resolve ( hiddenPath , basename ( f ) ) ;
5555 const existing = tsSystem . readFile ( hiddenFile ) ;
56- const toWrite = tsSystem . readFile ( f ) || '' ;
56+ const toWrite = tsSystem . readFile ( f ) ;
57+
58+ if ( ! toWrite ) {
59+ throw new Error ( `Could not read file: ${ f } ` ) ;
60+ }
61+
5762 if ( existing !== toWrite ) {
5863 tsSystem . writeFile ( hiddenFile , toWrite ) ;
64+ // TS doesn't throw an error if the file wasn't written
65+ if ( ! tsSystem . fileExists ( hiddenFile ) ) {
66+ throw new Error ( `Could not write file: ${ hiddenFile } ` ) ;
67+ }
5968 }
69+
6070 newFiles . push ( hiddenFile ) ;
6171 }
6272 svelteTsxFiles = newFiles ;
6373 }
6474 } catch ( e ) { }
6575 }
6676
67- if ( svelteHtmlPathExists ) {
68- svelteTsxFiles . push ( tsSystem . resolvePath ( resolve ( typesPath , svelteHtmlFile ) ) ) ;
77+ if ( svelteHtmlPath ) {
78+ svelteTsxFiles . push ( tsSystem . resolvePath ( resolve ( typesPath , svelteHtmlPath ) ) ) ;
6979 }
7080
7181 return svelteTsxFiles ;
0 commit comments