@graphql-codegen/cli 2.14.0 → 2.14.1-alpha-20221125150948-fd3e2f5ff

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/cjs/codegen.js CHANGED
@@ -295,10 +295,9 @@ async function executeCodegen(input) {
295
295
  },
296
296
  // It doesn't stop when one of tasks failed, to finish at least some of outputs
297
297
  exitOnError: false,
298
- concurrent: (0, os_1.cpus)().length,
299
298
  };
300
299
  });
301
- return task.newListr(generateTasks);
300
+ return task.newListr(generateTasks, { concurrent: (0, os_1.cpus)().length });
302
301
  },
303
302
  },
304
303
  ], {
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const hooks_js_1 = require("./hooks.js");
6
5
  const codegen_js_1 = require("./codegen.js");
7
6
  const watcher_js_1 = require("./utils/watcher.js");
8
7
  const file_system_js_1 = require("./utils/file-system.js");
9
- const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
10
8
  const path_1 = require("path");
11
9
  const debugging_js_1 = require("./utils/debugging.js");
12
10
  const config_js_1 = require("./config.js");
@@ -48,36 +46,38 @@ async function generate(input, saveToFile = true) {
48
46
  await (0, hooks_js_1.lifecycleHooks)(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
49
47
  }, 'Lifecycle: beforeAllFileWrite');
50
48
  await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
51
- const exists = await (0, file_system_js_1.fileExists)(result.filename);
49
+ const previousHash = recentOutputHash.get(result.filename) || (await hashFile(result.filename));
50
+ const exists = previousHash !== null;
51
+ // Store previous hash to avoid reading from disk again
52
+ if (previousHash) {
53
+ recentOutputHash.set(result.filename, previousHash);
54
+ }
52
55
  if (!shouldOverwrite(config, result.filename) && exists) {
53
56
  return;
54
57
  }
55
58
  const content = result.content || '';
56
59
  const currentHash = hash(content);
57
- let previousHash = recentOutputHash.get(result.filename);
58
- if (!previousHash && exists) {
59
- previousHash = hash(await (0, file_system_js_1.readFile)(result.filename));
60
- }
61
60
  if (previousHash && currentHash === previousHash) {
62
61
  (0, debugging_js_1.debugLog)(`Skipping file (${result.filename}) writing due to indentical hash...`);
63
62
  return;
64
63
  }
65
- else if (context.checkMode) {
64
+ // skip updating file in dry mode
65
+ if (context.checkMode) {
66
66
  context.checkModeStaleFiles.push(result.filename);
67
- return; // skip updating file in dry mode
67
+ return;
68
68
  }
69
69
  if (content.length === 0) {
70
70
  return;
71
71
  }
72
- recentOutputHash.set(result.filename, currentHash);
73
- const basedir = (0, path_1.dirname)(result.filename);
74
72
  await (0, hooks_js_1.lifecycleHooks)(result.hooks).beforeOneFileWrite(result.filename);
75
73
  await (0, hooks_js_1.lifecycleHooks)(config.hooks).beforeOneFileWrite(result.filename);
76
- await (0, mkdirp_1.default)(basedir);
77
74
  const absolutePath = (0, path_1.isAbsolute)(result.filename)
78
75
  ? result.filename
79
76
  : (0, path_1.join)(input.cwd || process.cwd(), result.filename);
80
- await (0, file_system_js_1.writeFile)(absolutePath, result.content);
77
+ const basedir = (0, path_1.dirname)(absolutePath);
78
+ await (0, file_system_js_1.mkdirp)(basedir);
79
+ await (0, file_system_js_1.writeFile)(absolutePath, content);
80
+ recentOutputHash.set(result.filename, currentHash);
81
81
  await (0, hooks_js_1.lifecycleHooks)(result.hooks).afterOneFileWrite(result.filename);
82
82
  await (0, hooks_js_1.lifecycleHooks)(config.hooks).afterOneFileWrite(result.filename);
83
83
  })), 'Write files');
