@@ -26,11 +26,41 @@ const aliasResolverPlugin = {
2626 const aliasRegex = new RegExp ( `^${ alias } ($|/.*)` )
2727 build . onResolve ( { filter : aliasRegex } , ( args ) => {
2828 const importPath = args . path . replace ( alias , aliasPath )
29+
30+ // First, check if the path exists as is
31+ if ( fs . existsSync ( importPath ) ) {
32+ const stats = fs . statSync ( importPath )
33+ if ( stats . isDirectory ( ) ) {
34+ // If it's a directory, try to find index files
35+ const extensions = [ ".ts" , ".tsx" , ".js" , ".jsx" ]
36+ for ( const ext of extensions ) {
37+ const indexFile = path . join ( importPath , `index${ ext } ` )
38+ if ( fs . existsSync ( indexFile ) ) {
39+ return { path : indexFile }
40+ }
41+ }
42+ } else {
43+ // It's a file that exists, so return it
44+ return { path : importPath }
45+ }
46+ }
47+
48+ // If the path doesn't exist, try appending extensions
49+ const extensions = [ ".ts" , ".tsx" , ".js" , ".jsx" ]
50+ for ( const ext of extensions ) {
51+ const pathWithExtension = `${ importPath } ${ ext } `
52+ if ( fs . existsSync ( pathWithExtension ) ) {
53+ return { path : pathWithExtension }
54+ }
55+ }
56+
57+ // If nothing worked, return the original path and let esbuild handle the error
2958 return { path : importPath }
3059 } )
3160 } )
3261 } ,
3362}
63+
3464const esbuildProblemMatcherPlugin = {
3565 name : "esbuild-problem-matcher" ,
3666
0 commit comments