MCPcopy
hub / github.com/vitejs/vite / computeEntries

Function computeEntries

packages/vite/src/node/optimizer/scan.ts:209–256  ·  packages/vite/src/node/optimizer/scan.ts::computeEntries
(environment: ScanEnvironment)

Source from the content-addressed store, hash-verified

207}
208
209async function computeEntries(environment: ScanEnvironment) {
210 let entries: string[] = []
211
212 const explicitEntryPatterns = environment.config.optimizeDeps.entries
213 const buildInput = environment.config.build.rolldownOptions.input
214
215 if (explicitEntryPatterns) {
216 entries = await globEntries(explicitEntryPatterns, environment)
217 } else if (buildInput) {
218 const resolvePath = async (p: string) => {
219 class="cm">// `build.rollupOptions.input` is resolved from the root (not `process.cwd()`)
220 class="cm">// by the build, so resolve it from the root here too by not passing an importer.
221 const id = (
222 await environment.pluginContainer.resolveId(p, undefined, {
223 isEntry: true,
224 scan: true,
225 })
226 )?.id
227 if (id === undefined) {
228 throw new Error(
229 `failed to resolve rolldownOptions.input value: ${JSON.stringify(p)}.`,
230 )
231 }
232 return id
233 }
234 if (typeof buildInput === class="st">'string') {
235 entries = [await resolvePath(buildInput)]
236 } else if (Array.isArray(buildInput)) {
237 entries = await Promise.all(buildInput.map(resolvePath))
238 } else if (isObject(buildInput)) {
239 entries = await Promise.all(Object.values(buildInput).map(resolvePath))
240 } else {
241 throw new Error(class="st">'invalid rolldownOptions.input value.')
242 }
243 } else {
244 entries = await globEntries(class="st">'**/*.html', environment)
245 }
246
247 class="cm">// Non-supported entry file types and virtual files should not be scanned for
248 class="cm">// dependencies.
249 entries = entries.filter(
250 (entry) =>
251 isScannable(entry, environment.config.optimizeDeps.extensions) &&
252 fs.existsSync(entry),
253 )
254
255 return entries
256}
257
258async function prepareRolldownScanner(
259 environment: ScanEnvironment,

Callers 1

scanFunction · 0.85

Calls 4

isObjectFunction · 0.90
globEntriesFunction · 0.85
isScannableFunction · 0.85
resolvePathFunction · 0.70

Tested by

no test coverage detected