@@ -657,18 +657,26 @@ function possibleAliasedPaths(
657
657
return result ;
658
658
}
659
659
660
+ // Try importing without adding any extension
661
+ // and then every supported extension
662
+ const getPossibleFilePaths = ( filePath : string ) => {
663
+ const extension = path . extname ( filePath ) ;
664
+ const filePathHasCodeExtension = EXTENSIONS . includes ( extension ) ;
665
+ const filePathNoCodeExtension = filePathHasCodeExtension
666
+ ? filePath . slice ( 0 , - extension . length )
667
+ : filePath ;
668
+
669
+ return [ filePath , ...EXTENSIONS . map ( ( ext ) => filePathNoCodeExtension + ext ) ] ;
670
+ } ;
671
+
660
672
// a function that resolves the absolute path of a file when given the
661
673
// relative path of the file from the source file
662
674
const filePathResolver = (
663
675
relativeFilePath: string,
664
676
sourceFilePath: string,
665
677
aliases: StyleXStateOptions['aliases'],
666
678
): ?string => {
667
- // Try importing without adding any extension
668
- // and then every supported extension
669
- for ( const ext of [ '' , ...EXTENSIONS ] ) {
670
- const importPathStr = relativeFilePath + ext ;
671
-
679
+ for ( const importPathStr of getPossibleFilePaths ( relativeFilePath ) ) {
672
680
// Try to resolve relative paths as is
673
681
if ( importPathStr . startsWith ( '.' ) ) {
674
682
try {
@@ -712,13 +720,9 @@ const addFileExtension = (
712
720
} ;
713
721
714
722
const matchesFileSuffix = ( allowedSuffix : string ) = > ( filename : string ) =>
715
- filename . endsWith ( `${ allowedSuffix } .js` ) ||
716
- filename . endsWith ( `${ allowedSuffix } .ts` ) ||
717
- filename . endsWith ( `${ allowedSuffix } .tsx` ) ||
718
- filename . endsWith ( `${ allowedSuffix } .jsx` ) ||
719
- filename . endsWith ( `${ allowedSuffix } .mjs` ) ||
720
- filename . endsWith ( `${ allowedSuffix } .cjs` ) ||
721
- filename . endsWith ( allowedSuffix ) ;
723
+ [ '' , ...EXTENSIONS ] . some ( ( extension ) =>
724
+ filename . endsWith ( `${ allowedSuffix } ${ extension } ` ) ,
725
+ ) ;
722
726
723
727
const getProgramPath = ( path : NodePath < > ) : null | NodePath < t . Program > => {
724
728
let programPath = path ;
0 commit comments