Vite: Add mock entries to optimizeDeps.entries#34167
Conversation
|
View your CI Pipeline Execution ↗ for commit d83eb16
☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughA new utility function Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing Touches
📝 Coding Plan
Comment Tip CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
code/builders/builder-vite/src/plugins/storybook-optimize-deps-plugin.ts (1)
60-73: Consider whetherdisableTelemetryshould followoptionsconfiguration.The
disableTelemetry: trueis hardcoded here. If this is intentional (e.g., to avoid telemetry during dep optimization which runs frequently), a brief comment explaining the rationale would be helpful for future maintainers.💡 Suggested documentation
const mockRedirectIncludeEntries = previewOrConfigFile ? getMockRedirectIncludeEntries( extractMockCalls( { previewConfigPath: previewOrConfigFile, + // Telemetry is disabled here to avoid excessive telemetry events during + // frequent dep optimization passes in development. coreOptions: { disableTelemetry: true }, configDir: options.configDir, },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/builders/builder-vite/src/plugins/storybook-optimize-deps-plugin.ts` around lines 60 - 73, The code hardcodes disableTelemetry: true in the extractMockCalls call (within mockRedirectIncludeEntries creation). Replace the literal with a value derived from the passed-in options (e.g., disableTelemetry: options.disableTelemetry ?? true) so telemetry follows the caller's configuration, or if the intent is to always disableTelemetry here, add a short clarifying comment above the getMockRedirectIncludeEntries/extractMockCalls call explaining why telemetry must be forced off during dep optimization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@code/builders/builder-vite/src/plugins/storybook-optimize-deps-plugin.ts`:
- Around line 60-73: The code hardcodes disableTelemetry: true in the
extractMockCalls call (within mockRedirectIncludeEntries creation). Replace the
literal with a value derived from the passed-in options (e.g., disableTelemetry:
options.disableTelemetry ?? true) so telemetry follows the caller's
configuration, or if the intent is to always disableTelemetry here, add a short
clarifying comment above the getMockRedirectIncludeEntries/extractMockCalls call
explaining why telemetry must be forced off during dep optimization.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1da82216-1fc7-45b2-aa7c-e2e37c68ad18
📒 Files selected for processing (2)
code/builders/builder-vite/src/plugins/storybook-optimize-deps-plugin.test.tscode/builders/builder-vite/src/plugins/storybook-optimize-deps-plugin.ts
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 534 | 534 | 0 |
| Self size | 650 KB | 650 KB | 🎉 -10 B 🎉 |
| Dependency size | 59.93 MB | 59.95 MB | 🚨 +19 KB 🚨 |
| Bundle Size Analyzer | Link | Link |
@storybook/preset-create-react-app
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 68 | 68 | 0 |
| Self size | 32 KB | 32 KB | 🎉 -4 B 🎉 |
| Dependency size | 6.00 MB | 6.01 MB | 🚨 +10 KB 🚨 |
| Bundle Size Analyzer | Link | Link |
Closes #
What I did
Added support in the Vite optimize-deps plugin to include manual
sb.mock(...)redirect targets (files in__mocks__) inoptimizeDeps.include, so dependencies imported by those mock files are pre-bundled correctly.Specifically:
extractMockCalls,findMockRedirect) in the optimize-deps plugin.redirectPathonly, escapes glob-sensitive characters, and deduplicates entries.optimizeDeps.includewhile preserving existing include ordering.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
No additional manual testing was performed. This change is covered by focused unit tests and validation commands (
nx compile,nx check, targetedvitest, and lint).Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-34167-sha-d83eb160. Try it out in a new sandbox by runningnpx storybook@0.0.0-pr-34167-sha-d83eb160 sandboxor in an existing project withnpx storybook@0.0.0-pr-34167-sha-d83eb160 upgrade.More information
0.0.0-pr-34167-sha-d83eb160valentin/support-optimize-deps-for-mocksd83eb1601773698919)To request a new release of this pull request, mention the
@storybookjs/coreteam.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=34167Summary by CodeRabbit
Refactor
Tests