ember-try provides various utility functions for configuration management, command execution, console output, and result reporting.
Utilities for loading, processing, and managing ember-try configuration.
/**
* Load and process ember-try configuration
* @param options - Configuration loading options
* @returns Promise resolving to processed configuration
*/
async function getConfig(options: {
/** Path to configuration file (relative to cwd) */
configPath?: string;
/** Current working directory */
cwd: string;
/** Version compatibility overrides for auto-generation */
versionCompatibility?: Record<string, string>;
}): Promise<EmberTryConfig>;
/**
* Determine configuration file path based on package.json or default location
* @param cwd - Current working directory
* @returns Path to configuration file
*/
function getConfigPath(cwd: string): string;
/**
* Load base configuration before processing
* @param options - Configuration loading options
* @returns Promise resolving to base configuration
*/
async function getBaseConfig(options: {
configPath?: string;
cwd: string;
versionCompatibility?: Record<string, string>;
}): Promise<EmberTryConfig>;
/**
* Extract version compatibility from package.json
* @param cwd - Current working directory
* @returns Version compatibility object or null
*/
function versionCompatibilityFromPackageJSON(cwd: string): Record<string, string> | null;
/**
* Read and parse package.json file
* @param cwd - Current working directory
* @returns Parsed package.json object or empty object if not found
*/
function readPackageFile(cwd: string): Record<string, any>;
/**
* Merge auto-generated config with explicit config file data
* @param autoConfig - Auto-generated configuration
* @param configData - Explicit configuration from file
* @returns Merged configuration
*/
function mergeAutoConfigAndConfigFileData(
autoConfig: EmberTryConfig,
configData?: Partial<EmberTryConfig>
): EmberTryConfig;Usage Examples:
// Load default configuration
const config = await getConfig({ cwd: process.cwd() });
// Load configuration with custom path
const config = await getConfig({
cwd: process.cwd(),
configPath: 'config/legacy-scenarios.js'
});
// Load configuration with version compatibility override
const config = await getConfig({
cwd: process.cwd(),
versionCompatibility: { ember: '>=3.16.0 <4.0.0' }
});
// Get configuration file path
const configPath = getConfigPath(process.cwd());
// Extract version compatibility from package.json
const versionCompat = versionCompatibilityFromPackageJSON(process.cwd());Utilities for formatted console output with color coding.
/**
* Log error message in red
* @param message - Message to log
*/
function error(message: string): void;
/**
* Log informational message in blue
* @param message - Message to log
*/
function info(message: string): void;
/**
* Log regular message
* @param message - Message to log
*/
function log(message: string): void;
/**
* Create styled prefix for messages
* @param string - Text to style as prefix
* @returns Styled prefix string
*/
function prefix(string: string): string;
/**
* Log success message in green
* @param message - Message to log
*/
function success(message: string): void;
/**
* Log warning message in yellow
* @param message - Message to log
*/
function warn(message: string): void;
/**
* Mock logging function for testing
* @param mockedLogFunction - Mock function to use for logging
*/
function _mockLog(mockedLogFunction: Function): void;
/**
* Restore original logging function
*/
function _restoreLog(): void;Usage Examples:
const { log, info, error, warn, success, prefix } = require('ember-try/lib/utils/console');
// Log different message types
log('Regular message');
info('Informational message');
error('Error occurred');
warn('Warning message');
success('Operation completed successfully');
// Create styled prefix
const styledPrefix = prefix('ember-try');
console.log(`${styledPrefix} Configuration loaded`);
// Mock logging for tests
_mockLog((message, consoleFunc, colorFunc) => {
// Custom logging logic
});
// Restore original logging
_restoreLog();Utilities for executing shell commands and managing ember command execution.
/**
* Execute command with ember path resolution
* @param root - Root directory for command execution
* @param commandArgs - Array of command arguments
* @param opts - Command execution options
* @returns Promise resolving to success boolean
*/
async function runCommand(
root: string,
commandArgs: string[],
opts?: any
): Promise<boolean>;
/**
* Low-level command execution utility
* @param command - Command to execute
* @param args - Command arguments
* @param options - Execution options
* @returns Promise that resolves when command completes
*/
async function run(
command: string,
args: string[],
options?: any
): Promise<void>;
/**
* Find ember executable path
* @param root - Project root directory
* @returns Promise resolving to ember executable path
*/
async function findEmberPath(root: string): Promise<string>;Usage Examples:
// Execute ember command
const success = await runCommand(
process.cwd(),
['ember', 'test', '--reporter', 'xunit'],
{ env: { NODE_ENV: 'test' } }
);
// Execute generic command
await run('npm', ['install'], { cwd: process.cwd() });
// Find ember executable
const emberPath = await findEmberPath(process.cwd());Utilities for formatting and displaying test results.
/**
* Class for formatting and displaying test results
*/
class ResultSummary {
/**
* Create a new ResultSummary instance
* @param options - Summary configuration options
*/
constructor(options: {
/** Array of scenario execution results */
results: ScenarioResult[];
});
/**
* Print formatted results summary to console
*/
print(): void;
}
/**
* Individual scenario result interface
*/
interface ScenarioResult {
/** Scenario name */
scenario: string;
/** Whether scenario is allowed to fail */
allowedToFail: boolean;
/** Dependency state changes */
dependencyState: any[];
/** Environment variables set */
envState?: Record<string, string>;
/** Command that was executed */
command: string;
/** Execution result (true = success, false = failure) */
result: boolean;
}Usage Examples:
// Create and display results summary
const results = [
{
scenario: 'ember-lts-3.16',
allowedToFail: false,
dependencyState: [],
command: 'ember test',
result: true
},
{
scenario: 'ember-canary',
allowedToFail: true,
dependencyState: [],
command: 'ember test',
result: false
}
];
const summary = new ResultSummary({ results });
summary.print();The ResultSummary displays:
Constants and utilities for working with different package managers.
/**
* Lockfile names by package manager
*/
const LOCKFILE = {
npm: 'package-lock.json',
pnpm: 'pnpm-lock.yaml',
yarn: 'yarn.lock'
};
/**
* Standard package.json filename constant
*/
const PACKAGE_JSON = 'package.json';
/**
* Package manager utility functions
*/
interface PackageManagerUtils {
/** Get lockfile name for package manager */
getLockfileName(packageManager: string): string;
/** Get default install options for package manager */
getDefaultInstallOptions(packageManager: string): string[];
/** Get overrides key for package manager */
getOverridesKey(packageManager: string): string;
}Utilities for file backup and restoration operations.
/**
* Backup utility for managing file backups and restoration
*/
class Backup {
/**
* Create a new Backup instance
* @param options - Backup configuration
*/
constructor(options: {
/** Current working directory */
cwd: string;
});
/**
* Add a single file to backup directory
* @param filename - File path relative to cwd to backup
* @returns Promise that resolves when backup is complete
*/
addFile(filename: string): Promise<void>;
/**
* Add multiple files to backup directory
* @param filenames - Array of file paths relative to cwd to backup
* @returns Promise that resolves when all backups are complete
*/
addFiles(filenames: string[]): Promise<void>;
/**
* Restore a single file from backup directory
* @param filename - File path relative to cwd to restore
* @returns Promise that resolves when restoration is complete
*/
restoreFile(filename: string): Promise<void>;
/**
* Restore multiple files from backup directory
* @param filenames - Array of file paths relative to cwd to restore
* @returns Promise that resolves when all restorations are complete
*/
restoreFiles(filenames: string[]): Promise<void>;
/**
* Get absolute path for a file in backup directory
* @param filename - File path relative to cwd
* @returns Absolute path in backup directory
*/
pathForFile(filename: string): string;
/**
* Clean up backup directory and all files
* @returns Promise that resolves when cleanup is complete
*/
cleanUp(): Promise<void>;
}Usage Examples:
// Create backup utility
const backup = new Backup({ cwd: process.cwd() });
// Backup files before modification
await backup.addFiles(['package.json', 'package-lock.json']);
// ... make changes ...
// Restore original files
await backup.restoreFiles(['package.json', 'package-lock.json']);
// Clean up backup directory
await backup.cleanUp();Debug logging utilities using the debug module.
/**
* Create debug function for a namespace
* @param namespace - Debug namespace
* @returns Debug function
*/
function createDebugFunction(namespace: string): (...args: any[]) => void;
/**
* Common debug namespaces used by ember-try
*/
const DEBUG_NAMESPACES = {
commands: {
tryEach: 'ember-try:commands:try-each',
tryOne: 'ember-try:commands:try-one',
tryEmber: 'ember-try:commands:try-ember',
config: 'ember-try:commands:config',
reset: 'ember-try:commands:reset'
},
tasks: {
tryEach: 'ember-try:task:try-each'
},
utils: {
config: 'ember-try:utils:config'
}
};Usage Examples:
const debug = require('debug')('ember-try:commands:try-each');
// Log debug information
debug('Options:', commandOptions);
debug('Config: %s', JSON.stringify(config));
// Enable debug output via environment variable
// DEBUG=ember-try:* ember try:eachUtilities include comprehensive error handling:
Most utilities throw descriptive errors that can be caught and handled by calling code.