@@ -801,6 +801,11 @@ private Path guessPackageMainFile(Path packageJsonFile, JsonObject packageJson,
801801 return resolved ;
802802 }
803803
804+ // Get the "main" property from the package.json
805+ // This usually refers to the compiled output, such as `./out/foo.js` but may hint as to
806+ // the name of main file ("foo" in this case).
807+ String mainStr = getChildAsString (packageJson , "main" );
808+
804809 // Look for source files `./src` if it exists
805810 Path sourceDir = packageDir .resolve ("src" );
806811 if (Files .isDirectory (sourceDir )) {
@@ -810,11 +815,6 @@ private Path guessPackageMainFile(Path packageJsonFile, JsonObject packageJson,
810815 return resolved ;
811816 }
812817
813- // Get the "main" property from the package.json
814- // This usually refers to the compiled output, such as `./out/foo.js` but may hint as to
815- // the name of main file ("foo" in this case).
816- String mainStr = getChildAsString (packageJson , "main" );
817-
818818 // If "main" was defined, try to map it to a file in `src`.
819819 // For example `out/dist/foo.bundle.js` might be mapped back to `src/foo.ts`.
820820 if (mainStr != null ) {
@@ -838,7 +838,17 @@ private Path guessPackageMainFile(Path packageJsonFile, JsonObject packageJson,
838838 }
839839 }
840840
841- return resolved ;
841+ // Try to resolve main as a sibling of the package.json file, such as "./main.js" -> "./main.ts".
842+ if (mainStr != null ) {
843+ Path mainPath = Paths .get (mainStr );
844+ String withoutExt = FileUtil .stripExtension (mainPath .getFileName ().toString ());
845+ resolved = tryResolveWithExtensions (packageDir , withoutExt , extensions );
846+ if (resolved != null ) {
847+ return resolved ;
848+ }
849+ }
850+
851+ return null ;
842852 }
843853
844854 private ExtractorConfig mkExtractorConfig () {
0 commit comments