@@ -112,3 +112,16 @@ function shouldOverwrite(config, outputPath) {
112
112
  function isConfiguredOutput(output) {
113
113
  return typeof output.plugins !== 'undefined';
114
114
  }
115
+ async function hashFile(filePath) {
116
+ try {
117
+ return hash(await (0, file_system_js_1.readFile)(filePath));
118
+ }
119
+ catch (err) {
120
+ if (err && err.code === 'ENOENT') {
121
+ // return null if file does not exist
122
+ return null;
123
+ }
124
+ // rethrow unexpected errors
125
+ throw err;
126
+ }
127
+ }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unlinkFile = exports.fileExists = exports.readFile = exports.writeFile = void 0;
3
+ exports.mkdirp = exports.unlinkFile = exports.readFile = exports.writeFile = void 0;
4
4
  const fs_1 = require("fs");
5
- const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = fs_1.promises;
5
+ const { writeFile: fsWriteFile, readFile: fsReadFile, mkdir } = fs_1.promises;
6
6
  function writeFile(filepath, content) {
7
7
  return fsWriteFile(filepath, content);
8
8
  }
@@ -11,16 +11,11 @@ function readFile(filepath) {
11
11
  return fsReadFile(filepath, 'utf-8');
12
12
  }
13
13
  exports.readFile = readFile;
14
- async function fileExists(filePath) {
15
- try {
16
- return (await fsStat(filePath)).isFile();
17
- }
18
- catch (err) {
19
- return false;
20
- }
21
- }
22
- exports.fileExists = fileExists;
23
14
  function unlinkFile(filePath, cb) {
24
15
  (0, fs_1.unlink)(filePath, cb);
25
16
  }
26
17
  exports.unlinkFile = unlinkFile;
18
+ function mkdirp(filePath) {
19
+ return mkdir(filePath, { recursive: true });
20
+ }
21
+ exports.mkdirp = mkdirp;
package/esm/codegen.js CHANGED
@@ -291,10 +291,9 @@ export async function executeCodegen(input) {
291
291
  },
292
292
  // It doesn't stop when one of tasks failed, to finish at least some of outputs
293
293
  exitOnError: false,
294
- concurrent: cpus().length,
295
294
  };
296
295
  });
297
- return task.newListr(generateTasks);
296
+ return task.newListr(generateTasks, { concurrent: cpus().length });
298
297
  },
299
298
  },
300
299
  ], {
@@ -1,8 +1,7 @@
1
1
  import { lifecycleHooks } from './hooks.js';
2
2
  import { executeCodegen } from './codegen.js';
3
3
  import { createWatcher } from './utils/watcher.js';
4
- import { fileExists, readFile, writeFile, unlinkFile } from './utils/file-system.js';
5
- import mkdirp from 'mkdirp';
4
+ import { readFile, writeFile, unlinkFile, mkdirp } from './utils/file-system.js';
6
5
  import { dirname, join, isAbsolute } from 'path';
7
6
  import { debugLog } from './utils/debugging.js';
8
7
  import { ensureContext } from './config.js';
@@ -44,36 +43,38 @@ export async function generate(input, saveToFile = true) {
44
43
  await lifecycleHooks(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
45
44
  }, 'Lifecycle: beforeAllFileWrite');
46
45
  await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
47
- const exists = await fileExists(result.filename);
46
+ const previousHash = recentOutputHash.get(result.filename) || (await hashFile(result.filename));
47
+ const exists = previousHash !== null;
48
+ // Store previous hash to avoid reading from disk again
49
+ if (previousHash) {
50
+ recentOutputHash.set(result.filename, previousHash);
51
+ }
48
52
  if (!shouldOverwrite(config, result.filename) && exists) {
49
53
  return;
50
54
  }
51
55
  const content = result.content || '';
52
56
  const currentHash = hash(content);
53
- let previousHash = recentOutputHash.get(result.filename);
54
- if (!previousHash && exists) {
55
- previousHash = hash(await readFile(result.filename));
56
- }
57
57
  if (previousHash && currentHash === previousHash) {
58
58
  debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
59
59
  return;
60
60
  }
61
- else if (context.checkMode) {
61
+ // skip updating file in dry mode
62
+ if (context.checkMode) {
62
63
  context.checkModeStaleFiles.push(result.filename);
63
- return; // skip updating file in dry mode
64
+ return;
64
65
  }
65
66
  if (content.length === 0) {
66
67
  return;
67
68
  }
68
- recentOutputHash.set(result.filename, currentHash);
69
- const basedir = dirname(result.filename);
70
69
  await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
71
70
  await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
72
- await mkdirp(basedir);
73
71
  const absolutePath = isAbsolute(result.filename)
74
72
  ? result.filename
75
73
  : join(input.cwd || process.cwd(), result.filename);
76
- await writeFile(absolutePath, result.content);
74
+ const basedir = dirname(absolutePath);
75
+ await mkdirp(basedir);
76
+ await writeFile(absolutePath, content);
77
+ recentOutputHash.set(result.filename, currentHash);
77
78
  await lifecycleHooks(result.hooks).afterOneFileWrite(result.filename);
78
79
  await lifecycleHooks(config.hooks).afterOneFileWrite(result.filename);
79
80
  })), 'Write files');
