Skip to content

Commit 9b55a92

Browse files
committed
use "createRequire" for resolve in cli "createContext"
1 parent c3587dc commit 9b55a92

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { findAndLoadGraphQLConfig } from './graphql-config';
88
import { loadSchema, loadDocuments, defaultSchemaLoadOptions, defaultDocumentsLoadOptions } from './load';
99
import { GraphQLSchema } from 'graphql';
1010
import yaml from 'yaml';
11+
import { createRequire } from 'module';
1112

1213
export type YamlCliFlags = {
1314
config: string;
@@ -180,7 +181,8 @@ export function parseArgv(argv = process.argv): YamlCliFlags {
180181

181182
export async function createContext(cliFlags: YamlCliFlags = parseArgv(process.argv)): Promise<CodegenContext> {
182183
if (cliFlags.require && cliFlags.require.length > 0) {
183-
await Promise.all(cliFlags.require.map(mod => import(mod)));
184+
const cwdRequire = createRequire(process.cwd());
185+
await Promise.all(cliFlags.require.map(mod => import(cwdRequire.resolve(mod))));
184186
}
185187

186188
const customConfigPath = getCustomConfigPath(cliFlags);

yarn.lock

+1-6
Original file line numberDiff line numberDiff line change
@@ -12655,7 +12655,7 @@ [email protected]:
1265512655
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
1265612656
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
1265712657

12658-
12658+
[email protected], prettier@^2.3.1:
1265912659
version "2.3.2"
1266012660
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
1266112661
integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
@@ -12665,11 +12665,6 @@ prettier@^1.19.1:
1266512665
resolved "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
1266612666
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
1266712667

12668-
prettier@^2.3.1:
12669-
version "2.3.1"
12670-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.1.tgz#76903c3f8c4449bc9ac597acefa24dc5ad4cbea6"
12671-
integrity sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==
12672-
1267312668
pretty-error@^2.1.1:
1267412669
version "2.1.1"
1267512670
resolved "https://registry.npmjs.org/pretty-error/-/pretty-error-2.1.1.tgz#5f4f87c8f91e5ae3f3ba87ab4cf5e03b1a17f1a3"

0 commit comments

Comments
 (0)