MCPcopy
hub / github.com/rolldown/tsdown / resolveArrayEntry

Function resolveArrayEntry

src/features/entry.ts:137–188  ·  view source on GitHub ↗
(
  entries: (string | Record<string, Arrayable<string>>)[],
  cwd: string,
  root?: string,
)

Source from the content-addressed store, hash-verified

135}
136
137async function resolveArrayEntry(
138 entries: (string | Record<string, Arrayable<string>>)[],
139 cwd: string,
140 root?: string,
141): Promise<[entry: Record<string, string>, root: string]> {
142 const stringEntries: string[] = []
143 const objectEntries: Record<string, Arrayable<string>>[] = []
144 for (const e of entries) {
145 if (typeof e === 'string') {
146 stringEntries.push(e)
147 } else {
148 objectEntries.push(e)
149 }
150 }
151
152 const isGlob = stringEntries.some((e) => isDynamicPattern(e))
153 let resolvedEntries: string[]
154 if (isGlob) {
155 resolvedEntries = (
156 await glob(stringEntries, {
157 cwd,
158 expandDirectories: false,
159 absolute: true,
160 })
161 ).map((file) => path.resolve(file))
162 } else {
163 resolvedEntries = stringEntries
164 }
165
166 const computedRoot = root || lowestCommonAncestor(...resolvedEntries)
167 // For entry name computation, base must match the path style of entries:
168 // glob entries are absolute, non-glob entries stay relative (may be virtual files)
169 const base = root && !isGlob ? path.relative(cwd, root) || '.' : computedRoot
170 const arrayEntryMap = Object.fromEntries(
171 resolvedEntries.map((file) => {
172 const relative = path.relative(base, file)
173 return [slash(stripExtname(relative)), file]
174 }),
175 )
176
177 const resolvedObjectEntries = await Promise.all(
178 objectEntries.map(async (entry) => {
179 const [entryMap] = await resolveObjectEntry(entry, cwd)
180 return entryMap
181 }),
182 )
183
184 return [
185 Object.assign({}, arrayEntryMap, ...resolvedObjectEntries),
186 computedRoot,
187 ]
188}

Callers 1

toObjectEntryFunction · 0.85

Calls 4

lowestCommonAncestorFunction · 0.90
slashFunction · 0.90
stripExtnameFunction · 0.90
resolveObjectEntryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…