@graphql-codegen/cli 2.16.4-alpha-20230107200104-a63e3c9d9 → 2.16.4-alpha-20230107200253-00a4e4db2

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
@@ -169,7 +169,7 @@ async function executeCodegen(input) {
169
169
  ? await (0, presets_js_1.getPresetByName)(outputConfig.preset, makeDefaultLoader(context.cwd))
170
170
  : outputConfig.preset
171
171
  : null;
172
- if (preset === null || preset === void 0 ? void 0 : preset.prepareDocuments) {
172
+ if (preset && preset.prepareDocuments) {
173
173
  outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
174
174
  }
175
175
  return subTask.newListr([
@@ -241,7 +241,7 @@ async function executeCodegen(input) {
241
241
  ...(typeof outputFileTemplateConfig === 'string'
242
242
  ? { value: outputFileTemplateConfig }
243
243
  : outputFileTemplateConfig),
244
- emitLegacyCommonJSImports: (0, config_js_1.shouldEmitLegacyCommonJSImports)(config),
244
+ emitLegacyCommonJSImports: (0, config_js_1.shouldEmitLegacyCommonJSImports)(config, filename),
245
245
  };
246
246
  const outputs = preset
247
247
  ? await context.profiler.run(async () => preset.buildGeneratesSection({
package/cjs/config.js CHANGED
@@ -55,9 +55,9 @@ function customLoader(ext) {
55
55
  return loader;
56
56
  }
57
57
  async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }) {
58
- configFilePath || (configFilePath = process.cwd());
59
- moduleName || (moduleName = 'codegen');
60
- packageProp || (packageProp = moduleName);
58
+ configFilePath = configFilePath || process.cwd();
59
+ moduleName = moduleName || 'codegen';
60
+ packageProp = packageProp || moduleName;
61
61
  const cosmi = (0, cosmiconfig_1.cosmiconfig)(moduleName, {
62
62
  searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces || []),
63
63
  packageProp,
@@ -345,7 +345,7 @@ function addHashToDocumentFiles(documentFilesPromise) {
345
345
  return doc;
346
346
  }));
347
347
  }
348
- function shouldEmitLegacyCommonJSImports(config) {
348
+ function shouldEmitLegacyCommonJSImports(config, outputPath) {
349
349
  const globalValue = config.emitLegacyCommonJSImports === undefined ? true : Boolean(config.emitLegacyCommonJSImports);
350
350
  // const outputConfig = config.generates[outputPath];
351
351
  // if (!outputConfig) {
@@ -56,7 +56,7 @@ function isGraphQLConfig(config) {
56
56
  catch (e) { }
57
57
  try {
58
58
  for (const projectName in config.projects) {
59
- if (Object.hasOwn(config.projects, projectName)) {
59
+ if (config.projects.hasOwnProperty(projectName)) {
60
60
  const project = config.projects[projectName];
61
61
  if (project.hasExtension('codegen')) {
62
62
  return true;
@@ -60,10 +60,14 @@ async function writePackage(answers, configLocation) {
60
60
  const pkgContent = (0, fs_1.readFileSync)(pkgPath, 'utf8');
61
61
  const pkg = JSON.parse(pkgContent);
62
62
  const { indent } = (0, detect_indent_1.default)(pkgContent);
63
- pkg.scripts || (pkg.scripts = {});
63
+ if (!pkg.scripts) {
64
+ pkg.scripts = {};
65
+ }
64
66
  pkg.scripts[answers.script] = `graphql-codegen --config ${configLocation}`;
65
67
  // plugin
66
- pkg.devDependencies || (pkg.devDependencies = {});
68
+ if (!pkg.devDependencies) {
69
+ pkg.devDependencies = {};
70
+ }
67
71
  await Promise.all((answers.plugins || []).map(async (plugin) => {
68
72
  pkg.devDependencies[plugin.package] = await (0, get_latest_version_js_1.getLatestVersion)(plugin.package);
69
73
  }));
package/cjs/presets.js CHANGED
@@ -12,10 +12,10 @@ async function getPresetByName(name, loader) {
12
12
  for (const moduleName of possibleNames) {
13
13
  try {
14
14
  const loaded = await loader(moduleName);
15
- if (loaded === null || loaded === void 0 ? void 0 : loaded.preset) {
15
+ if (loaded && loaded.preset) {
16
16
  return loaded.preset;
17
17
  }
18
- if (loaded === null || loaded === void 0 ? void 0 : loaded.default) {
18
+ if (loaded && loaded.default) {
19
19
  return loaded.default;
20
20
  }
21
21
  return loaded;
@@ -17,7 +17,7 @@ function setSilentLogger() {
17
17
  }
18
18
  exports.setSilentLogger = setSilentLogger;
19
19
  function useWinstonLogger() {
20
- if (logger === null || logger === void 0 ? void 0 : logger.levels) {
20
+ if (logger && logger.levels) {
21
21
  return;
22
22
  }
23
23
  logger = console;
@@ -68,9 +68,8 @@ const createWatcher = (initalContext, onNext) => {
68
68
  Object.keys(config.generates)
69
69
  .map(filename => ({ filename, config: (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]) }))
70
70
  .forEach(entry => {
71
- var _a;
72
71
  if (entry.config.preset) {
73
- const extension = (_a = entry.config.presetConfig) === null || _a === void 0 ? void 0 : _a.extension;
72
+ const extension = entry.config.presetConfig && entry.config.presetConfig.extension;
74
73
  if (extension) {
75
74
  ignored.push((0, path_1.join)(entry.filename, '**', '*' + extension));
76
75
  }
package/esm/codegen.js CHANGED
@@ -165,7 +165,7 @@ export async function executeCodegen(input) {
165
165
  ? await getPresetByName(outputConfig.preset, makeDefaultLoader(context.cwd))
166
166
  : outputConfig.preset
167
167
  : null;
168
- if (preset === null || preset === void 0 ? void 0 : preset.prepareDocuments) {
168
+ if (preset && preset.prepareDocuments) {
169
169
  outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
170
170
  }
171
171
  return subTask.newListr([
@@ -237,7 +237,7 @@ export async function executeCodegen(input) {
237
237
  ...(typeof outputFileTemplateConfig === 'string'
238
238
  ? { value: outputFileTemplateConfig }
239
239
  : outputFileTemplateConfig),
240
- emitLegacyCommonJSImports: shouldEmitLegacyCommonJSImports(config),
240
+ emitLegacyCommonJSImports: shouldEmitLegacyCommonJSImports(config, filename),
241
241
  };
242
242
  const outputs = preset
243
243
  ? await context.profiler.run(async () => preset.buildGeneratesSection({
package/esm/config.js CHANGED
@@ -50,9 +50,9 @@ function customLoader(ext) {
50
50
  return loader;
51
51
  }
52
52
  export async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }) {
53
- configFilePath || (configFilePath = process.cwd());
54
- moduleName || (moduleName = 'codegen');
55
- packageProp || (packageProp = moduleName);
53
+ configFilePath = configFilePath || process.cwd();
54
+ moduleName = moduleName || 'codegen';
55
+ packageProp = packageProp || moduleName;
56
56
  const cosmi = cosmiconfig(moduleName, {
57
57
  searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces || []),
58
58
  packageProp,
@@ -332,7 +332,7 @@ function addHashToDocumentFiles(documentFilesPromise) {
332
332
  return doc;
333
333
  }));
334
334
  }
335
- export function shouldEmitLegacyCommonJSImports(config) {
335
+ export function shouldEmitLegacyCommonJSImports(config, outputPath) {
336
336
  const globalValue = config.emitLegacyCommonJSImports === undefined ? true : Boolean(config.emitLegacyCommonJSImports);
337
337
  // const outputConfig = config.generates[outputPath];
338
338
  // if (!outputConfig) {
@@ -51,7 +51,7 @@ function isGraphQLConfig(config) {
51
51
  catch (e) { }
52
52
  try {
53
53
  for (const projectName in config.projects) {
54
- if (Object.hasOwn(config.projects, projectName)) {
54
+ if (config.projects.hasOwnProperty(projectName)) {
55
55
  const project = config.projects[projectName];
56
56
  if (project.hasExtension('codegen')) {
57
57
  return true;
@@ -55,10 +55,14 @@ export async function writePackage(answers, configLocation) {
55
55
  const pkgContent = readFileSync(pkgPath, 'utf8');
56
56
  const pkg = JSON.parse(pkgContent);
57
57
  const { indent } = detectIndent(pkgContent);
58
- pkg.scripts || (pkg.scripts = {});
58
+ if (!pkg.scripts) {
59
+ pkg.scripts = {};
60
+ }
59
61
  pkg.scripts[answers.script] = `graphql-codegen --config ${configLocation}`;
60
62
  // plugin
61
- pkg.devDependencies || (pkg.devDependencies = {});
63
+ if (!pkg.devDependencies) {
64
+ pkg.devDependencies = {};
65
+ }
62
66
  await Promise.all((answers.plugins || []).map(async (plugin) => {
63
67
  pkg.devDependencies[plugin.package] = await getLatestVersion(plugin.package);
64
68
  }));
package/esm/presets.js CHANGED
@@ -9,10 +9,10 @@ export async function getPresetByName(name, loader) {
9
9
  for (const moduleName of possibleNames) {
10
10
  try {
11
11
  const loaded = await loader(moduleName);
12
- if (loaded === null || loaded === void 0 ? void 0 : loaded.preset) {
12
+ if (loaded && loaded.preset) {
13
13
  return loaded.preset;
14
14
  }
15
- if (loaded === null || loaded === void 0 ? void 0 : loaded.default) {
15
+ if (loaded && loaded.default) {
16
16
  return loaded.default;
17
17
  }
18
18
  return loaded;
@@ -11,7 +11,7 @@ export function setSilentLogger() {
11
11
  logger = dummyLogger;
12
12
  }
13
13
  export function useWinstonLogger() {
14
- if (logger === null || logger === void 0 ? void 0 : logger.levels) {
14
+ if (logger && logger.levels) {
15
15
  return;
16
16
  }
17
17
  logger = console;
@@ -64,9 +64,8 @@ export const createWatcher = (initalContext, onNext) => {
64
64
  Object.keys(config.generates)
65
65
  .map(filename => ({ filename, config: normalizeOutputParam(config.generates[filename]) }))
66
66
  .forEach(entry => {
67
- var _a;
68
67
  if (entry.config.preset) {
69
- const extension = (_a = entry.config.presetConfig) === null || _a === void 0 ? void 0 : _a.extension;
68
+ const extension = entry.config.presetConfig && entry.config.presetConfig.extension;
70
69
  if (extension) {
71
70
  ignored.push(join(entry.filename, '**', '*' + extension));
72
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.16.4-alpha-20230107200104-a63e3c9d9",
3
+ "version": "2.16.4-alpha-20230107200253-00a4e4db2",
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
  "ts-node": ">=10"
@@ -136,4 +136,4 @@ export declare class CodegenContext {
136
136
  loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
137
137
  }
138
138
  export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
139
- export declare function shouldEmitLegacyCommonJSImports(config: Types.Config): boolean;
139
+ export declare function shouldEmitLegacyCommonJSImports(config: Types.Config, outputPath: string): boolean;
@@ -136,4 +136,4 @@ export declare class CodegenContext {
136
136
  loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
137
137
  }
138
138
  export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
139
- export declare function shouldEmitLegacyCommonJSImports(config: Types.Config): boolean;
139
+ export declare function shouldEmitLegacyCommonJSImports(config: Types.Config, outputPath: string): boolean;