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

Function scan

packages/vite/src/node/optimizer/scan.ts:131–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129 }
130
131 async function scan() {
132 const entries = await computeEntries(environment)
133 if (!entries.length) {
134 if (!config.optimizeDeps.entries && !config.optimizeDeps.include) {
135 environment.logger.warn(
136 colors.yellow(
137 '(!) Could not auto-determine entry point from rolldownOptions or html files ' +
138 'and there are no explicit optimizeDeps.include patterns. ' +
139 'Skipping dependency pre-bundling.',
140 ),
141 )
142 }
143 return
144 }
145 if (scanContext.cancelled) return
146
147 debug?.(
148 `Crawling dependencies using entries: ${entries
149 .map((entry) => `\n ${colors.dim(entry)}`)
150 .join('')}`,
151 )
152 const deps: Record<string, string> = {}
153 const missing: Record<string, string> = {}
154
155 const context = await prepareRolldownScanner(
156 environment,
157 entries,
158 deps,
159 missing,
160 )
161 if (scanContext.cancelled) return
162
163 try {
164 await context.build()
165 return {
166 // Ensure a fixed order so hashes are stable and improve logs
167 deps: orderedDependencies(deps),
168 missing,
169 }
170 } catch (e) {
171 // The scanner runs in the background and may still be crawling when the
172 // server is closed. In that case resolutions reject with
173 // `ERR_CLOSED_SERVER` and the scan build fails.
174 if (
175 e.errors?.some(
176 (error: { pluginCode?: string }) =>
177 error.pluginCode === ERR_CLOSED_SERVER,
178 )
179 ) {
180 return
181 }
182 const prependMessage = colors.red(`\
183 Failed to scan for dependencies from entries:
184 ${entries.join('\n')}
185
186 `)
187 e.message = prependMessage + e.message
188 throw e

Callers 2

scanImportsFunction · 0.85
buildFunction · 0.85

Calls 5

computeEntriesFunction · 0.85
prepareRolldownScannerFunction · 0.85
orderedDependenciesFunction · 0.85
buildMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected