@graphql-codegen/cli 2.6.0-alpha-c9d165f6a.0 → 2.6.0-alpha-dfbea14f8.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
@@ -57,7 +57,7 @@ const os = require('os');
57
57
  const Listr = _interopDefault(require('listr'));
58
58
  const isGlob = _interopDefault(require('is-glob'));
59
59
  const debounce = _interopDefault(require('debounce'));
60
- const fsExtra = require('fs-extra');
60
+ const mkdirp = _interopDefault(require('mkdirp'));
61
61
  const crypto = require('crypto');
62
62
  const inquirer = _interopDefault(require('inquirer'));
63
63
  const detectIndent = _interopDefault(require('detect-indent'));
@@ -730,32 +730,6 @@ function updateContextWithCliFlags(context, cliFlags) {
730
730
  class CodegenContext {
731
731
  constructor({ config, graphqlConfig, filepath, }) {
732
732
  this._pluginContext = {};
733
- this.loadSchema = useCache((pointer) => {
734
- const config = this.getConfig(defaultSchemaLoadOptions);
735
- if (this._graphqlConfig) {
736
- // TODO: SchemaWithLoader won't work here
737
- return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
738
- }
739
- return loadSchema(pointer, config);
740
- }, {
741
- cacheKey(pointer) {
742
- return JSON.stringify(pointer);
743
- },
744
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
745
- });
746
- this.loadDocuments = useCache((pointer) => {
747
- const config = this.getConfig(defaultDocumentsLoadOptions);
748
- if (this._graphqlConfig) {
749
- // TODO: pointer won't work here
750
- return this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
751
- }
752
- return loadDocuments(pointer, config);
753
- }, {
754
- cacheKey(pointer) {
755
- return JSON.stringify(pointer);
756
- },
757
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
758
- });
759
733
  this._config = config;
760
734
  this._graphqlConfig = graphqlConfig;
761
735
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -801,28 +775,27 @@ class CodegenContext {
801
775
  getPluginContext() {
802
776
  return this._pluginContext;
803
777
  }
778
+ async loadSchema(pointer) {
779
+ const config = this.getConfig(defaultSchemaLoadOptions);
780
+ if (this._graphqlConfig) {
781
+ // TODO: SchemaWithLoader won't work here
782
+ return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
783
+ }
784
+ return loadSchema(pointer, config);
785
+ }
786
+ async loadDocuments(pointer) {
787
+ const config = this.getConfig(defaultDocumentsLoadOptions);
788
+ if (this._graphqlConfig) {
789
+ // TODO: pointer won't work here
790
+ const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
791
+ return documents;
792
+ }
793
+ return loadDocuments(pointer, config);
794
+ }
804
795
  }
805
796
  function ensureContext(input) {
806
797
  return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
807
798
  }
808
- /**
809
- * The goal here is to avoid loading the same schema or documents across projects.
810
- */
811
- function useCache(originalFunction, { cacheKey, skip = () => false }) {
812
- if (skip()) {
813
- return originalFunction;
814
- }
815
- const cache = new Map();
816
- return (input) => {
817
- const key = cacheKey(input);
818
- if (cache.has(key)) {
819
- return cache.get(key);
820
- }
821
- const result = originalFunction(input);
822
- cache.set(key, result);
823
- return result;
824
- };
825
- }
826
799
 
827
800
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
828
801
  const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
@@ -1283,22 +1256,23 @@ const createWatcher = (initalContext, onNext) => {
1283
1256
  });
1284
1257
  };
1285
1258
 
1259
+ const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = fs.promises;
1286
1260
  function writeFile(filepath, content) {
1287
- return fsExtra.writeFile(filepath, content);
1261
+ return fsWriteFile(filepath, content);
1288
1262
  }
1289
1263
  function readFile(filepath) {
1290
- return fsExtra.readFile(filepath, 'utf-8');
1264
+ return fsReadFile(filepath, 'utf-8');
1291
1265
  }
1292
1266
  async function fileExists(filePath) {
1293
1267
  try {
1294
- return (await fsExtra.stat(filePath)).isFile();
1268
+ return (await fsStat(filePath)).isFile();
1295
1269
  }
1296
1270
  catch (err) {
1297
1271
  return false;
1298
1272
  }
1299
1273
  }
1300
1274
  function unlinkFile(filePath, cb) {
1301
- fsExtra.unlink(filePath, cb);
1275
+ fs.unlink(filePath, cb);
1302
1276
  }
1303
1277
 
1304
1278
  const hash = (content) => crypto.createHash('sha1').update(content).digest('base64');
@@ -1358,7 +1332,7 @@ async function generate(input, saveToFile = true) {
1358
1332
  const basedir = path.dirname(result.filename);
1359
1333
  await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
1360
1334
  await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
1361
- await fsExtra.mkdirp(basedir);
1335
+ await mkdirp(basedir);
1362
1336
  const absolutePath = path.isAbsolute(result.filename)
1363
1337
  ? result.filename
1364
1338
  : path.join(input.cwd || process.cwd(), result.filename);
@@ -1389,7 +1363,7 @@ async function generate(input, saveToFile = true) {
1389
1363
  const basedir = path.dirname(result.filename);
1390
1364
  await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
1391
1365
  await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
1392
- fsExtra.mkdirp.sync(basedir);
1366
+ mkdirp.sync(basedir);
1393
1367
  const absolutePath = path.isAbsolute(result.filename)
1394
1368
  ? result.filename
1395
1369
  : path.join(input.cwd || process.cwd(), result.filename);
package/config.d.ts CHANGED
@@ -110,7 +110,7 @@ export declare class CodegenContext {
110
110
  getPluginContext(): {
111
111
  [key: string]: any;
112
112
  };
113
- loadSchema: (input: Types.Schema) => Promise<GraphQLSchema>;
114
- loadDocuments: (input: Types.OperationDocument[]) => Promise<import("graphql-config").Source[]>;
113
+ loadSchema(pointer: Types.Schema): Promise<GraphQLSchema>;
114
+ loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
115
115
  }
116
116
  export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
package/index.js CHANGED
@@ -58,7 +58,7 @@ const Listr = _interopDefault(require('listr'));
58
58
  const child_process = require('child_process');
59
59
  const isGlob = _interopDefault(require('is-glob'));
60
60
  const debounce = _interopDefault(require('debounce'));
61
- const fsExtra = require('fs-extra');
61
+ const mkdirp = _interopDefault(require('mkdirp'));
62
62
  const crypto = require('crypto');
63
63
  const inquirer = _interopDefault(require('inquirer'));
64
64
  const detectIndent = _interopDefault(require('detect-indent'));
@@ -648,32 +648,6 @@ function updateContextWithCliFlags(context, cliFlags) {
648
648
  class CodegenContext {
649
649
  constructor({ config, graphqlConfig, filepath, }) {
650
650
  this._pluginContext = {};
651
- this.loadSchema = useCache((pointer) => {
652
- const config = this.getConfig(defaultSchemaLoadOptions);
653
- if (this._graphqlConfig) {
654
- // TODO: SchemaWithLoader won't work here
655
- return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
656
- }
657
- return loadSchema(pointer, config);
658
- }, {
659
- cacheKey(pointer) {
660
- return JSON.stringify(pointer);
661
- },
662
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
663
- });
664
- this.loadDocuments = useCache((pointer) => {
665
- const config = this.getConfig(defaultDocumentsLoadOptions);
666
- if (this._graphqlConfig) {
667
- // TODO: pointer won't work here
668
- return this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
669
- }
670
- return loadDocuments(pointer, config);
671
- }, {
672
- cacheKey(pointer) {
673
- return JSON.stringify(pointer);
674
- },
675
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
676
- });
677
651
  this._config = config;
678
652
  this._graphqlConfig = graphqlConfig;
679
653
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -719,28 +693,27 @@ class CodegenContext {
719
693
  getPluginContext() {
720
694
  return this._pluginContext;
721
695
  }
696
+ async loadSchema(pointer) {
697
+ const config = this.getConfig(defaultSchemaLoadOptions);
698
+ if (this._graphqlConfig) {
699
+ // TODO: SchemaWithLoader won't work here
700
+ return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
701
+ }
702
+ return loadSchema(pointer, config);
703
+ }
704
+ async loadDocuments(pointer) {
705
+ const config = this.getConfig(defaultDocumentsLoadOptions);
706
+ if (this._graphqlConfig) {
707
+ // TODO: pointer won't work here
708
+ const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
709
+ return documents;
710
+ }
711
+ return loadDocuments(pointer, config);
712
+ }
722
713
  }
723
714
  function ensureContext(input) {
724
715
  return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
725
716
  }
726
- /**
727
- * The goal here is to avoid loading the same schema or documents across projects.
728
- */
729
- function useCache(originalFunction, { cacheKey, skip = () => false }) {
730
- if (skip()) {
731
- return originalFunction;
732
- }
733
- const cache = new Map();
734
- return (input) => {
735
- const key = cacheKey(input);
736
- if (cache.has(key)) {
737
- return cache.get(key);
738
- }
739
- const result = originalFunction(input);
740
- cache.set(key, result);
741
- return result;
742
- };
743
- }
744
717
 
745
718
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
746
719
  const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
@@ -1284,22 +1257,23 @@ const createWatcher = (initalContext, onNext) => {
1284
1257
  });
1285
1258
  };
1286
1259
 
1260
+ const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = fs.promises;
1287
1261
  function writeFile(filepath, content) {
1288
- return fsExtra.writeFile(filepath, content);
1262
+ return fsWriteFile(filepath, content);
1289
1263
  }
1290
1264
  function readFile(filepath) {
1291
- return fsExtra.readFile(filepath, 'utf-8');
1265
+ return fsReadFile(filepath, 'utf-8');
1292
1266
  }
1293
1267
  async function fileExists(filePath) {
1294
1268
  try {
1295
- return (await fsExtra.stat(filePath)).isFile();
1269
+ return (await fsStat(filePath)).isFile();
1296
1270
  }
1297
1271
  catch (err) {
1298
1272
  return false;
1299
1273
  }
1300
1274
  }
1301
1275
  function unlinkFile(filePath, cb) {
1302
- fsExtra.unlink(filePath, cb);
1276
+ fs.unlink(filePath, cb);
1303
1277
  }
1304
1278
 
1305
1279
  const hash = (content) => crypto.createHash('sha1').update(content).digest('base64');
@@ -1359,7 +1333,7 @@ async function generate(input, saveToFile = true) {
1359
1333
  const basedir = path.dirname(result.filename);
1360
1334
  await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
1361
1335
  await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
1362
- await fsExtra.mkdirp(basedir);
1336
+ await mkdirp(basedir);
1363
1337
  const absolutePath = path.isAbsolute(result.filename)
1364
1338
  ? result.filename
1365
1339
  : path.join(input.cwd || process.cwd(), result.filename);
@@ -1390,7 +1364,7 @@ async function generate(input, saveToFile = true) {
1390
1364
  const basedir = path.dirname(result.filename);
1391
1365
  await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
1392
1366
  await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
1393
- fsExtra.mkdirp.sync(basedir);
1367
+ mkdirp.sync(basedir);
1394
1368
  const absolutePath = path.isAbsolute(result.filename)
1395
1369
  ? result.filename
1396
1370
  : path.join(input.cwd || process.cwd(), result.filename);
package/index.mjs CHANGED
@@ -25,13 +25,13 @@ import { JsonFileLoader } from '@graphql-tools/json-file-loader';
25
25
  import { UrlLoader } from '@graphql-tools/url-loader';
26
26
  import yaml from 'yaml';
27
27
  import { createRequire } from 'module';
28
- import fs, { promises, writeFileSync, readFileSync } from 'fs';
28
+ import fs, { promises, unlink, writeFileSync, readFileSync } from 'fs';
29
29
  import { cpus } from 'os';
30
30
  import Listr from 'listr';
31
31
  import { exec } from 'child_process';
32
32
  import isGlob from 'is-glob';
33
33
  import debounce from 'debounce';
34
- import { writeFile as writeFile$1, readFile as readFile$1, stat, unlink, mkdirp } from 'fs-extra';
34
+ import mkdirp from 'mkdirp';
35
35
  import { createHash } from 'crypto';
36
36
  import inquirer from 'inquirer';
37
37
  import detectIndent from 'detect-indent';
@@ -621,32 +621,6 @@ function updateContextWithCliFlags(context, cliFlags) {
621
621
  class CodegenContext {
622
622
  constructor({ config, graphqlConfig, filepath, }) {
623
623
  this._pluginContext = {};
624
- this.loadSchema = useCache((pointer) => {
625
- const config = this.getConfig(defaultSchemaLoadOptions);
626
- if (this._graphqlConfig) {
627
- // TODO: SchemaWithLoader won't work here
628
- return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
629
- }
630
- return loadSchema(pointer, config);
631
- }, {
632
- cacheKey(pointer) {
633
- return JSON.stringify(pointer);
634
- },
635
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
636
- });
637
- this.loadDocuments = useCache((pointer) => {
638
- const config = this.getConfig(defaultDocumentsLoadOptions);
639
- if (this._graphqlConfig) {
640
- // TODO: pointer won't work here
641
- return this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
642
- }
643
- return loadDocuments(pointer, config);
644
- }, {
645
- cacheKey(pointer) {
646
- return JSON.stringify(pointer);
647
- },
648
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
649
- });
650
624
  this._config = config;
651
625
  this._graphqlConfig = graphqlConfig;
652
626
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -692,28 +666,27 @@ class CodegenContext {
692
666
  getPluginContext() {
693
667
  return this._pluginContext;
694
668
  }
669
+ async loadSchema(pointer) {
670
+ const config = this.getConfig(defaultSchemaLoadOptions);
671
+ if (this._graphqlConfig) {
672
+ // TODO: SchemaWithLoader won't work here
673
+ return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
674
+ }
675
+ return loadSchema(pointer, config);
676
+ }
677
+ async loadDocuments(pointer) {
678
+ const config = this.getConfig(defaultDocumentsLoadOptions);
679
+ if (this._graphqlConfig) {
680
+ // TODO: pointer won't work here
681
+ const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
682
+ return documents;
683
+ }
684
+ return loadDocuments(pointer, config);
685
+ }
695
686
  }
696
687
  function ensureContext(input) {
697
688
  return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
698
689
  }
699
- /**
700
- * The goal here is to avoid loading the same schema or documents across projects.
701
- */
702
- function useCache(originalFunction, { cacheKey, skip = () => false }) {
703
- if (skip()) {
704
- return originalFunction;
705
- }
706
- const cache = new Map();
707
- return (input) => {
708
- const key = cacheKey(input);
709
- if (cache.has(key)) {
710
- return cache.get(key);
711
- }
712
- const result = originalFunction(input);
713
- cache.set(key, result);
714
- return result;
715
- };
716
- }
717
690
 
718
691
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
719
692
  const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
@@ -1257,15 +1230,16 @@ const createWatcher = (initalContext, onNext) => {
1257
1230
  });
1258
1231
  };
1259
1232
 
1233
+ const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = promises;
1260
1234
  function writeFile(filepath, content) {
1261
- return writeFile$1(filepath, content);
1235
+ return fsWriteFile(filepath, content);
1262
1236
  }
1263
1237
  function readFile(filepath) {
1264
- return readFile$1(filepath, 'utf-8');
1238
+ return fsReadFile(filepath, 'utf-8');
1265
1239
  }
1266
1240
  async function fileExists(filePath) {
1267
1241
  try {
1268
- return (await stat(filePath)).isFile();
1242
+ return (await fsStat(filePath)).isFile();
1269
1243
  }
1270
1244
  catch (err) {
1271
1245
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.6.0-alpha-c9d165f6a.0",
3
+ "version": "2.6.0-alpha-dfbea14f8.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 || ^16.0.0"
6
6
  },
@@ -26,7 +26,6 @@
26
26
  "debounce": "^1.2.0",
27
27
  "dependency-graph": "^0.11.0",
28
28
  "detect-indent": "^6.0.0",
29
- "fs-extra": "^9.1.0",
30
29
  "glob": "^7.1.6",
31
30
  "globby": "^11.0.4",
32
31
  "graphql-config": "^4.1.0",
@@ -38,6 +37,7 @@
38
37
  "listr-update-renderer": "^0.5.0",
39
38
  "log-symbols": "^4.0.0",
40
39
  "minimatch": "^3.0.4",
40
+ "mkdirp": "^1.0.4",
41
41
  "string-env-interpolation": "^1.0.1",
42
42
  "ts-log": "^2.2.3",
43
43
  "tslib": "~2.3.0",
@@ -1,4 +1,4 @@
1
- export declare function writeFile(filepath: string, content: string): any;
2
- export declare function readFile(filepath: string): any;
1
+ export declare function writeFile(filepath: string, content: string): Promise<void>;
2
+ export declare function readFile(filepath: string): Promise<string>;
3
3
  export declare function fileExists(filePath: string): Promise<boolean>;
4
4
  export declare function unlinkFile(filePath: string, cb?: (err?: Error) => any): void;