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)

## [email protected]

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

## [email protected]

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

## [email protected]
Expand All @@ -47,10 +51,10 @@
## [email protected]

- 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`

## [email protected]

Expand All @@ -59,9 +63,10 @@
## `[email protected]`

- `[email protected]`

- 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.)

- `[email protected]`
- `[email protected]`
Expand All @@ -76,14 +81,18 @@

## `[email protected]`

- This version should not be used as it was published without depended-on packages. Please use `[email protected]` instead.
- This version should not be used as it was published without depended-on packages. Please use `[email protected]` instead.

## `[email protected]`

- This version was not actually published.

## `[email protected]`

- This version was not actually published.

## `[email protected]`

- `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 @@
## `[email protected]`

- `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)

## `[email protected]`

- 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`.

## `[email protected]`

- 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.

## `[email protected]`

Expand All @@ -117,7 +126,7 @@
## `[email protected]`

- `[email protected]`
- 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)

## `[email protected]`

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