@@ -107,3 +108,16 @@ function shouldOverwrite(config, outputPath) {
107
108
  function isConfiguredOutput(output) {
108
109
  return typeof output.plugins !== 'undefined';
109
110
  }
111
+ async function hashFile(filePath) {
112
+ try {
113
+ return hash(await readFile(filePath));
114
+ }
115
+ catch (err) {
116
+ if (err && err.code === 'ENOENT') {
117
+ // return null if file does not exist
118
+ return null;
119
+ }
120
+ // rethrow unexpected errors
121
+ throw err;
122
+ }
123
+ }
@@ -1,19 +1,14 @@
1
1
  import { unlink as fsUnlink, promises } from 'fs';
2
- const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = promises;
2
+ const { writeFile: fsWriteFile, readFile: fsReadFile, mkdir } = promises;
3
3
  export function writeFile(filepath, content) {
4
4
  return fsWriteFile(filepath, content);
5
5
  }
6
6
  export function readFile(filepath) {
7
7
  return fsReadFile(filepath, 'utf-8');
8
8
  }
9
- export async function fileExists(filePath) {
10
- try {
11
- return (await fsStat(filePath)).isFile();
12
- }
13
- catch (err) {
14
- return false;
15
- }
16
- }
17
9
  export function unlinkFile(filePath, cb) {
18
10
  fsUnlink(filePath, cb);
19
11
  }
12
+ export function mkdirp(filePath) {
13
+ return mkdir(filePath, { recursive: true });
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.14.0",
3
+ "version": "2.14.1-alpha-20221125150948-fd3e2f5ff",
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
  },
@@ -34,7 +34,6 @@
34
34
  "json-to-pretty-yaml": "^1.2.2",
35
35
  "listr2": "^4.0.5",
36
36
  "log-symbols": "^4.0.0",
37
- "mkdirp": "^1.0.4",
38
37
  "shell-quote": "^1.7.3",
39
38
  "string-env-interpolation": "^1.0.1",
40
39
  "ts-log": "^2.2.3",
@@ -1,4 +1,4 @@
1
1
  export declare function writeFile(filepath: string, content: string): Promise<void>;
2
2
  export declare function readFile(filepath: string): Promise<string>;
3
- export declare function fileExists(filePath: string): Promise<boolean>;
4
3
  export declare function unlinkFile(filePath: string, cb?: (err?: Error) => any): void;
4
+ export declare function mkdirp(filePath: string): Promise<string>;
@@ -1,4 +1,4 @@
1
1
  export declare function writeFile(filepath: string, content: string): Promise<void>;
2
2
  export declare function readFile(filepath: string): Promise<string>;
3
- export declare function fileExists(filePath: string): Promise<boolean>;
4
3
  export declare function unlinkFile(filePath: string, cb?: (err?: Error) => any): void;
4
+ export declare function mkdirp(filePath: string): Promise<string>;