File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed
Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -619,3 +619,8 @@ export default SvgComponent
619619
620620"
621621`;
622+
623+ exports[`cli using typescript option, it creates index with \`.ts\` extension 1`] = `
624+ "export { default as File } from './File'
625+ "
626+ `;
Original file line number Diff line number Diff line change @@ -47,8 +47,11 @@ const defaultIndexTemplate: IndexTemplate = (paths) => {
4747 return exportEntries . join ( '\n' )
4848}
4949
50- const resolveExtension = ( config : Config , ext ?: string ) =>
51- ext || ( config . typescript ? 'tsx' : 'js' )
50+ const resolveExtension = (
51+ config : Config ,
52+ ext : string | null | undefined ,
53+ jsx : boolean ,
54+ ) => ext || ( config . typescript ? ( jsx ? 'tsx' : 'ts' ) : 'js' )
5255
5356export const dirCommand : SvgrCommand = async (
5457 opts ,
@@ -64,7 +67,7 @@ export const dirCommand: SvgrCommand = async (
6467 outDir,
6568 } = opts
6669
67- const ext = resolveExtension ( opts , extOpt )
70+ const ext = resolveExtension ( opts , extOpt , true )
6871
6972 const write = async ( src : string , dest : string ) => {
7073 if ( ! isCompilable ( src ) ) {
@@ -92,6 +95,7 @@ export const dirCommand: SvgrCommand = async (
9295 files : string [ ] ,
9396 opts : Options ,
9497 ) => {
98+ const ext = resolveExtension ( opts , extOpt , false )
9599 const filepath = path . join ( dest , `index.${ ext } ` )
96100 const indexTemplate = opts . indexTemplate || defaultIndexTemplate
97101 const fileContent = indexTemplate ( files )
Original file line number Diff line number Diff line change @@ -203,6 +203,15 @@ describe('cli', () => {
203203 expect ( content ) . toMatchSnapshot ( )
204204 } )
205205
206+ it ( 'using typescript option, it creates index with `.ts` extension' , async ( ) => {
207+ const inDir = '__fixtures__/simple'
208+ const outDir = `__fixtures_build__/ts-index`
209+ await del ( outDir )
210+ await cli ( `${ inDir } --out-dir=${ outDir } --typescript` )
211+ const content = await fs . readFile ( path . join ( outDir , 'index.ts' ) , 'utf-8' )
212+ expect ( content ) . toMatchSnapshot ( )
213+ } )
214+
206215 it ( 'should support --index-template in cli' , async ( ) => {
207216 const inDir = '__fixtures__/simple'
208217 const outDir = `__fixtures_build__/custom-index-arg`
You can’t perform that action at this time.
0 commit comments