Skip to content

Commit

Permalink
fix(watcher): fix watcher unable to find common directory on Windows (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
OriginalEXE authored Oct 12, 2023
1 parent 33f35a5 commit 5d6b6d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/stupid-onions-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/cli': patch
---

fix watcher unable to find highest common directory on Windows
6 changes: 5 additions & 1 deletion packages/graphql-codegen-cli/src/utils/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ const findHighestCommonDirectory = async (files: string[]): Promise<string> => {
// e.g. mm.scan("/**/foo/bar").base -> "/" ; mm.scan("/foo/bar/**/fizz/*.graphql") -> /foo/bar
const dirPaths = files
.map(filePath => (isAbsolute(filePath) ? filePath : resolve(filePath)))
.map(patterned => mm.scan(patterned).base);
// mm.scan doesn't know how to handle Windows \ path separator
.map(patterned => patterned.replace(/\\/g, '/'))
.map(patterned => mm.scan(patterned).base)
// revert the separators to the platform-supported ones
.map(base => base.replace(/\//g, sep));

// Return longest common prefix if it's accessible, otherwise process.cwd()
return (async (maybeValidPath: string) => {
Expand Down

0 comments on commit 5d6b6d9

Please sign in to comment.