Skip to content

fix(filesystem): normalize watcher paths to forward slashes on Windows#35715

Open
C0d3N1nja97342 wants to merge 1 commit into
anomalyco:devfrom
C0d3N1nja97342:fix/watcher-backslash-paths-dev
Open

fix(filesystem): normalize watcher paths to forward slashes on Windows#35715
C0d3N1nja97342 wants to merge 1 commit into
anomalyco:devfrom
C0d3N1nja97342:fix/watcher-backslash-paths-dev

Conversation

@C0d3N1nja97342

Copy link
Copy Markdown

Issue for this PR

Closes #35329

Type of change

  • Bug fix

What does this PR do?

@parcel/watcher emits paths with OS-native separators, so on Windows the subscribe callback receives backslash paths (e.g. C:\foo\bar.txt). The watcher published these verbatim to Event.Updated, but the rest of the codebase compares and stores paths with forward slashes — so on Windows, watcher event paths never matched anything that expected forward slashes (file operations, @file mentions, cache keys, etc.).

The fix normalizes update.path to forward slashes before publishing, via a small normalizeWatchPath helper that mirrors the existing storagePath normalization in database/path.ts. It's a no-op on non-Windows.

How did you verify your code works?

  • Reproduced the root cause on Windows with a minimal @parcel/watcher script: the raw callback path is C:\Users\...\sub (backslashes confirmed).
  • Applied the same replaceAll("\\", "/") normalization in that script and confirmed the emitted path becomes C:/Users/.../sub (no backslashes), including for nested subdirectories.
  • tsc --noEmit on packages/core is clean (0 errors) with these changes.
  • Added a regression test asserting emitted paths contain no backslashes.
  • Wrapped the expected paths in the existing live watcher tests with a toPosix helper so they still compare correctly now that emitted paths are forward slashes (previously both sides used backslashes on Windows, so the comparison passed without actually exercising normalization).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@parcel/watcher emits paths with OS-native separators, so on Windows the
callback receives backslash paths (e.g. `C:\foo\bar.txt`). The watcher
published these verbatim, but the rest of the codebase compares and stores
paths with forward slashes — causing path mismatches and inconsistent
behavior (file operations, @file mentions, cache keys) on Windows.

Normalize `update.path` to forward slashes before publishing
(mirroring the `storagePath` normalization in database/path.ts). The
option is a no-op on non-Windows platforms.

Test changes:
- Add a regression test asserting emitted paths contain no backslashes.
- Wrap expected paths in the existing live tests with a `toPosix` helper
  so they compare correctly now that emitted paths are forward slashes
  (previously both sides used backslashes on Windows, so the comparison
  passed by coincidence without actually exercising normalization).

Closes anomalyco#35329
@C0d3N1nja97342
C0d3N1nja97342 force-pushed the fix/watcher-backslash-paths-dev branch from a006a73 to 8c8e03e Compare July 9, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File watcher emits backslash paths on Windows

1 participant