Skip to content

Commit 9feb85c

Browse files
committed
fix includes/excludes glob matching
1 parent 0af7fe2 commit 9feb85c

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- `apollo-language-server`
88
- Better error handling in ApolloEngineClient [#953](https://github.com/apollographql/apollo-tooling/pull/953)
99
- Added a warning when there are 0 files found in a project [#1007](https://github.com/apollographql/apollo-tooling/pull/1007)
10+
- Allow relative paths in includes/excludes globs [#1007](https://github.com/apollographql/apollo-tooling/pull/1007)
1011
- `vscode-apollo`
1112
- Fix inline graphql highlighting in Vue `<script>` tags [#981](https://github.com/apollographql/apollo-tooling/pull/981)
1213

packages/apollo-language-server/src/fileSet.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,18 @@ export class FileSet {
5151
}
5252

5353
includesFile(filePath: string): boolean {
54-
filePath = relative(this.rootURI.fsPath, filePath);
55-
56-
return (
57-
this.includes.some(include => minimatch(filePath, include)) &&
58-
!this.excludes.some(exclude => minimatch(filePath, exclude))
59-
);
54+
return this.allFiles().includes(relative(this.rootURI.fsPath, filePath));
6055
}
6156

6257
allFiles(): string[] {
63-
return this.includes
64-
.flatMap(include =>
65-
glob.sync(include, { cwd: this.rootURI.fsPath, absolute: true })
66-
)
67-
.filter(
68-
filePath =>
69-
!this.excludes.some(exclude =>
70-
minimatch(relative(this.rootURI.fsPath, filePath), exclude)
71-
)
72-
);
58+
// since glob.sync takes a single patttern, but we allow an array of `includes`, we can join all the
59+
// `includes` globs into a single pattern and pass to glob.sync The `ignore` option does, however, allow
60+
// an array of globs to ignore, so we can pass it in directly
61+
const joinedIncludes = `{${this.includes.join(",")}}`;
62+
return glob.sync(joinedIncludes, {
63+
cwd: this.rootURI.fsPath,
64+
absolute: true,
65+
ignore: this.excludes
66+
});
7367
}
7468
}

0 commit comments

Comments
 (0)