()
| 633 | // imports after the first request have been crawled (dynamic imports may also |
| 634 | // be crawled if the browser requests them right away). |
| 635 | async function onCrawlEnd() { |
| 636 | // switch after this point to a simple debounce strategy |
| 637 | waitingForCrawlEnd = false |
| 638 | |
| 639 | debug?.(colors.green(`static imports crawl ended`)) |
| 640 | if (closed) { |
| 641 | return |
| 642 | } |
| 643 | |
| 644 | // Await for the scan+optimize step running in the background |
| 645 | // It normally should be over by the time crawling of user code ended |
| 646 | await depsOptimizer.scanProcessing |
| 647 | |
| 648 | if (optimizationResult && !options.noDiscovery) { |
| 649 | // In the holdUntilCrawlEnd strategy, we don't release the result of the |
| 650 | // post-scanner optimize step to the browser until we reach this point |
| 651 | // If there are new dependencies, we do another optimize run, if not, we |
| 652 | // use the post-scanner optimize result |
| 653 | // If holdUntilCrawlEnd is false and we reach here, it means that the |
| 654 | // scan+optimize step finished after crawl end. We follow the same |
| 655 | // process as in the holdUntilCrawlEnd in this case. |
| 656 | const afterScanResult = optimizationResult.result |
| 657 | optimizationResult = undefined // signal that we'll be using the result |
| 658 | |
| 659 | const result = await afterScanResult |
| 660 | currentlyProcessing = false |
| 661 | |
| 662 | const crawlDeps = Object.keys(metadata.discovered) |
| 663 | const scanDeps = Object.keys(result.metadata.optimized) |
| 664 | |
| 665 | if (scanDeps.length === 0 && crawlDeps.length === 0) { |
| 666 | debug?.( |
| 667 | colors.green( |
| 668 | `no dependencies found by the scanner or crawling static imports`, |
| 669 | ), |
| 670 | ) |
| 671 | // We still commit the result so the scanner isn't run on the next cold start |
| 672 | // for projects without dependencies |
| 673 | startNextDiscoveredBatch() |
| 674 | runOptimizer(result) |
| 675 | return |
| 676 | } |
| 677 | |
| 678 | const needsInteropMismatch = findInteropMismatches( |
| 679 | metadata.discovered, |
| 680 | result.metadata.optimized, |
| 681 | ) |
| 682 | const scannerMissedDeps = crawlDeps.some((dep) => !scanDeps.includes(dep)) |
| 683 | const outdatedResult = |
| 684 | needsInteropMismatch.length > 0 || scannerMissedDeps |
| 685 | |
| 686 | if (outdatedResult) { |
| 687 | // Drop this scan result, and perform a new optimization to avoid a full reload |
| 688 | result.cancel() |
| 689 | |
| 690 | // Add deps found by the scanner to the discovered deps while crawling |
| 691 | for (const dep of scanDeps) { |
| 692 | if (!crawlDeps.includes(dep)) { |
nothing calls this directly
no test coverage detected