Skip to content

Commit 4ad0319

Browse files
authoredNov 4, 2020
fix(cli): resolve modules provided through the -r flags relative to the cwd (#4983)
* fix(cli): require -r flags relative to the cwd * chore: disable eslint for import
1 parent 36294d9 commit 4ad0319

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎.changeset/sweet-avocados-unite.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/cli': patch
3+
---
4+
5+
Resolve modules passed through the -r flag relative to the cwd

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { DetailedError, Types } from '@graphql-codegen/plugin-helpers';
44
import { env } from 'string-env-interpolation';
55
import yargs from 'yargs';
66
import { GraphQLConfig } from 'graphql-config';
7+
// eslint-disable-next-line
8+
import { createRequire, createRequireFromPath } from 'module';
79
import { findAndLoadGraphQLConfig } from './graphql-config';
810
import { loadSchema, loadDocuments } from './load';
911

@@ -171,7 +173,8 @@ export function parseArgv(argv = process.argv): YamlCliFlags {
171173

172174
export async function createContext(cliFlags: YamlCliFlags = parseArgv(process.argv)): Promise<CodegenContext> {
173175
if (cliFlags.require && cliFlags.require.length > 0) {
174-
await Promise.all(cliFlags.require.map(mod => import(mod)));
176+
const relativeRequire = (createRequire || createRequireFromPath)(process.cwd());
177+
await Promise.all(cliFlags.require.map(mod => import(relativeRequire.resolve(mod))));
175178
}
176179

177180
const customConfigPath = getCustomConfigPath(cliFlags);

0 commit comments

Comments
 (0)
Please sign in to comment.