Skip to content

CLI

The CLI package is @optiprune/cli. It is the supported command-line entry point for running the @optiprune/core analyzer. Install the CLI in the project you want to inspect:

Terminal window
npm install --save-dev @optiprune/cli

Run the command from the project root:

Terminal window
npx @optiprune/cli analyze

analyze is the default command, so this is equivalent:

Terminal window
npx @optiprune/cli

Use explicit entry points when a project does not use conventional entries:

Terminal window
npx @optiprune/cli analyze \
--entry src/index.ts \
--entry src/worker.ts

The CLI discovers configuration, parses supported JavaScript and TypeScript files, builds the dependency graph, runs enabled plugins, and prints a terminal report. The default output is terminal text; use --json or --sarif for integrations.

Command Purpose
analyze [options] Analyze the current project. This is the default command.
export-cache <targetPath> Export the current analysis cache.
import-cache <sourcePath> Import an analysis cache before a run.
--help Print command and option help.
--version Print the CLI and detected Core versions.
Terminal window
# Structured JSON for scripts
npx @optiprune/cli analyze --json
# SARIF for code-scanning tools
npx @optiprune/cli analyze --sarif > optiprune.sarif
# Fail when high-confidence findings exist
npx @optiprune/cli analyze --fail-on high

The terminal reporter begins with Optiprune Analysis Report, followed by the root, a summary, and findings grouped by file. Each finding includes a rule, message, and—when a source location exists—confidence. See Output for the exact format and Reporters for Core-level formatting functions.

The CLI accepts project configuration from optiprune.json, optiprune.jsonc, optiprune.config.ts, optiprune.config.js, optiprune.config.mjs, or the package.json#optiprune field. See Configuration for precedence and examples.

Common options include:

Option Meaning
--rootDir <path> Analyze a different project root.
--entry <patterns...> Add entry-point files or globs.
--extensions <exts...> Set source extensions; the default includes .ts, .tsx, .js, .jsx, and .vue.
--ignore <patterns...> Ignore matching paths.
--no-conventional-entries Disable automatic conventional entries such as src/index.ts.
--cycles Include dependency-cycle information in human-readable output.
--ignore-tests Exclude conventional test files.
--verbose Include additional analyzer diagnostics.

Fixes are explicit and confidence-gated. Begin with a dry run:

Terminal window
npx @optiprune/cli analyze \
--fix files exports dependencies devDependencies conditions json \
--confidence medium+ \
--dry-run

Supported fix targets are files, exports, dependencies, devDependencies, conditions, and safely recoverable json changes. Review the proposed diff before running without --dry-run; see Fixes for safety boundaries.

Choose the CLI when you need a ready-to-run developer or CI command. Choose the Core API when another program owns orchestration, output, authentication, or user experience. The CLI and Core use the same analysis concepts, but they are separate npm packages and should be installed and documented separately.