@graphql-codegen/cli 2.3.0-alpha-5ed8c1163.0 → 2.3.0-alpha-f3053e3b7.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.
package/bin.js CHANGED
@@ -547,6 +547,7 @@ async function loadDocuments(documentPointers, config) {
547
547
  return loadedFromToolkit;
548
548
  }
549
549
 
550
+ const { lstat } = fs.promises;
550
551
  function generateSearchPlaces(moduleName) {
551
552
  const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
552
553
  // gives codegen.json...
@@ -579,20 +580,21 @@ function customLoader(ext) {
579
580
  }
580
581
  return loader;
581
582
  }
582
- function loadCodegenConfig(configFilePath) {
583
- const moduleName = 'codegen';
583
+ async function loadCodegenConfig({ configFilePath = process.cwd(), moduleName = 'codegen', searchPlaces: additionalSearchPlaces = [], packageProp = moduleName, loaders: customLoaders = {}, }) {
584
584
  const cosmi = cosmiconfig.cosmiconfig(moduleName, {
585
- searchPlaces: generateSearchPlaces(moduleName),
586
- packageProp: moduleName,
585
+ searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces),
586
+ packageProp,
587
587
  loaders: {
588
588
  '.json': customLoader('json'),
589
589
  '.yaml': customLoader('yaml'),
590
590
  '.yml': customLoader('yaml'),
591
591
  '.js': customLoader('js'),
592
592
  noExt: customLoader('yaml'),
593
+ ...customLoaders,
593
594
  },
594
595
  });
595
- return configFilePath ? cosmi.load(configFilePath) : cosmi.search(process.cwd());
596
+ const pathStats = await lstat(configFilePath);
597
+ return pathStats.isDirectory ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
596
598
  }
597
599
  async function loadContext(configFilePath) {
598
600
  const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
@@ -601,7 +603,7 @@ async function loadContext(configFilePath) {
601
603
  graphqlConfig,
602
604
  });
603
605
  }
