Skip to content

Commit

Permalink
fix: support type: module with .cjsfile extension (#4)
Browse files Browse the repository at this point in the history
* fix: support `type: module` with `.cjs`file extension

* refactor: ♻️ update to support new structure
  • Loading branch information
alexanderniebuhr authored Aug 11, 2021
1 parent 9e2eafa commit 5036d49
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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": {
Expand Down
2 changes: 2 additions & 0 deletions src/language-server/config/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const defaultFileNames = [
"package.json",
`${MODULE_NAME}.config.js`,
`${MODULE_NAME}.config.ts`,
`${MODULE_NAME}.config.cjs`
];
const envFileNames = [".env", ".env.local"];

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,
},
Expand Down
2 changes: 1 addition & 1 deletion src/language-server/project/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/language-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/language-server/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/**",
Expand Down

0 comments on commit 5036d49

Please sign in to comment.