Skip to content

Commit c9c9fef

Browse files
committed
ESM support
1 parent 1b9ceb7 commit c9c9fef

File tree

55 files changed

+669
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+669
-136
lines changed

.changeset/sharp-nails-clean.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
'@graphql-cli/codegen': major
3+
'@graphql-codegen/cli': major
4+
'@graphql-codegen/core': major
5+
'@graphql-codegen/c-sharp': major
6+
'@graphql-codegen/c-sharp-operations': major
7+
'@graphql-codegen/flow': major
8+
'@graphql-codegen/flow-operations': major
9+
'@graphql-codegen/flow-resolvers': major
10+
'@graphql-codegen/java-apollo-android': major
11+
'@graphql-codegen/java-common': major
12+
'@graphql-codegen/java': major
13+
'@graphql-codegen/kotlin': major
14+
'@graphql-codegen/java-resolvers': major
15+
'@graphql-codegen/add': major
16+
'@graphql-codegen/fragment-matcher': major
17+
'@graphql-codegen/introspection': major
18+
'@graphql-codegen/jsdoc': major
19+
'@graphql-codegen/schema-ast': major
20+
'@graphql-codegen/time': major
21+
'@graphql-codegen/urql-introspection': major
22+
'@graphql-codegen/visitor-plugin-common': major
23+
'@graphql-codegen/typescript-apollo-angular': major
24+
'@graphql-codegen/typescript-apollo-client-helpers': major
25+
'@graphql-codegen/typescript-compatibility': major
26+
'@graphql-codegen/typescript-document-nodes': major
27+
'@graphql-codegen/typescript-generic-sdk': major
28+
'@graphql-codegen/typescript-graphql-files-modules': major
29+
'@graphql-codegen/typescript-graphql-request': major
30+
'@graphql-codegen/typescript-mongodb': major
31+
'@graphql-codegen/named-operations-object': major
32+
'@graphql-codegen/typescript-oclif': major
33+
'@graphql-codegen/typescript-operations': major
34+
'@graphql-codegen/typescript-react-apollo': major
35+
'@graphql-codegen/typescript-react-offix': major
36+
'@graphql-codegen/typescript-react-query': major
37+
'@graphql-codegen/typescript-resolvers': major
38+
'@graphql-codegen/typescript-stencil-apollo': major
39+
'@graphql-codegen/typescript-type-graphql': major
40+
'@graphql-codegen/typed-document-node': major
41+
'@graphql-codegen/typescript': major
42+
'@graphql-codegen/typescript-urql': major
43+
'@graphql-codegen/typescript-urql-graphcache': major
44+
'@graphql-codegen/typescript-vue-apollo': major
45+
'@graphql-codegen/graphql-modules-preset': major
46+
'@graphql-codegen/import-types-preset': major
47+
'@graphql-codegen/near-operation-file-preset': major
48+
'@graphql-codegen/testing': major
49+
'@graphql-codegen/plugin-helpers': major
50+
---
51+
52+
ESM support

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"apollo-server": "2.25.0",
6060
"auto-bind": "4.0.0",
6161
"babel-jest": "27.0.2",
62-
"bob-the-bundler": "1.2.1",
62+
"@ardatan/bob-the-bundler": "1.2.6",
6363
"eslint": "7.28.0",
6464
"eslint-config-prettier": "8.3.0",
6565
"eslint-config-standard": "16.0.3",

