@codacy/analysis-runner

中文文档
0.28.0发布于 2026/11/09MITTypeScriptCommonJS近 30 天下载 1.2万

Core orchestration engine for Codacy analysis

原始使用文档
文档目录9 节
  1. Table of Contents
  2. Overview
  3. Quick start
  4. Creating a config
  5. Custom logging & cancellation
  6. API
  7. Pipeline steps
  8. Output formats
  9. Execution modes

@codacy/analysis-runner

Table of Contents


Overview

Core orchestration engine for the Codacy Analysis CLI. Discovers tools, checks capabilities, calls analyze() on each adapter, aggregates results, and transforms output. Usable programmatically by both the CLI and IDE integrations.

Quick start

Tool adapters live in a companion preset package, @codacy/analysis-adapters. A consumer installs both and registers the built-in adapters once before running anything tool-related — the runner's adapter registry starts empty and nothing auto-populates it.

import { registerBuiltinAdapters } from "@codacy/analysis-adapters";
import { analyze, createNullLogger } from "@codacy/analysis-runner";

// Register all built-in tools + cloud-only descriptors (call once at startup).
registerBuiltinAdapters();

// Run analysis. `repositoryRoot` must be a git work tree.
const result = await analyze({
  repositoryRoot: "/abs/path/to/repo",
  // files: ["src/index.ts"],   // optional: scope to specific files
  logger: createNullLogger(), // or bring your own Logger (see below)
});

// Issue paths are repo-relative; line/column are 1-based.
for (const issue of result.issues) {
  console.log(
    `${issue.filePath}:${issue.line}:${issue.column}  ${issue.patternId}  ${issue.message}`,
  );
}

To register only a subset of tools, import builtinAdapterEntries from the preset and call registerLazyAdapter(descriptor, load) for the ones you want.

Creating a config

analyze() reads .codacy/codacy.config.json. Generate one programmatically with the init* family — they build a CodacyConfig from the registered adapters; writeCodacyConfig persists it:

import {
  getRegisteredAdapters,
  initLocalConfig, // local-config detection only (offline)
  // initDefaultConfig / initAutoConfig / initRemoteConfig also available
  writeCodacyConfig,
} from "@codacy/analysis-runner";

const adapters = await getRegisteredAdapters();
const { config } = await initLocalConfig(repositoryRoot, adapters);
await writeCodacyConfig(repositoryRoot, config);

initAutoConfig additionally takes the registered descriptors (getRegisteredDescriptors()) and the preset's loadUnsupportedPatterns to gate stack-specific patterns; initRemoteConfig pulls the config from Codacy Cloud (pass an API token — see credential helpers below).

Custom logging & cancellation

  • Pass your own Logger (the @codacy/tooling contract: debug / info / warn / error) to route progress into your UI, or createNullLogger() for silence. Do not use createLogger() in an embedder — it writes to files/stderr. Drive progress UI from the onToolStart / onToolComplete / onToolProgress callbacks on AnalyzeOptions.
  • Pass signal: AbortSignal on AnalyzeOptions to cancel an in-flight run; signal-honoring adapters return partial results and remaining tools are marked cancelled.

API

ExportPurpose
analyze(options)Main entry point — runs the full analysis pipeline. Options include repositoryRoot, tools, files, logger, signal, and onTool* progress callbacks
registerAdapter(adapter) / registerLazyAdapter(descriptor, load)Register a tool adapter (eager / lazy)
clearAdapters()Reset adapter registry (for tests)
getRegisteredAdapters() / getRegisteredDescriptors()List registered adapters / descriptors
initLocalConfig() / initDefaultConfig() / initAutoConfig() / initRemoteConfig()Build a CodacyConfig (local, default, stack-aware, or Cloud-sourced)
readCodacyConfig() / writeCodacyConfig()Read/write .codacy/codacy.config.json
buildToolConfig()Assemble CodacyToolConfig from CodacyConfig + local config
discover(path)Scan a repo and report languages, frameworks, libraries, notable files
formatOutput(result, format)Transform AnalysisResult into a formatted string
createLogger() / createNullLogger()File/stderr logger (CLI) / no-op logger (embedders)
saveCredentials() / loadCredentials() / deleteCredentials() / resolveApiToken()Machine-stored API-token storage in ~/.codacy/credentials
validateApiToken() / configureApiToken() / listIgnoredFiles()Codacy Cloud API helpers

Adapter registration lives in the companion preset @codacy/analysis-adapters (registerBuiltinAdapters, builtinAdapterEntries), not here — the runner stays tool-agnostic.

Pipeline steps

  1. Discover registered adapters (filtered by options.tools if set)
  2. Check availability → build CapabilityReport
  3. Apply execution mode rules (standard/strict/auto-install/inspect)
  4. Discover files via git, apply exclusion layers, route to tools
  5. Check local config + build CodacyToolConfig per tool
  6. Execute adapter.analyze() with timeout and concurrency control
  7. Aggregate results into AnalysisResult
  8. Format output

Output formats

FormatDescription
jsonPretty-printed AnalysisResult (default)
sarifSARIF v2.1.0 document
containerOne JSON object per line (Codacy Docker runners)
textHuman-readable terminal summary with colors and grouping

Execution modes

ModeBehavior
standardSkip unavailable tools, report them (default)
strictFail if any configured tool is unavailable
auto-installAttempt to install missing tools before analysis
inspectDry-run: report capability without running analysis

版本与发布记录

@codacy/analysis-runner 共发布 36 个版本,首次发布于 2026/03/24;过去 12 个月发布了 36 个版本。

版本发布日期距今
0.28.0latest2026/11/09今天
0.27.12026/11/054 天前
0.27.02026/11/036 天前
0.26.02026/10/3010 天前
0.25.02026/10/1921 天前
0.24.02026/09/251 个月前

关于 @codacy/analysis-runner 的常见问题

@codacy/analysis-runner 是什么?

Core orchestration engine for Codacy analysis

如何安装 @codacy/analysis-runner?

在项目目录运行 npm install @codacy/analysis-runner,或使用 pnpm add / yarn add / bun add。

@codacy/analysis-runner 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codacy/analysis-runner 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@codacy/analysis-runner 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codacy/analysis-runner 可以商用吗?

@codacy/analysis-runner 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codacy/analysis-runner 的下载量有多少?

根据 npm 官方下载统计,@codacy/analysis-runner 在 2026/10/10 – 2026/11/08 这 30 天内被下载 11,963 次,日均约 399 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codacy/analysis-runner 还在维护吗?

最新版本 0.28.0 发布于 2026/11/09(今天);至今共发布 36 个版本,其中过去 12 个月发布了 36 个;首次发布于 2026/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。