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 .cjs file extension #2342 #2381

Merged
merged 9 commits into from
Aug 12, 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
37 changes: 23 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
- <First `apollo-language-server` related entry goes here>
- `apollo-tools`
- <First `apollo-tools` related entry goes here>
- `vscode-apollo`
- Adds support for àpollo.config.cjs`files, to allow Projects with`type: module`in package.json (Fixes #2342) [PR #2381](https://github.com/apollographql/apollo-tooling/pull/2381)

## apollo-tools@0.5.1

- Remove dependency on `apollo-env`, so using this package no longer installs polyfills.

## apollo-graphql@0.9.3

- Complex directive arguments don't break `transformSchema` (Fixes #2162) [PR #2335](https://github.com/apollographql/apollo-tooling/pull/2335)

## apollo@2.33.2
Expand All @@ -47,10 +51,10 @@
## apollo-env@0.9.0

- The following utility functions are no longer exported from `apollo-env` and can now be found in the `apollo-graphql` library:
- `createHash`
- `isNodeLike`
- `mapValues`
- `isNotNullOrDefined`
- `createHash`
- `isNodeLike`
- `mapValues`
- `isNotNullOrDefined`

## apollo-graphql@0.9.0

Expand All @@ -59,9 +63,10 @@
## `apollo@2.32.5`

- `apollo@2.32.5`

- Bump version of `env-ci` [#1754](https://github.com/apollographql/apollo-tooling/pull/1754) [Issue #2219](https://github.com/apollographql/apollo-tooling/issues/2219)

Due to human error during the release process, the following packages also had their versions bumped, despite having no known significant changes. (Apologies, from that human.)
Due to human error during the release process, the following packages also had their versions bumped, despite having no known significant changes. (Apologies, from that human.)

- `apollo-codegen-core@0.39.3`
- `apollo-codegen-flow@0.37.3`
Expand All @@ -76,14 +81,18 @@

## `apollo@2.32.4`

- This version should not be used as it was published without depended-on packages. Please use `apollo@2.32.5` instead.
- This version should not be used as it was published without depended-on packages. Please use `apollo@2.32.5` instead.

## `apollo@2.32.3`

- This version was not actually published.

## `apollo@2.32.3`

- This version was not actually published.

## `apollo@2.32.1`

- `apollo-codegen-swift`
- Fix issue where a query referencing many fragments caused type checking for `queryDocument` to time out [#2198](https://github.com/apollographql/apollo-tooling/pull/2198)

Expand All @@ -95,19 +104,19 @@
## `apollo@2.31.2`

- `apollo-codegen-swift`
- Fix bug in generated compound type names that lead to structName being inconsistent throughout codegen [#2170](https://github.com/apollographql/apollo-tooling/pull/2170)
- Fix bug in generated compound type names that lead to structName being inconsistent throughout codegen [#2170](https://github.com/apollographql/apollo-tooling/pull/2170)

## `apollo@2.31.1`

- Update CLI default API domain from `engine-graphql.apollographql.com` to `graphql.api.apollographql.com`.
Users that have set up support for corporate proxies or firewalls may need to update configurations.
- Accept GitLab remote URLs when fetching git info for service:check and service:push [#2104](https://github.com/apollographql/apollo-tooling/pull/2104)
- `--commitId` in `service:check` and `service:push` overrides the current commit ID otherwise read through [env-ci](https://www.npmjs.com/package/env-ci).
- `service:push` now takes `--author` and `--branch` matching `service:check`.
- Update CLI default API domain from `engine-graphql.apollographql.com` to `graphql.api.apollographql.com`.
Users that have set up support for corporate proxies or firewalls may need to update configurations.
- Accept GitLab remote URLs when fetching git info for service:check and service:push [#2104](https://github.com/apollographql/apollo-tooling/pull/2104)
- `--commitId` in `service:check` and `service:push` overrides the current commit ID otherwise read through [env-ci](https://www.npmjs.com/package/env-ci).
- `service:push` now takes `--author` and `--branch` matching `service:check`.

## `apollo-graphql@0.6.0`

- Rename `defaultEngineReportingSignature` to `defaultUsageReportingSignature`; the old name continues to be exported as well.
- Rename `defaultEngineReportingSignature` to `defaultUsageReportingSignature`; the old name continues to be exported as well.

## `apollo@2.30.2`

Expand All @@ -117,7 +126,7 @@
## `apollo@2.30.1`

- `apollo-codegen-swift@0.37.7`
- Generate JSON file including fragments when --operationIds option is provided [#2017](https://github.com/apollographql/apollo-tooling/pull/2017)
- Generate JSON file including fragments when --operationIds option is provided [#2017](https://github.com/apollographql/apollo-tooling/pull/2017)

## `apollo@2.30.0`

Expand Down
4 changes: 3 additions & 1 deletion packages/apollo-language-server/src/config/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ 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"];

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
7 changes: 6 additions & 1 deletion packages/apollo-language-server/src/project/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ 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
});
Expand Down
7 changes: 6 additions & 1 deletion packages/apollo-language-server/src/project/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ 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
});
Expand Down
6 changes: 5 additions & 1 deletion packages/apollo-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ 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.cjs") ||
uri.endsWith("apollo.config.js") ||
uri.endsWith(".env")
) {
workspace.reloadProjectForConfig(uri);
}

Expand Down
13 changes: 8 additions & 5 deletions packages/apollo-language-server/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ export class GraphQLWorkspace {
-- ~/:user/server (GraphQLProject) as WorkspaceFolder

*/
const apolloConfigFiles: string[] = fg.sync("**/apollo.config.@(js|ts)", {
cwd: URI.parse(folder.uri).fsPath,
absolute: true,
ignore: "**/node_modules/**"
});
const apolloConfigFiles: string[] = fg.sync(
"**/apollo.config.@(js|ts|cjs)",
{
cwd: URI.parse(folder.uri).fsPath,
absolute: true,
ignore: "**/node_modules/**"
}
);

// only have unique possible folders
const apolloConfigFolders = new Set<string>(apolloConfigFiles.map(dirname));
Expand Down