@@ -183,37 +183,48 @@ function isNotRelative (file) {
183
183
return isRelative ( file ) && file [ 0 ] !== '.'
184
184
}
185
185
186
- function parse ( opts ) {
186
+ function resolveDefaultEntriesPaths ( opts ) {
187
187
const pkgPath = opts . path
188
+ const pkgDir = path . dirname ( pkgPath )
188
189
const pkg = opts . package
189
- const extensions = opts . extensions
190
190
191
- const deps = { }
192
- const seen = [ ]
193
- const core = [ ]
194
- const mainPath = path . resolve ( pkg . main || path . join ( path . dirname ( pkgPath ) , 'index.js' ) )
191
+ const mainPath = path . resolve ( pkg . main || path . join ( pkgDir , 'index.js' ) )
195
192
196
193
let paths = [ ]
197
194
198
- if ( ! opts . noDefaultEntries && fs . existsSync ( mainPath ) ) paths . push ( mainPath )
195
+ // Add the path of the main file
196
+ if ( fs . existsSync ( mainPath ) ) paths . push ( mainPath )
199
197
200
- if ( ! opts . noDefaultEntries && pkg . bin ) {
198
+ // Add the path of binaries
199
+ if ( pkg . bin ) {
201
200
if ( typeof pkg . bin === 'string' ) {
202
- paths . push ( path . resolve ( path . join ( path . dirname ( pkgPath ) , pkg . bin ) ) )
203
201
} else {
204
202
Object . keys ( pkg . bin ) . forEach ( cmdName => {
205
203
const cmd = pkg . bin [ cmdName ]
206
- paths . push ( path . resolve ( path . join ( path . dirname ( pkgPath ) , cmd ) ) )
204
+ paths . push ( path . resolve ( path . join ( pkgDir , cmd ) ) )
207
205
} )
208
206
}
209
207
}
210
208
211
- // pass in custom additional entries e.g. ['./test.js']
212
- if ( opts . entries ) {
213
- paths = paths . concat (
214
- resolveGlobbedPath ( opts . entries , path . dirname ( pkgPath ) )
215
- )
216
- }
209
+ return paths
210
+ }
211
+
212
+ function resolvePaths ( opts ) {
213
+ return [
214
+ ...( ! opts . noDefaultEntries ? resolveDefaultEntriesPaths ( opts ) : [ ] ) ,
215
+ ...( opts . entries ? resolveGlobbedPath ( opts . entries , path . dirname ( opts . path ) ) : [ ] )
216
+ ]
217
+ }
218
+
219
+ function parse ( opts ) {
220
+ const pkg = opts . package
221
+ const extensions = opts . extensions
222
+
223
+ const deps = { }
224
+ const seen = [ ]
225
+ const core = [ ]
226
+
227
+ const paths = resolvePaths ( opts )
217
228
218
229
debug ( 'entry paths' , paths )
219
230
0 commit comments