Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Upcoming

- `apollo-language-server`
- Added a warning when there are 0 files found in a project [#1007](https://github.com/apollographql/apollo-tooling/pull/1007)
- Allow relative paths in includes/excludes globs [#1007](https://github.com/apollographql/apollo-tooling/pull/1007)

## `apollo-codegen-typescript@0.32.7`, `apollo-codegen-scala@0.33.2`, `apollo-graphql@1.0.2`

- `apollo-codegen-typescript@0.32.7`
Expand Down
51 changes: 34 additions & 17 deletions packages/apollo-language-server/src/fileSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export class FileSet {
constructor({
rootURI,
includes,
excludes
excludes,
configURI
}: {
rootURI: URI;
includes: string[];
excludes: string[];
configURI?: URI;
}) {
invariant(rootURI, `Must provide "rootURI".`);
invariant(includes, `Must provide "includes".`);
Expand All @@ -25,27 +27,42 @@ export class FileSet {
this.rootURI = rootURI;
this.includes = includes;
this.excludes = excludes;

/**
* This function is used in the Array.filter function below it to remove any .env files and config files.
* If there are 0 files remaining after removing those files, we should warn the user that their config
* may be wrong. We shouldn't throw an error here, since they could just be initially setting up a project
* and there's no way to know for sure that there _should_ be files.
*/
const filterConfigAndEnvFiles = (path: string) =>
!(
path.includes("apollo.config") ||
path.includes(".env") ||
(configURI && path === configURI.fsPath)
);
if (this.allFiles().filter(filterConfigAndEnvFiles).length === 0) {
console.warn(
"⚠️ It looks like there are 0 files associated with this Apollo Project. " +
"This may be because you don't have any files yet, or your includes/excludes " +
"fields are configured incorrectly, and Apollo can't find your files. " +
"For help configuring Apollo projects, see this guide: https://bit.ly/2ByILPj"
);
}
}

includesFile(filePath: string): boolean {
filePath = relative(this.rootURI.fsPath, filePath);

return (
this.includes.some(include => minimatch(filePath, include)) &&
!this.excludes.some(exclude => minimatch(filePath, exclude))
);
return this.allFiles().includes(relative(this.rootURI.fsPath, filePath));
}

allFiles(): string[] {
return this.includes
.flatMap(include =>
glob.sync(include, { cwd: this.rootURI.fsPath, absolute: true })
)
.filter(
filePath =>
!this.excludes.some(exclude =>
minimatch(relative(this.rootURI.fsPath, filePath), exclude)
)
);
// since glob.sync takes a single pattern, but we allow an array of `includes`, we can join all the
// `includes` globs into a single pattern and pass to glob.sync. The `ignore` option does, however, allow
// an array of globs to ignore, so we can pass it in directly
const joinedIncludes = `{${this.includes.join(",")}}`;
return glob.sync(joinedIncludes, {
Comment thread
JakeDawkins marked this conversation as resolved.
cwd: this.rootURI.fsPath,
absolute: true,
ignore: this.excludes
});
}
}
3 changes: 2 additions & 1 deletion packages/apollo-language-server/src/project/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export class GraphQLClientProject extends GraphQLProject {
// if a config doesn't have a uri associated, we can assume the `rootURI` is the project's root.
rootURI: config.configDirURI || rootURI,
includes: [...config.client.includes, ".env", "apollo.config.js"],
excludes: config.client.excludes
excludes: config.client.excludes,
configURI: config.configURI
});

super({ config, fileSet, loadingHandler, clientIdentity });
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo-language-server/src/project/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class GraphQLServiceProject extends GraphQLProject {
const fileSet = new FileSet({
rootURI: config.configDirURI || rootURI,
includes: [...config.service.includes, ".env", "apollo.config.js"],
excludes: config.service.excludes
excludes: config.service.excludes,
configURI: config.configURI
});

super({ config, fileSet, loadingHandler, clientIdentity });
Expand Down