@@ -4,8 +4,15 @@ import path from 'node:path';
4
4
import { ExecuteMode , type CommonOptions , type Format , type ResolvedCommonOptions } from '../../types/options' ;
5
5
import { isExists } from '../../util/file' ;
6
6
7
- const findEntryKeyFromObject = ( input : Record < string , string > ) => {
8
- return Object . keys ( input ) [ 0 ] ;
7
+ const findEntryKeyFromObject = ( input : Record < string , string | undefined | null > ) => {
8
+ let entry = null ;
9
+ for ( const key in input ) {
10
+ if ( input [ key ] ) {
11
+ entry = key ;
12
+ break ;
13
+ }
14
+ }
15
+ return entry ;
9
16
} ;
10
17
11
18
const maybeEntryPrefix = [ 'src' ] ;
@@ -97,14 +104,24 @@ function normalizeCommonEntry(entries: CommonOptions['entry']): ResolvedCommonOp
97
104
export async function tryFindEntryFromUserConfig ( logger : Logger , config : UserConfig , options : CommonOptions ) {
98
105
const entriesFromOption = normalizeCommonEntry ( options . entry ) ;
99
106
107
+ const defaultCompilationInputKeys = Object . keys ( config . compilation ?. input ?? { } ) . reduce (
108
+ ( res , key ) => Object . assign ( res , { [ key ] : null } ) ,
109
+ { } as Record < string , null | undefined | string > ,
110
+ ) ;
111
+
112
+ const clearDefault = ( obj : Record < string , null | string | undefined > ) => ( {
113
+ ...defaultCompilationInputKeys ,
114
+ ...obj ,
115
+ } ) ;
116
+
100
117
// cli option > config
101
118
if ( entriesFromOption ) {
102
- return entriesFromOption ;
119
+ return clearDefault ( entriesFromOption ) ;
103
120
}
104
121
105
122
let findEntryKey = findEntryKeyFromObject ( config . compilation ?. input ?? { } ) ;
106
123
107
- if ( findEntryKey ) return config . compilation ?. input ! ;
124
+ if ( findEntryKey ) return clearDefault ( { [ findEntryKey ] : config . compilation ?. input ?. [ findEntryKey ] } ) ;
108
125
109
126
let findEntry : string | null = null ;
110
127
@@ -116,9 +133,7 @@ export async function tryFindEntryFromUserConfig(logger: Logger, config: UserCon
116
133
} else {
117
134
logger . info ( `automatic find and use this entry: "${ findEntry } "` ) ;
118
135
}
119
- return {
120
- [ findEntryKey ] : findEntry ,
121
- } ;
136
+ return clearDefault ( { [ findEntryKey ] : findEntry } ) ;
122
137
}
123
138
124
139
const packageModuleValueMapFormat : Record < string , Format > = {
@@ -151,19 +166,21 @@ export function pinOutputEntryFilename(options: ResolvedCommonOptions) {
151
166
152
167
const executeMode = options . execute . type ;
153
168
154
-
155
- if ( options . target ?. startsWith ( 'browser' ) ) {
169
+ if ( options . target ?. startsWith ( 'browser' ) ) {
156
170
return ;
157
171
}
158
172
159
- if ( ( executeMode === ExecuteMode . Custom || executeMode === ExecuteMode . Node ) && ! options . noExecute ) {
160
- options . entry = Object . entries ( options . entry ) . reduce ( ( res , [ key , val ] ) => {
161
- res [ `${ key } .${ formatMapExt [ options . format ?? 'cjs' ] } ` ] = val ;
162
- return res ;
163
- } , { } as Record < string , string > ) ;
173
+ if ( executeMode === ExecuteMode . Node && ! options . noExecute ) {
174
+ options . entry = Object . entries ( options . entry ) . reduce (
175
+ ( res , [ key , val ] ) => {
176
+ if ( val ) res [ `${ key } .${ formatMapExt [ options . format ?? 'cjs' ] } ` ] = val ;
177
+ return res ;
178
+ } ,
179
+ { } as Record < string , string > ,
180
+ ) ;
164
181
165
182
options . outputEntry = {
166
- name : '[entryName]'
183
+ name : '[entryName]' ,
167
184
} ;
168
185
}
169
186
}
0 commit comments