Skip to content

Commit

Permalink
ESM support
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Jun 9, 2021
1 parent 1b9ceb7 commit 4cec3ae
Show file tree
Hide file tree
Showing 57 changed files with 661 additions and 119 deletions.
52 changes: 52 additions & 0 deletions .changeset/sharp-nails-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
'@graphql-cli/codegen': major
'@graphql-codegen/cli': major
'@graphql-codegen/core': major
'@graphql-codegen/c-sharp': major
'@graphql-codegen/c-sharp-operations': major
'@graphql-codegen/flow': major
'@graphql-codegen/flow-operations': major
'@graphql-codegen/flow-resolvers': major
'@graphql-codegen/java-apollo-android': major
'@graphql-codegen/java-common': major
'@graphql-codegen/java': major
'@graphql-codegen/kotlin': major
'@graphql-codegen/java-resolvers': major
'@graphql-codegen/add': major
'@graphql-codegen/fragment-matcher': major
'@graphql-codegen/introspection': major
'@graphql-codegen/jsdoc': major
'@graphql-codegen/schema-ast': major
'@graphql-codegen/time': major
'@graphql-codegen/urql-introspection': major
'@graphql-codegen/visitor-plugin-common': major
'@graphql-codegen/typescript-apollo-angular': major
'@graphql-codegen/typescript-apollo-client-helpers': major
'@graphql-codegen/typescript-compatibility': major
'@graphql-codegen/typescript-document-nodes': major
'@graphql-codegen/typescript-generic-sdk': major
'@graphql-codegen/typescript-graphql-files-modules': major
'@graphql-codegen/typescript-graphql-request': major
'@graphql-codegen/typescript-mongodb': major
'@graphql-codegen/named-operations-object': major
'@graphql-codegen/typescript-oclif': major
'@graphql-codegen/typescript-operations': major
'@graphql-codegen/typescript-react-apollo': major
'@graphql-codegen/typescript-react-offix': major
'@graphql-codegen/typescript-react-query': major
'@graphql-codegen/typescript-resolvers': major
'@graphql-codegen/typescript-stencil-apollo': major
'@graphql-codegen/typescript-type-graphql': major
'@graphql-codegen/typed-document-node': major
'@graphql-codegen/typescript': major
'@graphql-codegen/typescript-urql': major
'@graphql-codegen/typescript-urql-graphcache': major
'@graphql-codegen/typescript-vue-apollo': major
'@graphql-codegen/graphql-modules-preset': major
'@graphql-codegen/import-types-preset': major
'@graphql-codegen/near-operation-file-preset': major
'@graphql-codegen/testing': major
'@graphql-codegen/plugin-helpers': major
---

ESM support
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"apollo-server": "2.25.0",
"auto-bind": "4.0.0",
"babel-jest": "27.0.2",
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"eslint": "7.28.0",
"eslint-config-prettier": "8.3.0",
"eslint-config-standard": "16.0.3",
Expand Down
14 changes: 12 additions & 2 deletions packages/graphql-cli-codegen-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@
"@graphql-codegen/cli": "1.21.5",
"@graphql-cli/common": "4.1.0"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/graphql-codegen-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql-codegen-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { createContext } from './config';
import { lifecycleHooks } from './hooks';
import { DetailedError } from '@graphql-codegen/plugin-helpers';

export function runCli(cmd: string): Promise<any> {
ensureGraphQlPackage();
export async function runCli(cmd: string): Promise<any> {
await ensureGraphQlPackage();

switch (cmd) {
case 'init':
Expand All @@ -22,9 +22,9 @@ export function runCli(cmd: string): Promise<any> {
}
}

export function ensureGraphQlPackage() {
export async function ensureGraphQlPackage() {
try {
require('graphql');
await import('graphql');
} catch (e) {
throw new DetailedError(
`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency!`,
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function parseArgv(argv = process.argv): YamlCliFlags {

export async function createContext(cliFlags: YamlCliFlags = parseArgv(process.argv)): Promise<CodegenContext> {
if (cliFlags.require && cliFlags.require.length > 0) {
await Promise.all(cliFlags.require.map(mod => import(require.resolve(mod, { paths: [process.cwd()] }))));
await Promise.all(cliFlags.require.map(mod => import(mod)));
}

const customConfigPath = getCustomConfigPath(cliFlags);
Expand Down
3 changes: 1 addition & 2 deletions packages/graphql-codegen-cli/src/utils/listr-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { ListrTask } from 'listr';
import { DetailedError, isDetailedError } from '@graphql-codegen/plugin-helpers';
import { Source } from 'graphql';
import { debugLog, printLogs } from './debugging';

const UpdateRenderer = require('listr-update-renderer');
import UpdateRenderer from 'listr-update-renderer';

export class Renderer {
private updateRenderer: any;
Expand Down
5 changes: 4 additions & 1 deletion packages/graphql-codegen-cli/src/utils/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ export const createWatcher = (
lifecycleHooks(config.hooks).onWatchTriggered(eventName, path);
debugLog(`[Watcher] triggered due to a file ${eventName} event: ${path}`);
const fullPath = join(process.cwd(), path);
delete require.cache[fullPath];
// In ESM require is not defined
try {
delete require.cache[fullPath];
} catch (err) {}

if (eventName === 'change' && config.configFilePath && fullPath === config.configFilePath) {
log(`${logSymbols.info} Config file has changed, reloading...`);
Expand Down
14 changes: 12 additions & 2 deletions packages/graphql-codegen-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,18 @@
"@graphql-tools/utils": "^7.9.1",
"tslib": "~2.2.0"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/c-sharp/c-sharp-operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@
"tslib": "~2.2.0"
},
"sideEffects": false,
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/c-sharp/c-sharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@
"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"
},
"sideEffects": false,
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/flow/flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/flow/operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/flow/resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/java/apollo-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@
"devDependencies": {
"@types/pluralize": "0.0.29"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/java/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/java/common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Kind, TypeNode } from 'graphql';
import minIndent from 'min-indent';

import unixify from 'unixify';

export function buildPackageNameFromPath(path: string): string {
const unixify = require('unixify');
return unixify(path || '')
.replace(/src\/main\/.*?\//, '')
.replace(/\//g, '.');
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/java/java/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/java/kotlin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
14 changes: 12 additions & 2 deletions packages/plugins/java/resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@
"peerDependencies": {
"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"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand Down
Loading

0 comments on commit 4cec3ae

Please sign in to comment.