(environment: ScanEnvironment)
| 207 | } |
| 208 | |
| 209 | async 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 | |
| 258 | async function prepareRolldownScanner( |
| 259 | environment: ScanEnvironment, |
no test coverage detected