@@ -9,6 +9,7 @@ const tryExtensions = async (
99) => {
1010 for ( const extension of extensions ) {
1111 const pathWithExtension = pathWithoutExtension + extension ;
12+ console . log ( "checking for path" , pathWithExtension ) ;
1213 if ( await fsExists ( pathWithExtension ) ) {
1314 return {
1415 extension,
@@ -36,22 +37,23 @@ export const getSourcePath = async (
3637) => {
3738 const sourcePathUnresolved = source + exportEntry . outputPath . slice ( dist . length ) ;
3839
39- for ( const distExtension of distExtensions ) {
40- if ( exportEntry . outputPath . endsWith ( distExtension ) ) {
41- const sourcePath = await tryExtensions (
42- sourcePathUnresolved . slice ( 0 , - distExtension . length ) ,
43- extensionMap [ distExtension ] ,
44- ) ;
45-
46- if ( sourcePath ) {
47- return {
48- input : sourcePath . path ,
49- srcExtension : sourcePath . extension ,
50- distExtension ,
51- } ;
52- }
40+ const distExtension = distExtensions . find ( ( distExtension ) => exportEntry . outputPath . endsWith ( distExtension ) ) ;
41+ if ( distExtension ) {
42+ const sourcePathWithoutExtension = sourcePathUnresolved . slice ( 0 , - distExtension . length ) ;
43+ const sourcePath = await tryExtensions (
44+ sourcePathWithoutExtension ,
45+ extensionMap [ distExtension ] ,
46+ ) ;
47+
48+ if ( sourcePath ) {
49+ return {
50+ input : sourcePath . path ,
51+ srcExtension : sourcePath . extension ,
52+ distExtension ,
53+ } ;
5354 }
55+ throw new Error ( `Could not find matching source file for export path: ${ stringify ( exportEntry . outputPath ) } ; Expected: ${ sourcePathWithoutExtension } [${ extensionMap [ distExtension ] . join ( '|' ) } ]` ) ;
5456 }
5557
56- throw new Error ( `Could not find matching source file for export path ${ stringify ( exportEntry . outputPath ) } ` ) ;
58+ throw new Error ( `Package.json output path contains invalid extension: ${ stringify ( exportEntry . outputPath ) } ; Expected: ${ distExtensions . join ( ', ' ) } ` ) ;
5759} ;
0 commit comments