@@ -30,28 +30,29 @@ const extensionMap = {
3030const distExtensions = Object . keys ( extensionMap ) as ( keyof typeof extensionMap ) [ ] ;
3131
3232export const getSourcePath = async (
33- exportEntry : ExportEntry ,
33+ { outputPath } : ExportEntry ,
3434 source : string ,
3535 dist : string ,
3636) => {
37- const sourcePathUnresolved = source + exportEntry . outputPath . slice ( dist . length ) ;
38-
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- }
37+ const sourcePathUnresolved = source + outputPath . slice ( dist . length ) ;
38+
39+ const distExtension = distExtensions . find ( extension => outputPath . endsWith ( extension ) ) ;
40+ if ( distExtension ) {
41+ const sourcePathWithoutExtension = sourcePathUnresolved . slice ( 0 , - distExtension . length ) ;
42+ const sourcePath = await tryExtensions (
43+ sourcePathWithoutExtension ,
44+ extensionMap [ distExtension ] ,
45+ ) ;
46+
47+ if ( sourcePath ) {
48+ return {
49+ input : sourcePath . path ,
50+ srcExtension : sourcePath . extension ,
51+ distExtension ,
52+ } ;
5353 }
54+ throw new Error ( `Could not find matching source file for export path: ${ stringify ( outputPath ) } ; Expected: ${ sourcePathWithoutExtension } [${ extensionMap [ distExtension ] . join ( '|' ) } ]` ) ;
5455 }
5556
56- throw new Error ( `Could not find matching source file for export path ${ stringify ( exportEntry . outputPath ) } ` ) ;
57+ throw new Error ( `Package.json output path contains invalid extension: ${ stringify ( outputPath ) } ; Expected: ${ distExtensions . join ( ', ' ) } ` ) ;
5758} ;
0 commit comments