or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

adapter.mdcache.mdcli.mdcommit.mdconfig.mdgit.mdindex.mdinit.mdstaging.md
tile.json

adapter.mddocs/

Adapter Management

The adapter system provides functionality for installing, configuring, and loading commit message format adapters that define the interactive prompting behavior.

Capabilities

Adapter Path Resolution

Resolves adapter module paths from various sources including npm packages and local paths.

/**
 * Resolves an adapter path to an absolute module path
 * @param inboundAdapterPath - Package name or file path to adapter
 * @returns Resolved absolute path to adapter module
 * @throws Error if adapter cannot be resolved
 */
function resolveAdapterPath(inboundAdapterPath: string): string;

Usage Examples:

const { adapter } = require('commitizen');

// Resolve npm package
const npmPath = adapter.resolveAdapterPath('cz-conventional-changelog');

// Resolve local path (relative to git root)
const localPath = adapter.resolveAdapterPath('./my-custom-adapter');

// Resolve scoped package
const scopedPath = adapter.resolveAdapterPath('@company/cz-adapter');

Prompter Loading

Loads and validates the prompter function from resolved adapter modules.

/**
 * Loads the prompter function from an adapter
 * @param adapterPath - Path to adapter module (package name or file path)
 * @returns Prompter function for interactive commit message creation
 * @throws Error if prompter method is not found or invalid
 */
function getPrompter(adapterPath: string): PrompterFunction;

type PrompterFunction = (
  inquirer: object,
  callback: (error: Error | null, template: string, overrideOptions?: object) => void
) => void;

Usage Examples:

const inquirer = require('inquirer');
const { adapter } = require('commitizen');

// Load prompter from adapter
const prompter = adapter.getPrompter('cz-conventional-changelog');

// Use prompter for commit message creation
prompter(inquirer, (error, commitMessage, overrideOptions) => {
  if (error) {
    console.error('Prompter error:', error);
    return;
  }
  console.log('Generated commit message:', commitMessage);
  console.log('Override options:', overrideOptions);
});

Configuration Management

Updates package.json with adapter configuration and manages commitizen settings.

/**
 * Adds adapter path configuration to package.json
 * @param cliPath - Absolute path to CLI installation directory
 * @param repoPath - Path to repository root
 * @param adapterNpmName - NPM package name of the adapter
 */
function addPathToAdapterConfig(cliPath: string, repoPath: string, adapterNpmName: string): void;

Usage Examples:

const path = require('path');
const { adapter } = require('commitizen');

// Add adapter config to package.json
adapter.addPathToAdapterConfig(
  path.join(__dirname, '../../'),  // CLI path
  process.cwd(),                   // Repository path
  'cz-conventional-changelog'      // Adapter name
);

// This modifies package.json to include:
// {
//   "config": {
//     "commitizen": {
//       "path": "./node_modules/cz-conventional-changelog"
//     }
//   }
// }

Install Command Generation

Generates package manager-specific install commands for adapters.

/**
 * Generates install command string for specified package manager
 * @param stringMappings - Map of install flags to package manager options
 * @param adapterNpmName - NPM package name to install
 * @param packageManager - Package manager to use ('npm', 'yarn', 'pnpm')
 * @returns Complete install command string
 */
function generateInstallAdapterCommand(
  stringMappings: Map<string, string | undefined>,
  adapterNpmName: string,
  packageManager?: 'npm' | 'yarn' | 'pnpm'
): string;

Usage Examples:

const { adapter } = require('commitizen');

// Generate npm install command
const flags = adapter.getInstallStringMappings(
  { saveDev: true, saveExact: true },
  'npm'
);
const npmCmd = adapter.generateInstallAdapterCommand(
  flags,
  'cz-conventional-changelog',
  'npm'
);
// Result: "npm install cz-conventional-changelog --save-dev --save-exact"

// Generate yarn add command  
const yarnFlags = adapter.getInstallStringMappings(
  { dev: true, exact: true },
  'yarn'
);
const yarnCmd = adapter.generateInstallAdapterCommand(
  yarnFlags,
  'cz-conventional-changelog', 
  'yarn'
);
// Result: "yarn add cz-conventional-changelog --dev --exact"

Install Flag Mapping

Maps generic install options to package manager-specific flags.

/**
 * Maps install flags to package manager-specific options
 * @param flags - Generic install flags
 * @param packageManager - Target package manager
 * @returns Map of flag names to command-line options
 */
function getInstallStringMappings(
  flags: InstallFlags,
  packageManager: 'npm' | 'yarn' | 'pnpm'
): Map<string, string | undefined>;

interface InstallFlags {
  save?: boolean;        // Add to dependencies
  dev?: boolean;         // Add to devDependencies (yarn)
  saveDev?: boolean;     // Add to devDependencies (npm/pnpm)
  exact?: boolean;       // Install exact version (yarn)
  saveExact?: boolean;   // Install exact version (npm/pnpm)
  force?: boolean;       // Force installation
}

Directory Utilities

Utilities for locating project directories and node_modules paths.

/**
 * Finds the nearest node_modules directory
 * @param options - Search options (passed to find-node-modules)
 * @returns Path to nearest node_modules directory
 */
function getNearestNodeModulesDirectory(options?: object): string;

/**
 * Gets the nearest project root directory
 * @param repoPath - Repository path
 * @param options - Search options
 * @returns Path to project root directory
 */
function getNearestProjectRootDirectory(repoPath: string, options?: object): string;

/**
 * Gets the git repository root path
 * @returns Absolute path to git repository root
 */
function getGitRootPath(): string;

Usage Examples:

const { adapter } = require('commitizen');

// Find node_modules
const nodeModulesPath = adapter.getNearestNodeModulesDirectory();
console.log('node_modules at:', nodeModulesPath);

// Find project root
const projectRoot = adapter.getNearestProjectRootDirectory(process.cwd());
console.log('Project root:', projectRoot);

// Get git root
const gitRoot = adapter.getGitRootPath();
console.log('Git repository root:', gitRoot);

Error Handling

Adapter functions handle various error conditions:

  • Module resolution failures: Clear error messages with resolution suggestions
  • Invalid prompter functions: Validation of adapter exports and function signatures
  • Missing node_modules: Helpful guidance for project setup
  • File system errors: Graceful handling of permission and access issues
  • Git repository detection: Fallback behavior for non-git directories