Skip to content

Codemod: Fix glob pattern handling on Windows#33714

Merged
valentinpalkovic merged 2 commits into
nextfrom
kasper/fix-codemod-windows
Jan 30, 2026
Merged

Codemod: Fix glob pattern handling on Windows#33714
valentinpalkovic merged 2 commits into
nextfrom
kasper/fix-codemod-windows

Conversation

@kasperpeulen
Copy link
Copy Markdown
Member

@kasperpeulen kasperpeulen commented Jan 30, 2026

Closes #

What I did

Fixed a Windows-specific bug where runCodemod in @storybook/codemod failed to find files because tinyglobby requires forward slashes in glob patterns, but path.join() on Windows produces backslash-separated paths.

The Bug

When running codemods on Windows, files were silently not being transformed because:

  1. User or code provides a path like C:\Users\...\file.stories.tsx (or uses path.join() to construct it)
  2. tinyglobby requires forward slashes for glob patterns
  3. The backslash path doesn't match any files
  4. Codemod reports "0 files" and does nothing

Root Cause

The cli-storybook version of runCodemod already handles this correctly using the slash package:

// code/lib/cli-storybook/src/automigrate/codemod.ts
const files = await globby(slash(globPattern), { ... });

But the @storybook/codemod version was missing this normalization:

// code/lib/codemod/src/index.ts (before fix)
const files = await tinyglobby([glob, '!**/node_modules', '!**/dist']);

The Fix

Use pathe.normalize() (already used throughout the codebase) to normalize paths before passing to tinyglobby:

// code/lib/codemod/src/index.ts (after fix)
import { normalize } from 'pathe';
// ...
const files = await tinyglobby([normalize(glob), '!**/node_modules', '!**/dist']);

How this was discovered

This pre-existing bug was exposed by the unit tests added in #33646. The tests use path.join(tmpdir(), ...) which produces backslash paths on Windows, causing the tests to fail on Windows CI (ci:daily). The bug itself has existed longer - it would have affected any Windows user calling the codemod with a backslash path.

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!

This was caught by the existing unit tests in src/index.test.ts which were failing on Windows CI (ci:daily). The fix makes those tests pass. This affects real Windows users, not just tests - anyone using npx storybook migrate on Windows with backslash paths would be affected.

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
    • Fixed glob pattern path handling on Windows to ensure consistent use of forward-slash notation, improving cross-platform compatibility.
    • Improved reliability of file matching and downstream processing on Windows systems, reducing cases of missed or incorrectly processed files.

✏️ Tip: You can customize this high-level summary in your review settings.

@kasperpeulen kasperpeulen added bug ci:daily Run the CI jobs that normally run in the daily job. labels Jan 30, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 30, 2026

View your CI Pipeline Execution ↗ for commit 5f4ed14

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 19m 50s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-30 10:29:28 UTC

@kasperpeulen kasperpeulen force-pushed the kasper/fix-codemod-windows branch 2 times, most recently from 7757879 to 6bb0e14 Compare January 30, 2026 08:25
Normalize backslashes to forward slashes in glob patterns before passing
them to tinyglobby. On Windows, path.join() produces backslash-separated
paths, but glob libraries require forward slashes.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@kasperpeulen kasperpeulen force-pushed the kasper/fix-codemod-windows branch from 6bb0e14 to 7ef33d0 Compare January 30, 2026 08:27
@kasperpeulen kasperpeulen marked this pull request as ready for review January 30, 2026 08:30
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 30, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Imports normalize from pathe and applies it to glob patterns passed to tinyglobby, ensuring glob patterns use forward slashes on Windows and preserving existing filtering/processing logic.

Changes

Cohort / File(s) Summary
Path Normalization
code/lib/codemod/src/index.ts
Added normalize import from pathe and wrapped glob patterns with normalize(...) before building the tinyglobby file list to ensure consistent forward-slash globs on Windows.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


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

@valentinpalkovic valentinpalkovic merged commit 4d07f57 into next Jan 30, 2026
12 of 16 checks passed
@valentinpalkovic valentinpalkovic deleted the kasper/fix-codemod-windows branch January 30, 2026 10:10
@github-actions github-actions Bot mentioned this pull request Jan 30, 2026
24 tasks
@kasperpeulen kasperpeulen added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jan 30, 2026
@github-actions github-actions Bot mentioned this pull request Feb 2, 2026
11 tasks
valentinpalkovic added a commit that referenced this pull request Feb 2, 2026
Codemod: Fix glob pattern handling on Windows
(cherry picked from commit 4d07f57)
@github-actions github-actions Bot mentioned this pull request Feb 2, 2026
13 tasks
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:daily Run the CI jobs that normally run in the daily job. patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants