Skip to content

Commit

Permalink
[VSCode] Fix detection of projects inside folders (#519)
Browse files Browse the repository at this point in the history
* [VSCode] Fix detection of projects inside folders

* Exclude node_modules when scanning for config files
  • Loading branch information
shadaj authored Jul 30, 2018
1 parent 4eee386 commit 5a496e1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
15 changes: 13 additions & 2 deletions packages/apollo-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface DocumentSet {
}

export interface ApolloConfig {
configFile: string;
projectFolder: string;
name?: string;
schemas?: { [name: string]: SchemaDependency }; // path to JSON introspection, if not provided endpoint will be used
Expand Down Expand Up @@ -100,6 +101,7 @@ function loadDocumentSet(obj: any): DocumentSet {

export function loadConfig(
obj: any,
configFile: string,
configDir: string,
defaultEndpoint: boolean,
defaultSchema: boolean
Expand All @@ -114,6 +116,7 @@ export function loadConfig(
}

return {
configFile,
projectFolder: configDir,
schemas: schemasObj,
name: basename(configDir),
Expand All @@ -136,6 +139,7 @@ export function loadConfigFromFile(
delete require.cache[require.resolve(file)];
return loadConfig(
require(file),
file,
dirname(file),
defaultEndpoint,
defaultSchema
Expand All @@ -145,12 +149,19 @@ export function loadConfigFromFile(
if (apolloKey) {
return loadConfig(
apolloKey,
file,
dirname(file),
defaultEndpoint,
defaultSchema
);
} else {
return loadConfig({}, dirname(file), defaultEndpoint, defaultSchema);
return loadConfig(
{},
file,
dirname(file),
defaultEndpoint,
defaultSchema
);
}
} else {
throw new Error("Unsupported config file format");
Expand All @@ -175,7 +186,7 @@ export function findAndLoadConfig(
defaultSchema
);
} else {
return loadConfig({}, dir, defaultEndpoint, defaultSchema);
return loadConfig({}, dir, dir, defaultEndpoint, defaultSchema);
}
}

Expand Down
38 changes: 20 additions & 18 deletions packages/apollo-language-server/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,38 @@ export class GraphQLWorkspace {
}

addProjectsInFolder(folder: WorkspaceFolder) {
const apolloConfigFiles: string[] = fg.sync("apollo.config.js", {
const apolloConfigFiles: string[] = fg.sync("**/apollo.config.js", {
cwd: Uri.parse(folder.uri).fsPath,
absolute: true
absolute: true,
ignore: "**/node_modules/**"
});

apolloConfigFiles.push(
...fg.sync("package.json", {
...fg.sync("**/package.json", {
cwd: Uri.parse(folder.uri).fsPath,
absolute: true
absolute: true,
ignore: "**/node_modules/**"
})
);

const projectConfigs = apolloConfigFiles.flatMap(configFile => {
const loadedConfig = findAndLoadConfig(dirname(configFile), false, true);

if (loadedConfig) {
return [
{
config: loadedConfig,
configFile
}
];
} else {
return [];
const apolloConfigFolders = new Set<string>(
apolloConfigFiles.map(f => dirname(f))
);

const projectConfigs = Array.from(apolloConfigFolders).flatMap(
configFolder => {
try {
return [findAndLoadConfig(configFolder, false, true)];
} catch (e) {
console.error(e);
return [];
}
}
});
);

const projects = projectConfigs.map(projectConfig => {
const project = new GraphQLProject(
projectConfig.config,
projectConfig,
projectConfig.configFile
);

Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a496e1

Please sign in to comment.