604
- const result = await loadCodegenConfig(configFilePath);
606
+ const result = await loadCodegenConfig({ configFilePath });
605
607
  if (!result) {
606
608
  if (configFilePath) {
607
609
  throw new pluginHelpers.DetailedError(`Config ${configFilePath} does not exist`, `
package/config.d.ts CHANGED
@@ -10,12 +10,36 @@ export declare type YamlCliFlags = {
10
10
  silent: boolean;
11
11
  errorsOnly: boolean;
12
12
  };
13
- export interface LoadedCodegenConfig {
13
+ export interface LoadCodegenConfigOptions {
14
+ /**
15
+ * The path to the config file or directory contains the config file.
16
+ * @default process.cwd()
17
+ */
18
+ configFilePath?: string;
19
+ /**
20
+ * The name of the config file
21
+ * @default codegen
22
+ */
23
+ moduleName?: string;
24
+ /**
25
+ * Additional search paths for the config file you want to check
26
+ */
27
+ searchPlaces?: string[];
28
+ /**
29
+ * @default codegen
30
+ */
31
+ packageProp?: string;
32
+ /**
33
+ * Overrides or extends the loaders for specific file extensions
34
+ */
35
+ loaders?: Record<string, (filepath: string, content: string) => Promise<Types.Config> | Types.Config>;
36
+ }
37
+ export interface LoadCodegenConfigResult {
14
38
  filepath: string;
15
39
  config: Types.Config;
16
40
  isEmpty?: boolean;
17
41
  }
18
- export declare function loadCodegenConfig(configFilePath?: string): Promise<LoadedCodegenConfig>;
42
+ export declare function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }: LoadCodegenConfigOptions): Promise<LoadCodegenConfigResult>;
19
43
  export declare function loadContext(configFilePath?: string): Promise<CodegenContext> | never;
20
44
  export declare function buildOptions(): {
21
45
  c: {
package/index.js CHANGED
@@ -465,6 +465,7 @@ async function loadDocuments(documentPointers, config) {
465
465
  return loadedFromToolkit;
466
466
  }
467
467
 
468
+ const { lstat } = fs.promises;
468
469
  function generateSearchPlaces(moduleName) {
469
470
  const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
470
471
  // gives codegen.json...
@@ -497,20 +498,21 @@ function customLoader(ext) {
497
498
  }
498
499
  return loader;
499
500
  }
500
- function loadCodegenConfig(configFilePath) {
501
- const moduleName = 'codegen';
501
+ async function loadCodegenConfig({ configFilePath = process.cwd(), moduleName = 'codegen', searchPlaces: additionalSearchPlaces = [], packageProp = moduleName, loaders: customLoaders = {}, }) {
502
502
  const cosmi = cosmiconfig.cosmiconfig(moduleName, {
503
- searchPlaces: generateSearchPlaces(moduleName),
504
- packageProp: moduleName,
503
+ searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces),
504
+ packageProp,
505
505
  loaders: {
506
506
  '.json': customLoader('json'),
507
507
  '.yaml': customLoader('yaml'),
508
508
  '.yml': customLoader('yaml'),
509
509
  '.js': customLoader('js'),
510
510
  noExt: customLoader('yaml'),
511
+ ...customLoaders,
511
512
  },
512
513
  });
513
- return configFilePath ? cosmi.load(configFilePath) : cosmi.search(process.cwd());
514
+ const pathStats = await lstat(configFilePath);
515
+ return pathStats.isDirectory ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
514
516
  }
515
517
  async function loadContext(configFilePath) {
516
518
  const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
@@ -519,7 +521,7 @@ async function loadContext(configFilePath) {
519
521
  graphqlConfig,
520
522
  });
521
523
  }
522
- const result = await loadCodegenConfig(configFilePath);
524
+ const result = await loadCodegenConfig({ configFilePath });
523
525
  if (!result) {
524
526
  if (configFilePath) {
525
527
  throw new pluginHelpers.DetailedError(`Config ${configFilePath} does not exist`, `
package/index.mjs CHANGED
@@ -24,7 +24,7 @@ import { JsonFileLoader } from '@graphql-tools/json-file-loader';
24
24
  import { UrlLoader } from '@graphql-tools/url-loader';
25
25
  import yaml from 'yaml';
26
26
  import { createRequire } from 'module';
27
- import fs, { readFileSync, writeFileSync, statSync, unlink } from 'fs';
27
+ import fs, { promises, readFileSync, writeFileSync, statSync, unlink } from 'fs';
28
28
  import Listr from 'listr';
29
29
  import { exec } from 'child_process';
30
30
  import isGlob from 'is-glob';
@@ -438,6 +438,7 @@ async function loadDocuments(documentPointers, config) {
438
438
  return loadedFromToolkit;
439
439
  }
440
440
 
441
+ const { lstat } = promises;
441
442
  function generateSearchPlaces(moduleName) {
442
443
  const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
443
444
  // gives codegen.json...
@@ -470,20 +471,21 @@ function customLoader(ext) {
470
471
  }
471
472
  return loader;
472
473
  }
473
- function loadCodegenConfig(configFilePath) {
474
- const moduleName = 'codegen';
474
+ async function loadCodegenConfig({ configFilePath = process.cwd(), moduleName = 'codegen', searchPlaces: additionalSearchPlaces = [], packageProp = moduleName, loaders: customLoaders = {}, }) {
475
475
  const cosmi = cosmiconfig(moduleName, {
476
- searchPlaces: generateSearchPlaces(moduleName),
477
- packageProp: moduleName,
476
+ searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces),
477
+ packageProp,
478
478
  loaders: {
479
479
  '.json': customLoader('json'),
480
480
  '.yaml': customLoader('yaml'),
481
481
  '.yml': customLoader('yaml'),
482
482
  '.js': customLoader('js'),
483
483
  noExt: customLoader('yaml'),
484
+ ...customLoaders,
484
485
  },
485
486
  });
486
- return configFilePath ? cosmi.load(configFilePath) : cosmi.search(process.cwd());
487
+ const pathStats = await lstat(configFilePath);
488
+ return pathStats.isDirectory ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
487
489
  }
488
490
  async function loadContext(configFilePath) {
489
491
  const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
@@ -492,7 +494,7 @@ async function loadContext(configFilePath) {
492
494
  graphqlConfig,
493
495
  });
494
496
  }
495
- const result = await loadCodegenConfig(configFilePath);
497
+ const result = await loadCodegenConfig({ configFilePath });
496
498
  if (!result) {
497
499
  if (configFilePath) {
498
500
  throw new DetailedError(`Config ${configFilePath} does not exist`, `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.3.0-alpha-5ed8c1163.0",
3
+ "version": "2.3.0-alpha-f3053e3b7.0",
4
4
  "peerDependencies": {
5
5
  "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"
6
6
  },