File tree 3 files changed +21
-3
lines changed
3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -619,3 +619,8 @@ export default SvgComponent
619
619
620
620
"
621
621
`;
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) => {
47
47
return exportEntries . join ( '\n' )
48
48
}
49
49
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' )
52
55
53
56
export const dirCommand : SvgrCommand = async (
54
57
opts ,
@@ -64,7 +67,7 @@ export const dirCommand: SvgrCommand = async (
64
67
outDir,
65
68
} = opts
66
69
67
- const ext = resolveExtension ( opts , extOpt )
70
+ const ext = resolveExtension ( opts , extOpt , true )
68
71
69
72
const write = async ( src : string , dest : string ) => {
70
73
if ( ! isCompilable ( src ) ) {
@@ -92,6 +95,7 @@ export const dirCommand: SvgrCommand = async (
92
95
files : string [ ] ,
93
96
opts : Options ,
94
97
) => {
98
+ const ext = resolveExtension ( opts , extOpt , false )
95
99
const filepath = path . join ( dest , `index.${ ext } ` )
96
100
const indexTemplate = opts . indexTemplate || defaultIndexTemplate
97
101
const fileContent = indexTemplate ( files )
Original file line number Diff line number Diff line change @@ -203,6 +203,15 @@ describe('cli', () => {
203
203
expect ( content ) . toMatchSnapshot ( )
204
204
} )
205
205
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
+
206
215
it ( 'should support --index-template in cli' , async ( ) => {
207
216
const inDir = '__fixtures__/simple'
208
217
const outDir = `__fixtures_build__/custom-index-arg`
You can’t perform that action at this time.
1 commit comments
vercel[bot] commentedon Jan 29, 2022
Successfully deployed to the following URLs: