@graphql-codegen/cli 3.3.0-alpha-20230330170711-35035e12d → 3.3.0-alpha-20230330211230-31e3b90c4

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.
@@ -19,9 +19,9 @@ async function generate(input, saveToFile = true) {
19
19
  const filenames = generationResult.map(o => o.filename);
20
20
  // find stale files from previous build which are not present in current build
21
21
  const staleFilenames = previouslyGeneratedFilenames.filter(f => !filenames.includes(f));
22
- staleFilenames.forEach(filename => {
22
+ for (const filename of staleFilenames) {
23
23
  if (shouldOverwrite(config, filename)) {
24
- return (0, file_system_js_1.unlinkFile)(filename, err => {
24
+ (0, file_system_js_1.unlinkFile)(filename, err => {
25
25
  const prettyFilename = filename.replace(`${input.cwd || process.cwd()}/`, '');
26
26
  if (err) {
27
27
  (0, debugging_js_1.debugLog)(`Cannot remove stale file: ${prettyFilename}\n${err}`);
@@ -31,7 +31,7 @@ async function generate(input, saveToFile = true) {
31
31
  }
32
32
  });
33
33
  }
34
- });
34
+ }
35
35
  previouslyGeneratedFilenames = filenames;
36
36
  }
37
37
  const recentOutputHash = new Map();
@@ -13,14 +13,14 @@ const get_latest_version_js_1 = require("../utils/get-latest-version.js");
13
13
  const types_js_1 = require("./types.js");
14
14
  function jsObjectToBabelObjectExpression(obj) {
15
15
  const objExp = t.objectExpression([]);
16
- Object.entries(obj).forEach(([key, val]) => {
16
+ for (const [key, val] of Object.entries(obj)) {
17
17
  if (Array.isArray(val)) {
18
18
  objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), t.arrayExpression(val.map(v => (typeof v === 'object' ? jsObjectToBabelObjectExpression(v) : t.valueToNode(v))))));
19
19
  }
20
20
  else {
21
21
  objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), typeof val === 'object' ? jsObjectToBabelObjectExpression(val) : t.valueToNode(val)));
22
22
  }
23
- });
23
+ }
24
24
  return objExp;
25
25
  }
26
26
  // Parses config and writes it to a file
package/cjs/plugins.js CHANGED
@@ -32,7 +32,7 @@ async function getPluginByName(name, pluginLoader) {
32
32
  const possibleNamesMsg = possibleNames
33
33
  .map(name => `
34
34
  - ${name}
35
- `.trimRight())
35
+ `.trimEnd())
36
36
  .join('');
37
37
  throw new Error(`
38
38
  Unable to find template plugin matching '${name}'
package/cjs/presets.js CHANGED
@@ -38,7 +38,7 @@ async function getPresetByName(name, loader) {
38
38
  const possibleNamesMsg = possibleNames
39
39
  .map(name => `
40
40
  - ${name}
41
- `.trimRight())
41
+ `.trimEnd())
42
42
  .join('');
43
43
  throw new Error(`Unable to find preset matching ${name}
44
44
 
@@ -11,9 +11,9 @@ function debugLog(message, ...meta) {
11
11
  }
12
12
  exports.debugLog = debugLog;
13
13
  function printLogs() {
14
- queue.forEach(log => {
14
+ for (const log of queue) {
15
15
  (0, logger_js_1.getLogger)().info(log.message, ...log.meta);
16
- });
16
+ }
17
17
  resetLogs();
18
18
  }
19
19
  exports.printLogs = printLogs;
@@ -28,33 +28,33 @@ const createWatcher = (initalContext, onNext) => {
28
28
  const documents = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.documents);
29
29
  const schemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.schema);
30
30
  // Add schemas and documents from "generates"
31
- Object.keys(config.generates)
32
- .map(filename => (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]))
33
- .forEach(conf => {
31
+ for (const conf of Object.keys(config.generates).map(filename => (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]))) {
34
32
  schemas.push(...(0, plugin_helpers_1.normalizeInstanceOrArray)(conf.schema));
35
33
  documents.push(...(0, plugin_helpers_1.normalizeInstanceOrArray)(conf.documents));
36
34
  files.push(...(0, plugin_helpers_1.normalizeInstanceOrArray)(conf.watchPattern));
37
- });
35
+ }
38
36
  if (documents) {
39
- documents.forEach(doc => {
37
+ for (const doc of documents) {
40
38
  if (typeof doc === 'string') {
41
39
  files.push(doc);
42
40
  }
43
41
  else {
44
42
  files.push(...Object.keys(doc));
45
43
  }
46
- });
44
+ }
47
45
  }
