Skip to content

Commit 5d6b6d9

Browse files
authored
fix(watcher): fix watcher unable to find common directory on Windows (#9698)
1 parent 33f35a5 commit 5d6b6d9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/stupid-onions-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/cli': patch
3+
---
4+
5+
fix watcher unable to find highest common directory on Windows

packages/graphql-codegen-cli/src/utils/watcher.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ const findHighestCommonDirectory = async (files: string[]): Promise<string> => {
229229
// e.g. mm.scan("/**/foo/bar").base -> "/" ; mm.scan("/foo/bar/**/fizz/*.graphql") -> /foo/bar
230230
const dirPaths = files
231231
.map(filePath => (isAbsolute(filePath) ? filePath : resolve(filePath)))
232-
.map(patterned => mm.scan(patterned).base);
232+
// mm.scan doesn't know how to handle Windows \ path separator
233+
.map(patterned => patterned.replace(/\\/g, '/'))
234+
.map(patterned => mm.scan(patterned).base)
235+
// revert the separators to the platform-supported ones
236+
.map(base => base.replace(/\//g, sep));
233237

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

0 commit comments

Comments
 (0)