Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support type: module with .cjsfile extension #4

Merged
merged 3 commits into from
Aug 11, 2021
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
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