48
- schemas.forEach((schema) => {
46
+ for (const s of schemas) {
47
+ const schema = s;
49
48
  if ((0, is_glob_1.default)(schema) || (0, utils_1.isValidPath)(schema)) {
50
49
  files.push(schema);
51
50
  }
52
- });
51
+ }
53
52
  if (typeof config.watch !== 'boolean') {
54
53
  files.push(...(0, plugin_helpers_1.normalizeInstanceOrArray)(config.watch));
55
54
  }
56
55
  let watcherSubscription;
57
56
  const runWatcher = async () => {
57
+ var _a;
58
58
  const parcelWatcher = await Promise.resolve().then(() => tslib_1.__importStar(require('@parcel/watcher')));
59
59
  (0, debugging_js_1.debugLog)(`[Watcher] Parcel watcher loaded...`);
60
60
  let isShutdown = false;
@@ -67,10 +67,10 @@ const createWatcher = (initalContext, onNext) => {
67
67
  }, 100);
68
68
  emitWatching();
69
69
  const ignored = [];
70
- Object.keys(config.generates)
71
- .map(filename => ({ filename, config: (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]) }))
72
- .forEach(entry => {
73
- var _a;
70
+ for (const entry of Object.keys(config.generates).map(filename => ({
71
+ filename,
72
+ config: (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]),
73
+ }))) {
74
74
  if (entry.config.preset) {
75
75
  const extension = (_a = entry.config.presetConfig) === null || _a === void 0 ? void 0 : _a.extension;
76
76
  if (extension) {
@@ -80,7 +80,7 @@ const createWatcher = (initalContext, onNext) => {
80
80
  else {
81
81
  ignored.push(entry.filename);
82
82
  }
83
- });
83
+ }
84
84
  watcherSubscription = await parcelWatcher.subscribe(process.cwd(), async (_, events) => {
85
85
  // it doesn't matter what has changed, need to run whole process anyway
86
86
  await Promise.all(events.map(async ({ type: eventName, path }) => {
@@ -16,9 +16,9 @@ export async function generate(input, saveToFile = true) {
16
16
  const filenames = generationResult.map(o => o.filename);
17
17
  // find stale files from previous build which are not present in current build
18
18
  const staleFilenames = previouslyGeneratedFilenames.filter(f => !filenames.includes(f));
19
- staleFilenames.forEach(filename => {
19
+ for (const filename of staleFilenames) {
20
20
  if (shouldOverwrite(config, filename)) {
21
- return unlinkFile(filename, err => {
21
+ unlinkFile(filename, err => {
22
22
  const prettyFilename = filename.replace(`${input.cwd || process.cwd()}/`, '');
23
23
  if (err) {
24
24
  debugLog(`Cannot remove stale file: ${prettyFilename}\n${err}`);
@@ -28,7 +28,7 @@ export async function generate(input, saveToFile = true) {
28
28
  }
29
29
  });
30
30
  }
31
- });
31
+ }
32
32
  previouslyGeneratedFilenames = filenames;
33
33
  }
34
34
  const recentOutputHash = new Map();
@@ -9,14 +9,14 @@ import { getLatestVersion } from '../utils/get-latest-version.js';
9
9
  import { Tags } from './types.js';
10
10
  function jsObjectToBabelObjectExpression(obj) {
11
11
  const objExp = t.objectExpression([]);
12
- Object.entries(obj).forEach(([key, val]) => {
12
+ for (const [key, val] of Object.entries(obj)) {
13
13
  if (Array.isArray(val)) {
14
14
  objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), t.arrayExpression(val.map(v => (typeof v === 'object' ? jsObjectToBabelObjectExpression(v) : t.valueToNode(v))))));
15
15
  }
16
16
  else {
17
17
  objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), typeof val === 'object' ? jsObjectToBabelObjectExpression(val) : t.valueToNode(val)));
18
18
  }
19
- });
19
+ }
20
20
  return objExp;
21
21
  }
22
22
  // Parses config and writes it to a file
package/esm/plugins.js CHANGED
@@ -29,7 +29,7 @@ export async function getPluginByName(name, pluginLoader) {
29
29
  const possibleNamesMsg = possibleNames
30
30
  .map(name => `
31
31
  - ${name}
32
- `.trimRight())
32
+ `.trimEnd())
33
33
  .join('');
34
34
  throw new Error(`
35
35
  Unable to find template plugin matching '${name}'
package/esm/presets.js CHANGED
@@ -35,7 +35,7 @@ export async function getPresetByName(name, loader) {
35
35
  const possibleNamesMsg = possibleNames
36
36
  .map(name => `
37
37
  - ${name}
38
- `.trimRight())
38
+ `.trimEnd())
39
39
  .join('');
40
40
  throw new Error(`Unable to find preset matching ${name}
41
41
 
@@ -7,9 +7,9 @@ export function debugLog(message, ...meta) {
7
7
  });
8
8
  }
9
9
  export function printLogs() {
10
- queue.forEach(log => {
10
+ for (const log of queue) {
11
11
  getLogger().info(log.message, ...log.meta);
12
- });
12
+ }
13
13
  resetLogs();
14
14
  }
15
15
  export function resetLogs() {
@@ -24,33 +24,33 @@ export const createWatcher = (initalContext, onNext) => {
24
24
  const documents = normalizeInstanceOrArray(config.documents);
25
25
  const schemas = normalizeInstanceOrArray(config.schema);
26
26
  // Add schemas and documents from "generates"
27
- Object.keys(config.generates)
28
- .map(filename => normalizeOutputParam(config.generates[filename]))
29
- .forEach(conf => {
27
+ for (const conf of Object.keys(config.generates).map(filename => normalizeOutputParam(config.generates[filename]))) {
30
28
  schemas.push(...normalizeInstanceOrArray(conf.schema));
31
29
  documents.push(...normalizeInstanceOrArray(conf.documents));
32
30
  files.push(...normalizeInstanceOrArray(conf.watchPattern));
33
- });
31
+ }
34
32
  if (documents) {
35
- documents.forEach(doc => {
33
+ for (const doc of documents) {
36
34
  if (typeof doc === 'string') {
37
35
  files.push(doc);
38
36
  }
39
37
  else {
40
38
  files.push(...Object.keys(doc));
41
39
  }
42
- });
40
+ }
43
41
  }
44
- schemas.forEach((schema) => {
42
+ for (const s of schemas) {
43
+ const schema = s;
45
44
  if (isGlob(schema) || isValidPath(schema)) {
46
45
  files.push(schema);
47
46
  }
48
- });
47
+ }
49
48
  if (typeof config.watch !== 'boolean') {
50
49
  files.push(...normalizeInstanceOrArray(config.watch));
51
50
  }
52
51
  let watcherSubscription;
53
52
  const runWatcher = async () => {
53
+ var _a;
54
54
  const parcelWatcher = await import('@parcel/watcher');
55
55
  debugLog(`[Watcher] Parcel watcher loaded...`);
56
56
  let isShutdown = false;
@@ -63,10 +63,10 @@ export const createWatcher = (initalContext, onNext) => {
63
63
  }, 100);
64
64
  emitWatching();
65
65
  const ignored = [];
66
- Object.keys(config.generates)
67
- .map(filename => ({ filename, config: normalizeOutputParam(config.generates[filename]) }))
68
- .forEach(entry => {
69
- var _a;
66
+ for (const entry of Object.keys(config.generates).map(filename => ({
67
+ filename,
68
+ config: normalizeOutputParam(config.generates[filename]),
69
+ }))) {
70
70
  if (entry.config.preset) {
71
71
  const extension = (_a = entry.config.presetConfig) === null || _a === void 0 ? void 0 : _a.extension;
72
72
  if (extension) {
@@ -76,7 +76,7 @@ export const createWatcher = (initalContext, onNext) => {
76
76
  else {
77
77
  ignored.push(entry.filename);
78
78
  }
79
- });
79
+ }
80
80
  watcherSubscription = await parcelWatcher.subscribe(process.cwd(), async (_, events) => {
81
81
  // it doesn't matter what has changed, need to run whole process anyway
82
82
  await Promise.all(events.map(async ({ type: eventName, path }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "3.3.0-alpha-20230330170711-35035e12d",
3
+ "version": "3.3.0-alpha-20230330211230-31e3b90c4",
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
  },
@@ -9,7 +9,7 @@
9
9
  "@babel/template": "^7.18.10",
10
10
  "@babel/types": "^7.18.13",
11
11
  "@graphql-codegen/core": "^3.1.0",
12
- "@graphql-codegen/plugin-helpers": "4.2.0-alpha-20230330170711-35035e12d",
12
+ "@graphql-codegen/plugin-helpers": "4.2.0-alpha-20230330211230-31e3b90c4",
13
13
  "@graphql-tools/apollo-engine-loader": "^7.3.6",
14
14
  "@graphql-tools/code-file-loader": "^7.3.17",
15
15
  "@graphql-tools/git-loader": "^7.2.13",