@@ -30,28 +30,29 @@ const extensionMap = {
30
30
const distExtensions = Object . keys ( extensionMap ) as ( keyof typeof extensionMap ) [ ] ;
31
31
32
32
export const getSourcePath = async (
33
- exportEntry : ExportEntry ,
33
+ { outputPath } : ExportEntry ,
34
34
source : string ,
35
35
dist : string ,
36
36
) => {
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
+ } ;
53
53
}
54
+ throw new Error ( `Could not find matching source file for export path: ${ stringify ( outputPath ) } ; Expected: ${ sourcePathWithoutExtension } [${ extensionMap [ distExtension ] . join ( '|' ) } ]` ) ;
54
55
}
55
56
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 ( ', ' ) } ` ) ;
57
58
} ;
0 commit comments