fix(workshop-utils): Windows path compatibility in diff pipeline#608
Merged
kentcdodds merged 1 commit intoMay 17, 2026
Merged
Conversation
On Windows, `path.join` and `path.relative` return backslash-separated
paths. Three places in `diff.server.ts` assumed POSIX-style forward
slashes, which caused the Diff tab in any workshop to crash for Windows
users with:
TypeError: Cannot read properties of undefined (reading 'trim')
at processPatch (.../@pierre/diffs/.../parsePatchFiles.ts:90)
Root cause chain:
1. `copyUnignoredFiles` passes `path.relative(...)` directly to the
`ignore` package, which only understands POSIX paths. Patterns with
slashes like `**/build/` silently fail to match on Windows.
2. `prepareForDiff` builds temp copy paths with `path.join`. When
passed to `git diff --no-index`, git quotes any path containing a
backslash. The quoted output trips the downstream `@pierre/diffs`
patch parser.
3. `getDiffPatchImpl` and `getDiffOutputWithRelativePaths` use
`.slice(1)` to strip a leading slash. On POSIX (`/tmp/foo`) this
works. On Windows (`C:/Users/foo`) it strips the drive letter.
This patch normalises paths to POSIX form wherever they cross into git,
the `ignore` package, or the patch-text replacements. The `a${path}`
replaceAll patterns are also changed to `a/${relative}` so they line up
with what git emits on both platforms.
No behaviour change on POSIX. On Windows the Diff tab now renders
instead of crashing.
Member
|
Bugbot review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three small Windows path fixes in
packages/workshop-utils/src/diff.server.ts.Why
On Windows,
path.joinandpath.relativereturn backslash-separated paths. The diff pipeline assumed POSIX-style forward slashes in three places, so the Diff tab in any workshop crashes for Windows users with:The root cause chain:
Changes
`copyUnignoredFiles` — normalise `path.relative(...)` to POSIX before passing to `ignore`. Without this, gitignore patterns containing slashes silently fail to match on Windows.
`prepareForDiff` — normalise `app1CopyPath` / `app2CopyPath` to POSIX after `path.join`. Git now sees forward-slash paths and emits unquoted output, which the patch parser can handle.
`getDiffPatchImpl` and `getDiffOutputWithRelativePaths` — replace `.slice(1)` with `.replace(/^//, '')` so Windows paths (no leading slash) keep their drive letter. The `a${absPath}` patterns become `a/${relativePath}` so they line up with the slash that git always inserts, on both platforms.
A small `toPosixPath(p)` helper is defined locally in the file; happy to extract it to a shared module if you'd prefer.
Testing
Notes
The downstream `@pierre/diffs` parser also has a latent bug — its `diff --git` line destructure only reads the unquoted capture groups, even though its own regex has a quoted-path branch. Fixing this PR is sufficient to make the diff tab work because git no longer emits quoted paths, but the parser fix is worth pursuing upstream as well.