@graphql-codegen/cli 2.7.0-alpha-d6c7238c0.0 → 2.7.0-alpha-6aa2d3c43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/bin.js +17 -16
  2. package/bin.mjs +1869 -0
  3. package/index.js +17 -16
  4. package/index.mjs +17 -16
  5. package/package.json +9 -8
package/bin.js CHANGED
@@ -109,7 +109,7 @@ const DEFAULT_HOOKS = {
109
109
  function normalizeHooks(_hooks) {
110
110
  const keys = Object.keys({
111
111
  ...DEFAULT_HOOKS,
112
- ...(_hooks || {}),
112
+ ..._hooks,
113
113
  });
114
114
  return keys.reduce((prev, hookName) => {
115
115
  if (typeof _hooks[hookName] === 'string') {
@@ -118,21 +118,19 @@ function normalizeHooks(_hooks) {
118
118
  [hookName]: [_hooks[hookName]],
119
119
  };
120
120
  }
121
- else if (typeof _hooks[hookName] === 'function') {
121
+ if (typeof _hooks[hookName] === 'function') {
122
122
  return {
123
123
  ...prev,
124
124
  [hookName]: [_hooks[hookName]],
125
125
  };
126
126
  }
127
- else if (Array.isArray(_hooks[hookName])) {
127
+ if (Array.isArray(_hooks[hookName])) {
128
128
  return {
129
129
  ...prev,
130
130
  [hookName]: _hooks[hookName],
131
131
  };
132
132
  }
133
- else {
134
- return prev;
135
- }
133
+ return prev;
136
134
  }, {});
137
135
  }
138
136
  function execShellCommand(cmd) {
@@ -376,14 +374,19 @@ async function getPluginByName(name, pluginLoader) {
376
374
  }
377
375
 
378
376
  async function getPresetByName(name, loader) {
379
- const possibleNames = [`@graphql-codegen/${name}`, `@graphql-codegen/${name}-preset`, name];
377
+ const possibleNames = [
378
+ `@graphql-codegen/${name}`,
379
+ `@graphql-codegen/${name}-preset`,
380
+ name,
381
+ path.resolve(process.cwd(), name),
382
+ ];
380
383
  for (const moduleName of possibleNames) {
381
384
  try {
382
385
  const loaded = await loader(moduleName);
383
386
  if (loaded && loaded.preset) {
384
387
  return loaded.preset;
385
388
  }
386
- else if (loaded && loaded.default) {
389
+ if (loaded && loaded.default) {
387
390
  return loaded.default;
388
391
  }
389
392
  return loaded;
@@ -689,7 +692,7 @@ function buildOptions() {
689
692
  };
690
693
  }
691
694
  function parseArgv(argv = process.argv) {
692
- return yargs.options(buildOptions()).parse(argv);
695
+ return yargs(argv).options(buildOptions()).parse();
693
696
  }
694
697
  async function createContext(cliFlags = parseArgv(process.argv)) {
695
698
  if (cliFlags.require && cliFlags.require.length > 0) {
@@ -1034,8 +1037,8 @@ async function executeCodegen(input) {
1034
1037
  const outputSchemaAst = await context.loadSchema(schemaPointerMap);
1035
1038
  const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
1036
1039
  return {
1037
- outputSchemaAst: outputSchemaAst,
1038
- outputSchema: outputSchema,
1040
+ outputSchemaAst,
1041
+ outputSchema,
1039
1042
  };
1040
1043
  });
1041
1044
  outputSchemaAst = await result.outputSchemaAst;
@@ -1052,7 +1055,7 @@ async function executeCodegen(input) {
1052
1055
  return cache('documents', hash, async () => {
1053
1056
  const documents = await context.loadDocuments(docs);
1054
1057
  return {
1055
- documents: documents,
1058
+ documents,
1056
1059
  };
1057
1060
  });
1058
1061
  }));
@@ -1757,12 +1760,10 @@ function getOutputDefaultValue(answers) {
1757
1760
  if (answers.plugins.some(plugin => plugin.defaultExtension === '.tsx')) {
1758
1761
  return 'src/generated/graphql.tsx';
1759
1762
  }
1760
- else if (answers.plugins.some(plugin => plugin.defaultExtension === '.ts')) {
1763
+ if (answers.plugins.some(plugin => plugin.defaultExtension === '.ts')) {
1761
1764
  return 'src/generated/graphql.ts';
1762
1765
  }
1763
- else {
1764
- return 'src/generated/graphql.js';
1765
- }
1766
+ return 'src/generated/graphql.js';
1766
1767
  }
1767
1768
 
1768
1769
  async function guessTargets() {