Skip to content

Core: Normalize file paths in ChangeDetectionService and trace-changed for Windows support#34445

Merged
ghengeveld merged 8 commits into
nextfrom
change-detection-windows
Apr 7, 2026
Merged

Core: Normalize file paths in ChangeDetectionService and trace-changed for Windows support#34445
ghengeveld merged 8 commits into
nextfrom
change-detection-windows

Conversation

@ghengeveld
Copy link
Copy Markdown
Member

@ghengeveld ghengeveld commented Apr 2, 2026

What I did

Normalize paths in change detection and module tracing logic to support Windows.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make 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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Bug Fixes

    • Standardized path handling to ensure changed and newly indexed story files are detected consistently across platforms and to eliminate a duplicate/new-file indexing inconsistency.
  • Tests

    • Updated tests to use the same normalized path approach and validate change-detection behavior remains correct.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 2, 2026

View your CI Pipeline Execution ↗ for commit a09cdf6

Command Status Duration Result
nx run-many -t compile,check,knip,test,lint,fmt... ✅ Succeeded 6m 24s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-07 12:09:08 UTC

@ghengeveld ghengeveld added ci:daily Run the CI jobs that normally run in the daily job. and removed ci:normal labels Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changed path handling in change-detection: replaced absolute resolution with pathe.join for story/module keys, switched scanned/new/changed file set construction to use repo-root-joined or pathe.relative, removed custom toRepoRelativePath, and updated tests to use pathe.join and shared path variables. Also introduced a duplicated newFiles assignment in the diff.

Changes

Cohort / File(s) Summary
ChangeDetection service
code/core/src/core-server/change-detection/ChangeDetectionService.ts
Replaced node:path.resolve(workingDir, ...) with pathe.join(workingDir, ...) for story/module keys; changed scanned/new/changed file set creation to use pathe.join(repoRoot, filePath) and pathe.relative(repoRoot, changedFile); removed toRepoRelativePath() (including its Windows \\\\?\\ handling); diff includes a duplicated newFiles assignment altering how newFiles is built.
Tests — change-detection
code/core/src/core-server/change-detection/ChangeDetectionService.test.ts
Switched test import to pathe, introduced shared path variables (buttonCssPath, buttonComponentPath, buttonStoryPath) and reused them for createModuleNode(...) and ModuleGraph keys to match new join/relative behavior; assertions unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
code/core/src/core-server/change-detection/trace-changed.ts (1)

5-21: Well-structured fallback lookup for cross-platform compatibility.

The two-phase approach is sound: direct O(1) lookup first, then O(n) fallback only when needed. This handles module graphs where keys might have inconsistent path formats (e.g., Windows backslashes vs. forward slashes).

Consider adding a brief inline comment explaining when the fallback is expected to trigger (e.g., Windows paths in moduleGraph keys).

📝 Optional: Add explanatory comment
 function getModuleNodesByNormalizedPath(
   moduleGraph: ModuleGraph,
   normalizedPath: string
 ): Set<ModuleNode> | undefined {
   const directMatch = moduleGraph.get(normalizedPath);
   if (directMatch) {
     return directMatch;
   }
 
+  // Fallback: moduleGraph keys may use OS-native separators (e.g., backslashes on Windows)
   for (const [modulePath, nodes] of moduleGraph.entries()) {
     if (normalizePath(modulePath) === normalizedPath) {
       return nodes;
     }
   }
 
   return undefined;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/core-server/change-detection/trace-changed.ts` around lines 5 -
21, Add a short inline comment in getModuleNodesByNormalizedPath explaining that
after the O(1) direct lookup the O(n) fallback scans moduleGraph entries to
handle mismatched path formats (e.g., Windows backslashes vs POSIX forward
slashes) and will only run when keys in moduleGraph are not already normalized;
place the comment above the fallback for clarity so future readers understand
when and why the fallback path is expected to trigger.
🤖 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/core/src/core-server/change-detection/trace-changed.ts`:
- Around line 5-21: Add a short inline comment in getModuleNodesByNormalizedPath
explaining that after the O(1) direct lookup the O(n) fallback scans moduleGraph
entries to handle mismatched path formats (e.g., Windows backslashes vs POSIX
forward slashes) and will only run when keys in moduleGraph are not already
normalized; place the comment above the fallback for clarity so future readers
understand when and why the fallback path is expected to trigger.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e02881a4-04ee-44dc-9bd3-3a481498b7a6

📥 Commits

Reviewing files that changed from the base of the PR and between c2bcb9d and b14cbbd.

📒 Files selected for processing (2)
  • code/core/src/core-server/change-detection/ChangeDetectionService.ts
  • code/core/src/core-server/change-detection/trace-changed.ts

Comment thread code/core/src/core-server/change-detection/ChangeDetectionService.ts Outdated
Comment thread code/core/src/core-server/change-detection/trace-changed.ts Outdated
@ghengeveld ghengeveld added ci:merged Run the CI jobs that normally run when merged. and removed ci:daily Run the CI jobs that normally run in the daily job. labels Apr 7, 2026
@ghengeveld ghengeveld merged commit 370524f into next Apr 7, 2026
304 of 312 checks passed
@ghengeveld ghengeveld deleted the change-detection-windows branch April 7, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:merged Run the CI jobs that normally run when merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants