@codacy/analysis-runner 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +151 -41
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -225,16 +225,24 @@ function filterByTargetFiles(allFiles, targetPatterns) {
225
225
  // src/executor.ts
226
226
  async function runTool(adapter, ctx, codacyToolConfig, timeoutMs) {
227
227
  const startTime = Date.now();
228
- ctx.logger.debug("runTool started", { toolId: adapter.id, fileCount: ctx.targetFiles.length, timeoutMs });
228
+ ctx.logger.debug("runTool started", {
229
+ toolId: adapter.id,
230
+ fileCount: ctx.targetFiles.length,
231
+ timeoutMs
232
+ });
229
233
  try {
230
234
  const timeoutPromise = new Promise((_resolve, reject) => {
231
- setTimeout(() => reject(new Error(`TIMEOUT: Tool ${adapter.id} exceeded ${timeoutMs}ms`)), timeoutMs);
235
+ setTimeout(
236
+ () => reject(new Error(`TIMEOUT: Tool ${adapter.id} exceeded ${timeoutMs}ms`)),
237
+ timeoutMs
238
+ );
239
+ });
240
+ const result = await Promise.race([adapter.analyze(ctx, codacyToolConfig), timeoutPromise]);
241
+ ctx.logger.debug("runTool completed", {
242
+ toolId: adapter.id,
243
+ issueCount: result.summary.issueCount,
244
+ durationMs: result.summary.durationMs
232
245
  });
233
- const result = await Promise.race([
234
- adapter.analyze(ctx, codacyToolConfig),
235
- timeoutPromise
236
- ]);
237
- ctx.logger.debug("runTool completed", { toolId: adapter.id, issueCount: result.summary.issueCount, durationMs: result.summary.durationMs });
238
246
  return result;
239
247
  } catch (err) {
240
248
  const durationMs = Date.now() - startTime;
@@ -242,7 +250,11 @@ async function runTool(adapter, ctx, codacyToolConfig, timeoutMs) {
242
250
  if (isTimeout) {
243
251
  ctx.logger.error("Tool timed out", { toolId: adapter.id, timeoutMs, elapsedMs: durationMs });
244
252
  } else {
245
- ctx.logger.error("Tool execution failed", { toolId: adapter.id, error: err instanceof Error ? err.message : String(err), durationMs });
253
+ ctx.logger.error("Tool execution failed", {
254
+ toolId: adapter.id,
255
+ error: err instanceof Error ? err.message : String(err),
256
+ durationMs
257
+ });
246
258
  }
247
259
  const now = /* @__PURE__ */ new Date();
248
260
  return {
@@ -277,7 +289,12 @@ async function runToolsSequential(tools, timeoutMs, callbacks) {
277
289
  for (const { adapter, ctx, codacyToolConfig } of tools) {
278
290
  callbacks?.onToolStart?.(adapter.id, adapter.displayName);
279
291
  const result = await runTool(adapter, ctx, codacyToolConfig, timeoutMs);
280
- callbacks?.onToolComplete?.(adapter.id, adapter.displayName, result.summary.issueCount, result.summary.durationMs);
292
+ callbacks?.onToolComplete?.(
293
+ adapter.id,
294
+ adapter.displayName,
295
+ result.summary.issueCount,
296
+ result.summary.durationMs
297
+ );
281
298
  results.push(result);
282
299
  }
283
300
  return results;
@@ -291,7 +308,12 @@ async function runToolsParallel(tools, timeoutMs, concurrency, callbacks) {
291
308
  const { adapter, ctx, codacyToolConfig } = tools[index];
292
309
  callbacks?.onToolStart?.(adapter.id, adapter.displayName);
293
310
  results[index] = await runTool(adapter, ctx, codacyToolConfig, timeoutMs);
294
- callbacks?.onToolComplete?.(adapter.id, adapter.displayName, results[index].summary.issueCount, results[index].summary.durationMs);
311
+ callbacks?.onToolComplete?.(
312
+ adapter.id,
313
+ adapter.displayName,
314
+ results[index].summary.issueCount,
315
+ results[index].summary.durationMs
316
+ );
295
317
  }
296
318
  }
297
319
  const workers = Array.from({ length: Math.min(concurrency, tools.length) }, () => worker());
@@ -337,11 +359,19 @@ async function analyze(options) {
337
359
  const availability = await Promise.race([
338
360
  adapter.checkAvailability(ctx),
339
361
  new Promise(
340
- (_, reject) => setTimeout(() => reject(new Error(`checkAvailability timed out after ${availabilityTimeout}ms`)), availabilityTimeout)
362
+ (_, reject) => setTimeout(
363
+ () => reject(new Error(`checkAvailability timed out after ${availabilityTimeout}ms`)),
364
+ availabilityTimeout
365
+ )
341
366
  )
342
367
  ]);
343
368
  if (availability.available) {
344
- logger.debug("Tool available", { toolId: adapter.id, version: availability.version, installation: availability.installation, durationMs: Date.now() - checkStart });
369
+ logger.debug("Tool available", {
370
+ toolId: adapter.id,
371
+ version: availability.version,
372
+ installation: availability.installation,
373
+ durationMs: Date.now() - checkStart
374
+ });
345
375
  ready.push({
346
376
  toolId: adapter.id,
347
377
  displayName: adapter.displayName,
@@ -350,7 +380,11 @@ async function analyze(options) {
350
380
  runner: "local"
351
381
  });
352
382
  } else {
353
- logger.warn("Tool unavailable", { toolId: adapter.id, reason: availability.reason, durationMs: Date.now() - checkStart });
383
+ logger.warn("Tool unavailable", {
384
+ toolId: adapter.id,
385
+ reason: availability.reason,
386
+ durationMs: Date.now() - checkStart
387
+ });
354
388
  unavailable.push({
355
389
  toolId: adapter.id,
356
390
  displayName: adapter.displayName,
@@ -359,7 +393,11 @@ async function analyze(options) {
359
393
  });
360
394
  }
361
395
  } catch (err) {
362
- logger.warn("Availability check failed", { toolId: adapter.id, error: err instanceof Error ? err.message : String(err), durationMs: Date.now() - checkStart });
396
+ logger.warn("Availability check failed", {
397
+ toolId: adapter.id,
398
+ error: err instanceof Error ? err.message : String(err),
399
+ durationMs: Date.now() - checkStart
400
+ });
363
401
  unavailable.push({
364
402
  toolId: adapter.id,
365
403
  displayName: adapter.displayName,
@@ -378,7 +416,11 @@ async function analyze(options) {
378
416
  const configuredIds = new Set(codacyConfig.tools.map((t) => t.toolId));
379
417
  capability.ready = capability.ready.filter((t) => configuredIds.has(t.toolId));
380
418
  capability.unavailable = capability.unavailable.filter((t) => configuredIds.has(t.toolId));
381
- logger.debug("Filtered by config", { readyBefore, readyAfter: capability.ready.length, configuredToolCount: configuredIds.size });
419
+ logger.debug("Filtered by config", {
420
+ readyBefore,
421
+ readyAfter: capability.ready.length,
422
+ configuredToolCount: configuredIds.size
423
+ });
382
424
  } else {
383
425
  logger.debug("No codacy config found, running all available tools");
384
426
  }
@@ -407,7 +449,9 @@ async function analyze(options) {
407
449
  });
408
450
  capability.unavailable.splice(i, 1);
409
451
  } else {
410
- logger.error(`${adapter.displayName} post-install check failed: ${recheck.reason ?? "unknown"}`);
452
+ logger.error(
453
+ `${adapter.displayName} post-install check failed: ${recheck.reason ?? "unknown"}`
454
+ );
411
455
  installErrors.push({
412
456
  toolId: adapter.id,
413
457
  phase: "toolInstall",
@@ -445,7 +489,15 @@ async function analyze(options) {
445
489
  }
446
490
  }
447
491
  if (installErrors.length > 0) {
448
- return buildResult(startedAt, options.repositoryRoot, mode, capability, [], installErrors, []);
492
+ return buildResult(
493
+ startedAt,
494
+ options.repositoryRoot,
495
+ mode,
496
+ capability,
497
+ [],
498
+ installErrors,
499
+ []
500
+ );
449
501
  }
450
502
  }
451
503
  if (mode === "inspect") {
@@ -478,15 +530,23 @@ async function analyze(options) {
478
530
  }
479
531
  if (mode === "strict" && capability.unavailable.length > 0) {
480
532
  const missingTools = capability.unavailable.map((u) => u.toolId).join(", ");
481
- return buildResult(startedAt, options.repositoryRoot, mode, capability, [], [
482
- {
483
- toolId: "runner",
484
- phase: "requirementCheck",
485
- kind: "UnavailableTools",
486
- message: `Strict mode: the following tools are unavailable: ${missingTools}`,
487
- level: "error"
488
- }
489
- ], []);
533
+ return buildResult(
534
+ startedAt,
535
+ options.repositoryRoot,
536
+ mode,
537
+ capability,
538
+ [],
539
+ [
540
+ {
541
+ toolId: "runner",
542
+ phase: "requirementCheck",
543
+ kind: "UnavailableTools",
544
+ message: `Strict mode: the following tools are unavailable: ${missingTools}`,
545
+ level: "error"
546
+ }
547
+ ],
548
+ []
549
+ );
490
550
  }
491
551
  const globalExclude = codacyConfig?.exclude || [];
492
552
  let allFiles = listRepoFiles(options.repositoryRoot);
@@ -515,7 +575,11 @@ async function analyze(options) {
515
575
  const ctx = makeToolContext(baseCtx, adapter, toolFiles);
516
576
  const configCheck = await adapter.checkLocalConfigurationFile(ctx);
517
577
  const codacyToolConfig = buildToolConfig(codacyConfig, adapter, configCheck);
518
- logger.debug("Tool config resolved", { toolId: adapter.id, configSource: codacyToolConfig.useLocalConfigurationFile ? "local" : "codacy", patternCount: codacyToolConfig.patterns?.length ?? 0 });
578
+ logger.debug("Tool config resolved", {
579
+ toolId: adapter.id,
580
+ configSource: codacyToolConfig.useLocalConfigurationFile ? "local" : "codacy",
581
+ patternCount: codacyToolConfig.patterns?.length ?? 0
582
+ });
519
583
  const readyEntry = capability.ready.find((r) => r.toolId === adapter.id);
520
584
  if (readyEntry) {
521
585
  if (configCheck.found && codacyToolConfig.useLocalConfigurationFile) {
@@ -527,7 +591,11 @@ async function analyze(options) {
527
591
  }
528
592
  toolRuns.push({ adapter, ctx, codacyToolConfig });
529
593
  }
530
- logger.info("Starting tool execution", { toolCount: toolRuns.length, parallel: parallelTools > 1, parallelTools });
594
+ logger.info("Starting tool execution", {
595
+ toolCount: toolRuns.length,
596
+ parallel: parallelTools > 1,
597
+ parallelTools
598
+ });
531
599
  const callbacks = {
532
600
  onToolStart: options.onToolStart,
533
601
  onToolComplete: options.onToolComplete
@@ -541,8 +609,20 @@ async function analyze(options) {
541
609
  const allIssues = normalizeIssues(results.flatMap((r) => r.issues));
542
610
  const allErrors = results.flatMap((r) => r.errors);
543
611
  const allSummaries = results.map((r) => r.summary);
544
- logger.info("Pipeline complete", { totalIssues: allIssues.length, totalErrors: allErrors.length, durationMs: Date.now() - startedAt.getTime() });
545
- return buildResult(startedAt, options.repositoryRoot, mode, capability, allIssues, allErrors, allSummaries);
612
+ logger.info("Pipeline complete", {
613
+ totalIssues: allIssues.length,
614
+ totalErrors: allErrors.length,
615
+ durationMs: Date.now() - startedAt.getTime()
616
+ });
617
+ return buildResult(
618
+ startedAt,
619
+ options.repositoryRoot,
620
+ mode,
621
+ capability,
622
+ allIssues,
623
+ allErrors,
624
+ allSummaries
625
+ );
546
626
  }
547
627
  function makeToolContext(base, adapter, targetFiles) {
548
628
  return {
@@ -792,7 +872,14 @@ function formatTextSummary(result, isInspect) {
792
872
  ]);
793
873
  }
794
874
  for (const tool of unavailableTools) {
795
- table.push([import_ansis.default.dim.red(tool.displayName ?? tool.toolId), "-", "-", "-", "-", tool.reason]);
875
+ table.push([
876
+ import_ansis.default.dim.red(tool.displayName ?? tool.toolId),
877
+ "-",
878
+ "-",
879
+ "-",
880
+ "-",
881
+ tool.reason
882
+ ]);
796
883
  }
797
884
  lines.push(table.toString());
798
885
  } else {
@@ -4602,7 +4689,11 @@ async function initLocalConfigBase(repositoryRoot, adapters2) {
4602
4689
  }
4603
4690
  async function initLocalConfig(repositoryRoot, adapters2) {
4604
4691
  const baseConfig = await initLocalConfigBase(repositoryRoot, adapters2);
4605
- const { config, codacyYamlApplied } = await enrichWithCodacyYaml(baseConfig, repositoryRoot, adapters2);
4692
+ const { config, codacyYamlApplied } = await enrichWithCodacyYaml(
4693
+ baseConfig,
4694
+ repositoryRoot,
4695
+ adapters2
4696
+ );
4606
4697
  return { config, stats: { codacyYamlApplied } };
4607
4698
  }
4608
4699
  async function initDefaultConfig(repositoryRoot, adapters2) {
@@ -4618,7 +4709,7 @@ async function initDefaultConfig(repositoryRoot, adapters2) {
4618
4709
  for (const adapter of adapters2) {
4619
4710
  if (toolsWithLocalConfig.has(adapter.id)) continue;
4620
4711
  const apiTool = apiTools.find(
4621
- (t) => t.prefix ? t.prefix.replace(/_$/, "") === adapter.id : t.name === adapter.id
4712
+ (t) => t.prefix ? t.prefix.replace(/_$/, "") === adapter.id : t.shortName === adapter.id
4622
4713
  );
4623
4714
  if (!apiTool) continue;
4624
4715
  if (!apiTool.enabledByDefault) continue;
@@ -4641,8 +4732,16 @@ async function initDefaultConfig(repositoryRoot, adapters2) {
4641
4732
  addedTools++;
4642
4733
  }
4643
4734
  }
4644
- const baseConfig = createCodacyConfig({ source: "default", languages: base.metadata.languages, tools: updatedTools });
4645
- const { config, codacyYamlApplied } = await enrichWithCodacyYaml(baseConfig, repositoryRoot, adapters2);
4735
+ const baseConfig = createCodacyConfig({
4736
+ source: "default",
4737
+ languages: base.metadata.languages,
4738
+ tools: updatedTools
4739
+ });
4740
+ const { config, codacyYamlApplied } = await enrichWithCodacyYaml(
4741
+ baseConfig,
4742
+ repositoryRoot,
4743
+ adapters2
4744
+ );
4646
4745
  return { config, stats: { totalApiTools: apiTools.length, addedTools, codacyYamlApplied } };
4647
4746
  }
4648
4747
  async function initRemoteConfig(repositoryRoot, provider, organization, repositoryName, adapters2, apiToken, onRemoteToolsFound, onToolProcessed) {
@@ -4711,8 +4810,15 @@ async function initRemoteConfig(repositoryRoot, provider, organization, reposito
4711
4810
  repositoryId: repoInfo.repositoryId != null ? String(repoInfo.repositoryId) : void 0,
4712
4811
  repositoryName
4713
4812
  });
4714
- const { config, codacyYamlApplied } = await enrichWithCodacyYaml(baseConfig, repositoryRoot, adapters2);
4715
- return { config, stats: { totalRemoteTools: remoteTools.length, matchedAdapters, codacyYamlApplied } };
4813
+ const { config, codacyYamlApplied } = await enrichWithCodacyYaml(
4814
+ baseConfig,
4815
+ repositoryRoot,
4816
+ adapters2
4817
+ );
4818
+ return {
4819
+ config,
4820
+ stats: { totalRemoteTools: remoteTools.length, matchedAdapters, codacyYamlApplied }
4821
+ };
4716
4822
  }
4717
4823
  async function initContainerConfig(repositoryRoot, adapters2) {
4718
4824
  const codacyrcPath = import_path6.default.join(repositoryRoot, ".codacyrc");
@@ -4787,8 +4893,9 @@ function rotateLogFiles(logsDir, maxFiles) {
4787
4893
  }
4788
4894
  }
4789
4895
  }
4896
+ var fileSeq = 0;
4790
4897
  function fileTimestamp() {
4791
- return (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
4898
+ return `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${fileSeq++}`;
4792
4899
  }
4793
4900
  function enrichMessage(message, fields) {
4794
4901
  if (!fields) return message;
@@ -4799,10 +4906,13 @@ function enrichMessage(message, fields) {
4799
4906
  if (fields.configSource) parts.push(String(fields.configSource));
4800
4907
  if (typeof fields.fileCount === "number") parts.push(`${fields.fileCount} files`);
4801
4908
  if (typeof fields.issueCount === "number") parts.push(`${fields.issueCount} issues`);
4802
- if (typeof fields.errorCount === "number" && fields.errorCount > 0) parts.push(`${fields.errorCount} errors`);
4909
+ if (typeof fields.errorCount === "number" && fields.errorCount > 0)
4910
+ parts.push(`${fields.errorCount} errors`);
4803
4911
  if (typeof fields.totalIssues === "number") parts.push(`${fields.totalIssues} issues`);
4804
- if (typeof fields.totalErrors === "number" && fields.totalErrors > 0) parts.push(`${fields.totalErrors} errors`);
4805
- if (typeof fields.durationMs === "number") parts.push(`${(fields.durationMs / 1e3).toFixed(1)}s`);
4912
+ if (typeof fields.totalErrors === "number" && fields.totalErrors > 0)
4913
+ parts.push(`${fields.totalErrors} errors`);
4914
+ if (typeof fields.durationMs === "number")
4915
+ parts.push(`${(fields.durationMs / 1e3).toFixed(1)}s`);
4806
4916
  if (fields.reason) parts.push(String(fields.reason));
4807
4917
  if (fields.error) parts.push(String(fields.error));
4808
4918
  if (typeof fields.found === "boolean") parts.push(fields.found ? "found" : "not found");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/analysis-runner",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Core orchestration engine for Codacy analysis",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,11 +12,11 @@
12
12
  "cli-table3": "^0.6",
13
13
  "minimatch": "10.2.4",
14
14
  "yaml": "^2.6.0",
15
- "@codacy/tooling": "0.1.0"
15
+ "@codacy/tooling": "0.1.1"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@codacy/openapi-typescript-codegen": "0.0.9",
19
- "@codacy/tools-dummy-1": "0.1.0"
19
+ "@codacy/tools-dummy-1": "0.1.1"
20
20
  },
21
21
  "license": "MIT",
22
22
  "author": "Codacy <support@codacy.com> (https://www.codacy.com)",