Skip to content

Commit

Permalink
use "createRequire" for resolve in cli "createContext"
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Jul 30, 2021
1 parent 1bcbe75 commit 9babdae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 12 additions & 1 deletion packages/graphql-codegen-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { findAndLoadGraphQLConfig } from './graphql-config';
import { loadSchema, loadDocuments, defaultSchemaLoadOptions, defaultDocumentsLoadOptions } from './load';
import { GraphQLSchema } from 'graphql';
import yaml from 'yaml';
import { createRequire, createRequireFromPath } from 'module';

export type YamlCliFlags = {
config: string;
Expand Down Expand Up @@ -180,7 +181,17 @@ 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(mod)));
const relativeRequire = (createRequire || createRequireFromPath)(process.cwd());
await Promise.all(
cliFlags.require.map(
mod =>
import(
relativeRequire.resolve(mod, {
paths: [process.cwd()],
})
)
)
);
}

const customConfigPath = getCustomConfigPath(cliFlags);
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12517,7 +12517,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==

[email protected]:
[email protected], prettier@^2.3.1:
version "2.3.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
Expand All @@ -12527,11 +12527,6 @@ prettier@^1.19.1:
resolved "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

prettier@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.1.tgz#76903c3f8c4449bc9ac597acefa24dc5ad4cbea6"
integrity sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==

pretty-error@^2.1.1:
version "2.1.1"
resolved "https://registry.npmjs.org/pretty-error/-/pretty-error-2.1.1.tgz#5f4f87c8f91e5ae3f3ba87ab4cf5e03b1a17f1a3"
Expand Down

0 comments on commit 9babdae

Please sign in to comment.