packages/graphql-cli-codegen-plugin/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@
2929
"@graphql-codegen/cli": "1.21.5",
3030
"@graphql-cli/common": "4.1.0"
3131
},
32-
"main": "dist/index.cjs.js",
33-
"module": "dist/index.esm.js",
32+
"main": "dist/index.js",
33+
"module": "dist/index.mjs",
34+
"exports": {
35+
".": {
36+
"require": "./dist/index.js",
37+
"import": "./dist/index.mjs"
38+
},
39+
"./*": {
40+
"require": "./dist/*.js",
41+
"import": "./dist/*.mjs"
42+
}
43+
},
3444
"typings": "dist/index.d.ts",
3545
"typescript": {
3646
"definition": "dist/index.d.ts"

packages/graphql-codegen-cli/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,18 @@
9999
"peerDependencies": {
100100
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
101101
},
102-
"main": "dist/index.cjs.js",
103-
"module": "dist/index.esm.js",
102+
"main": "dist/index.js",
103+
"module": "dist/index.mjs",
104+
"exports": {
105+
".": {
106+
"require": "./dist/index.js",
107+
"import": "./dist/index.mjs"
108+
},
109+
"./*": {
110+
"require": "./dist/*.js",
111+
"import": "./dist/*.mjs"
112+
}
113+
},
104114
"typings": "dist/index.d.ts",
105115
"typescript": {
106116
"definition": "dist/index.d.ts"

packages/graphql-codegen-cli/src/cli.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { createContext } from './config';
44
import { lifecycleHooks } from './hooks';
55
import { DetailedError } from '@graphql-codegen/plugin-helpers';
66

7-
export function runCli(cmd: string): Promise<any> {
8-
ensureGraphQlPackage();
7+
export async function runCli(cmd: string): Promise<any> {
8+
await ensureGraphQlPackage();
99

1010
switch (cmd) {
1111
case 'init':
@@ -22,9 +22,9 @@ export function runCli(cmd: string): Promise<any> {
2222
}
2323
}
2424

25-
export function ensureGraphQlPackage() {
25+
export async function ensureGraphQlPackage() {
2626
try {
27-
require('graphql');
27+
await import('graphql');
2828
} catch (e) {
2929
throw new DetailedError(
3030
`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency!`,

packages/graphql-codegen-cli/src/utils/listr-renderer.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import { ListrTask } from 'listr';
88
import { DetailedError, isDetailedError } from '@graphql-codegen/plugin-helpers';
99
import { Source } from 'graphql';
1010
import { debugLog, printLogs } from './debugging';
11-
12-
const UpdateRenderer = require('listr-update-renderer');
11+
import UpdateRenderer from 'listr-update-renderer';
1312

1413
export class Renderer {
1514
private updateRenderer: any;

packages/graphql-codegen-core/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@
4343
"@graphql-tools/utils": "^7.9.1",
4444
"tslib": "~2.2.0"
4545
},
46-
"main": "dist/index.cjs.js",
47-
"module": "dist/index.esm.js",
46+
"main": "dist/index.js",
47+
"module": "dist/index.mjs",
48+
"exports": {
49+
".": {
50+
"require": "./dist/index.js",
51+
"import": "./dist/index.mjs"
52+
},
53+
"./*": {
54+
"require": "./dist/*.js",
55+
"import": "./dist/*.mjs"
56+
}
57+
},
4858
"typings": "dist/index.d.ts",
4959
"typescript": {
5060
"definition": "dist/index.d.ts"

packages/plugins/c-sharp/c-sharp-operations/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@
2121
"tslib": "~2.2.0"
2222
},
2323
"sideEffects": false,
24-
"main": "dist/index.cjs.js",
25-
"module": "dist/index.esm.js",
24+
"main": "dist/index.js",
25+
"module": "dist/index.mjs",
26+
"exports": {
27+
".": {
28+
"require": "./dist/index.js",
29+
"import": "./dist/index.mjs"
30+
},
31+
"./*": {
32+
"require": "./dist/*.js",
33+
"import": "./dist/*.mjs"
34+
}
35+
},
2636
"typings": "dist/index.d.ts",
2737
"typescript": {
2838
"definition": "dist/index.d.ts"

packages/plugins/c-sharp/c-sharp/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@
2020
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2121
},
2222
"sideEffects": false,
23-
"main": "dist/index.cjs.js",
24-
"module": "dist/index.esm.js",
23+
"main": "dist/index.js",
24+
"module": "dist/index.mjs",
25+
"exports": {
26+
".": {
27+
"require": "./dist/index.js",
28+
"import": "./dist/index.mjs"
29+
},
30+
"./*": {
31+
"require": "./dist/*.js",
32+
"import": "./dist/*.mjs"
33+
}
34+
},
2535
"typings": "dist/index.d.ts",
2636
"typescript": {
2737
"definition": "dist/index.d.ts"

packages/plugins/flow/flow/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@
2222
"peerDependencies": {
2323
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2424
},
25-
"main": "dist/index.cjs.js",
26-
"module": "dist/index.esm.js",
25+
"main": "dist/index.js",
26+
"module": "dist/index.mjs",
27+
"exports": {
28+
".": {
29+
"require": "./dist/index.js",
30+
"import": "./dist/index.mjs"
31+
},
32+
"./*": {
33+
"require": "./dist/*.js",
34+
"import": "./dist/*.mjs"
35+
}
36+
},
2737
"typings": "dist/index.d.ts",
2838
"typescript": {
2939
"definition": "dist/index.d.ts"

packages/plugins/flow/operations/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@
2323
"peerDependencies": {
2424
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2525
},
26-
"main": "dist/index.cjs.js",
27-
"module": "dist/index.esm.js",
26+
"main": "dist/index.js",
27+
"module": "dist/index.mjs",
28+
"exports": {
29+
".": {
30+
"require": "./dist/index.js",
31+
"import": "./dist/index.mjs"
32+
},
33+
"./*": {
34+
"require": "./dist/*.js",
35+
"import": "./dist/*.mjs"
36+
}
37+
},
2838
"typings": "dist/index.d.ts",
2939
"typescript": {
3040
"definition": "dist/index.d.ts"

packages/plugins/flow/resolvers/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@
2424
"peerDependencies": {
2525
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2626
},
27-
"main": "dist/index.cjs.js",
28-
"module": "dist/index.esm.js",
27+
"main": "dist/index.js",
28+
"module": "dist/index.mjs",
29+
"exports": {
30+
".": {
31+
"require": "./dist/index.js",
32+
"import": "./dist/index.mjs"
33+
},
34+
"./*": {
35+
"require": "./dist/*.js",
36+
"import": "./dist/*.mjs"
37+
}
38+
},
2939
"typings": "dist/index.d.ts",
3040
"typescript": {
3141
"definition": "dist/index.d.ts"

packages/plugins/java/apollo-android/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@
2828
"devDependencies": {
2929
"@types/pluralize": "0.0.29"
3030
},
31-
"main": "dist/index.cjs.js",
32-
"module": "dist/index.esm.js",
31+
"main": "dist/index.js",
32+
"module": "dist/index.mjs",
33+
"exports": {
34+
".": {
35+
"require": "./dist/index.js",
36+
"import": "./dist/index.mjs"
37+
},
38+
"./*": {
39+
"require": "./dist/*.js",
40+
"import": "./dist/*.mjs"
41+
}
42+
},
3343
"typings": "dist/index.d.ts",
3444
"typescript": {
3545
"definition": "dist/index.d.ts"

packages/plugins/java/common/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@
2323
"peerDependencies": {
2424
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2525
},
26-
"main": "dist/index.cjs.js",
27-
"module": "dist/index.esm.js",
26+
"main": "dist/index.js",
27+
"module": "dist/index.mjs",
28+
"exports": {
29+
".": {
30+
"require": "./dist/index.js",
31+
"import": "./dist/index.mjs"
32+
},
33+
"./*": {
34+
"require": "./dist/*.js",
35+
"import": "./dist/*.mjs"
36+
}
37+
},
2838
"typings": "dist/index.d.ts",
2939
"typescript": {
3040
"definition": "dist/index.d.ts"

packages/plugins/java/common/src/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Kind, TypeNode } from 'graphql';
22
import minIndent from 'min-indent';
33

4+
import unixify from 'unixify';
5+
46
export function buildPackageNameFromPath(path: string): string {
5-
const unixify = require('unixify');
67
return unixify(path || '')
78
.replace(/src\/main\/.*?\//, '')
89
.replace(/\//g, '.');

packages/plugins/java/java/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@
2222
"peerDependencies": {
2323
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2424
},
25-
"main": "dist/index.cjs.js",
26-
"module": "dist/index.esm.js",
25+
"main": "dist/index.js",
26+
"module": "dist/index.mjs",
27+
"exports": {
28+
".": {
29+
"require": "./dist/index.js",
30+
"import": "./dist/index.mjs"
31+
},
32+
"./*": {
33+
"require": "./dist/*.js",
34+
"import": "./dist/*.mjs"
35+
}
36+
},
2737
"typings": "dist/index.d.ts",
2838
"typescript": {
2939
"definition": "dist/index.d.ts"

packages/plugins/java/kotlin/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@
2222
"peerDependencies": {
2323
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2424
},
25-
"main": "dist/index.cjs.js",
26-
"module": "dist/index.esm.js",
25+
"main": "dist/index.js",
26+
"module": "dist/index.mjs",
27+
"exports": {
28+
".": {
29+
"require": "./dist/index.js",
30+
"import": "./dist/index.mjs"
31+
},
32+
"./*": {
33+
"require": "./dist/*.js",
34+
"import": "./dist/*.mjs"
35+
}
36+
},
2737
"typings": "dist/index.d.ts",
2838
"typescript": {
2939
"definition": "dist/index.d.ts"

packages/plugins/java/resolvers/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@
2222
"peerDependencies": {
2323
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2424
},
25-
"main": "dist/index.cjs.js",
26-
"module": "dist/index.esm.js",
25+
"main": "dist/index.js",
26+
"module": "dist/index.mjs",
27+
"exports": {
28+
".": {
29+
"require": "./dist/index.js",
30+
"import": "./dist/index.mjs"
31+
},
32+
"./*": {
33+
"require": "./dist/*.js",
34+
"import": "./dist/*.mjs"
35+
}
36+
},
2737
"typings": "dist/index.d.ts",
2838
"typescript": {
2939
"definition": "dist/index.d.ts"

packages/plugins/other/add/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@
1919
"peerDependencies": {
2020
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
2121
},
22-
"main": "dist/index.cjs.js",
23-
"module": "dist/index.esm.js",
22+
"main": "dist/index.js",
23+
"module": "dist/index.mjs",
24+
"exports": {
25+
".": {
26+
"require": "./dist/index.js",
27+
"import": "./dist/index.mjs"
28+
},
29+
"./*": {
30+
"require": "./dist/*.js",
31+
"import": "./dist/*.mjs"
32+
}
33+
},
2434
"typings": "dist/index.d.ts",
2535
"typescript": {
2636
"definition": "dist/index.d.ts"

0 commit comments

Comments
 (0)