From 5d6b6d90f225c66d4f42617be22e75dce803165b Mon Sep 17 00:00:00 2001 From: Ante Sepic Date: Thu, 12 Oct 2023 21:22:56 +0200 Subject: [PATCH] fix(watcher): fix watcher unable to find common directory on Windows (#9698) --- .changeset/stupid-onions-tap.md | 5 +++++ packages/graphql-codegen-cli/src/utils/watcher.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/stupid-onions-tap.md diff --git a/.changeset/stupid-onions-tap.md b/.changeset/stupid-onions-tap.md new file mode 100644 index 00000000000..dbc0621999a --- /dev/null +++ b/.changeset/stupid-onions-tap.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/cli': patch +--- + +fix watcher unable to find highest common directory on Windows diff --git a/packages/graphql-codegen-cli/src/utils/watcher.ts b/packages/graphql-codegen-cli/src/utils/watcher.ts index b2420f65cfa..bef6702414d 100644 --- a/packages/graphql-codegen-cli/src/utils/watcher.ts +++ b/packages/graphql-codegen-cli/src/utils/watcher.ts @@ -229,7 +229,11 @@ const findHighestCommonDirectory = async (files: string[]): Promise => { // 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) => {