From efbec61b8c9e6e795458ae9648984b845997a9e8 Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr <45965090+alexanderniebuhr@users.noreply.github.com> Date: Thu, 22 Jul 2021 07:45:58 +0200 Subject: [PATCH 1/2] fix: support `type: module` with `.cjs`file extension --- package.json | 3 ++- src/language-server/config/loadConfig.ts | 4 +++- src/language-server/project/client.ts | 2 +- src/language-server/project/service.ts | 2 +- src/language-server/server.ts | 2 +- src/language-server/workspace.ts | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 0bad02d2..f1de9f3d 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,8 @@ ], "icon": "images/icon-apollo-blue-400x400.png", "activationEvents": [ - "workspaceContains:**/apollo.config.[jt]s" + "workspaceContains:**/apollo.config.[jt]s", + "workspaceContains:**/apollo.config.cjs" ], "contributes": { "configuration": { diff --git a/src/language-server/config/loadConfig.ts b/src/language-server/config/loadConfig.ts index bf69f2fc..0f6dd26d 100644 --- a/src/language-server/config/loadConfig.ts +++ b/src/language-server/config/loadConfig.ts @@ -21,7 +21,8 @@ const MODULE_NAME = "apollo"; const defaultFileNames = [ "package.json", `${MODULE_NAME}.config.js`, - `${MODULE_NAME}.config.ts` + `${MODULE_NAME}.config.ts`, + `${MODULE_NAME}.config.cjs` ]; const envFileNames = [".env", ".env.local"]; @@ -29,6 +30,7 @@ const loaders = { // XXX improve types for config ".json": (cosmiconfig as any).loadJson as LoaderEntry, ".js": (cosmiconfig as any).loadJs as LoaderEntry, + ".cjs": (cosmiconfig as any).loadJs as LoaderEntry, ".ts": { async: TypeScriptLoader } diff --git a/src/language-server/project/client.ts b/src/language-server/project/client.ts index 54d931ad..c1092eea 100644 --- a/src/language-server/project/client.ts +++ b/src/language-server/project/client.ts @@ -106,7 +106,7 @@ export class GraphQLClientProject extends GraphQLProject { // the URI of the folder _containing_ the apollo.config.js is the true project's root. // 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"], + includes: [...config.client.includes, ".env", "apollo.config.js", "apollo.config.cjs"], excludes: config.client.excludes, configURI: config.configURI }); diff --git a/src/language-server/project/service.ts b/src/language-server/project/service.ts index 4661a010..dcff1003 100644 --- a/src/language-server/project/service.ts +++ b/src/language-server/project/service.ts @@ -26,7 +26,7 @@ export class GraphQLServiceProject extends GraphQLProject { }: GraphQLServiceProjectConfig) { const fileSet = new FileSet({ rootURI: config.configDirURI || rootURI, - includes: [...config.service.includes, ".env", "apollo.config.js"], + includes: [...config.service.includes, ".env", "apollo.config.js", "apollo.config.cjs"], excludes: config.service.excludes, configURI: config.configURI }); diff --git a/src/language-server/server.ts b/src/language-server/server.ts index ebf6ae8d..22cf01ae 100644 --- a/src/language-server/server.ts +++ b/src/language-server/server.ts @@ -131,7 +131,7 @@ documents.onDidChangeContent( connection.onDidChangeWatchedFiles(params => { for (const { uri, type } of params.changes) { - if (uri.endsWith("apollo.config.js") || uri.endsWith(".env")) { + if (uri.endsWith("apollo.config.js") || uri.endsWith("apollo.config.cjs") || uri.endsWith(".env")) { workspace.reloadProjectForConfig(uri); } diff --git a/src/language-server/workspace.ts b/src/language-server/workspace.ts index ae4070e8..f0e9d2be 100644 --- a/src/language-server/workspace.ts +++ b/src/language-server/workspace.ts @@ -114,7 +114,7 @@ export class GraphQLWorkspace { -- ~/:user/server (GraphQLProject) as WorkspaceFolder */ - const apolloConfigFiles: string[] = fg.sync("**/apollo.config.@(js|ts)", { + const apolloConfigFiles: string[] = fg.sync("**/apollo.config.@(js|ts|cjs)", { cwd: URI.parse(folder.uri).fsPath, absolute: true, ignore: "**/node_modules/**" From 9a1fdf4a166ecc227ba4f9f1e4b91c93c599f3ca Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr <45965090+alexanderniebuhr@users.noreply.github.com> Date: Mon, 9 Aug 2021 16:22:28 +0200 Subject: [PATCH 2/2] refactor: :recycle: update to support new structure --- src/language-server/project/base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/language-server/project/base.ts b/src/language-server/project/base.ts index f57955f7..4bdf5cb0 100644 --- a/src/language-server/project/base.ts +++ b/src/language-server/project/base.ts @@ -102,7 +102,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider { : config.service; const fileSet = new FileSet({ rootURI: this.rootURI, - includes: [...includes, ".env", "apollo.config.js"], + includes: [...includes, ".env", "apollo.config.js", "apollo.config.cjs"], // We do not want to include the local schema file in our list of documents excludes: [...excludes, ...this.getRelativeLocalSchemaFilePaths()], configURI: config.configURI,