11import path from 'node:path'
2+ import picomatch from 'picomatch'
23import { glob , isDynamicPattern } from 'tinyglobby'
3- import { fsExists , lowestCommonAncestor } from '../utils/fs.ts'
4+ import { fsExists , lowestCommonAncestor , stripExtname } from '../utils/fs.ts'
45import { slash } from '../utils/general.ts'
56import type { UserConfig } from '../config/index.ts'
67import type { Logger } from '../utils/logger.ts'
@@ -45,7 +46,32 @@ export async function toObjectEntry(
4546 entry = [ entry ]
4647 }
4748 if ( ! Array . isArray ( entry ) ) {
48- return entry
49+ // resolve object entry with globs
50+ return Object . fromEntries (
51+ (
52+ await Promise . all (
53+ Object . entries ( entry ) . map ( async ( [ key , value ] ) => {
54+ if ( ! key . includes ( '*' ) ) return [ [ key , value ] ]
55+
56+ const valueGlob = picomatch . scan ( value )
57+ const files = await glob ( value , {
58+ cwd,
59+ expandDirectories : false ,
60+ } )
61+
62+ return files . map ( ( file ) => [
63+ slash (
64+ key . replaceAll (
65+ '*' ,
66+ stripExtname ( path . relative ( valueGlob . base , file ) ) ,
67+ ) ,
68+ ) ,
69+ path . resolve ( cwd , file ) ,
70+ ] )
71+ } ) ,
72+ )
73+ ) . flat ( ) ,
74+ )
4975 }
5076
5177 const isGlob = entry . some ( ( e ) => isDynamicPattern ( e ) )
@@ -66,12 +92,7 @@ export async function toObjectEntry(
6692 return Object . fromEntries (
6793 resolvedEntry . map ( ( file ) => {
6894 const relative = path . relative ( base , file )
69- return [
70- slash (
71- relative . slice ( 0 , relative . length - path . extname ( relative ) . length ) ,
72- ) ,
73- file ,
74- ]
95+ return [ slash ( stripExtname ( relative ) ) , file ]
7596 } ) ,
7697 )
7798}
0 commit comments