@@ -11,16 +11,16 @@ import { ParsedMeta, ParsedStory, parse } from './parser'
1111export async function transform ( code : string ) {
1212 let result = ''
1313 const { resolvedScript, meta, stories, docs } = parse ( code )
14+ const isTS = resolvedScript ?. lang === 'ts'
1415 if ( resolvedScript ) {
15- const isTS = resolvedScript . lang === 'ts'
16- const plugins : ParserPlugin [ ] = isTS ? [ 'typescript' ] : [ ]
17- result += rewriteDefault ( resolvedScript . content , '_sfc_main' , plugins )
16+ const babelPlugins : ParserPlugin [ ] = isTS ? [ 'typescript' ] : [ ]
17+ result += rewriteDefault ( resolvedScript . content , '_sfc_main' , babelPlugins )
1818 result += '\n'
1919 } else {
2020 result += 'const _sfc_main = {}\n'
2121 }
2222 result += await transformTemplate ( { meta, stories, docs } , resolvedScript )
23- result = organizeImports ( result )
23+ result = await organizeImports ( result , isTS )
2424 return result
2525
2626 /*
@@ -151,10 +151,10 @@ function generateStoryImport(
151151 };`
152152}
153153
154- function organizeImports ( result : string ) : string {
154+ async function organizeImports ( result : string , isTS : boolean ) : Promise < string > {
155155 // Use prettier to organize imports
156- return prettierFormat ( result , {
157- parser : 'babel' ,
156+ return await prettierFormat ( result , {
157+ parser : isTS ? 'typescript' : 'babel' ,
158158 plugins : [ 'prettier-plugin-organize-imports' ] ,
159159 } )
160160}
0 commit comments