CLI compatibility layer for older Nx workspaces that serves as a bridge to core nx functionality
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Formatted logging system with consistent branding and error handling for CLI applications. Provides standardized output formatting with color-coded messages and NX branding.
Main logging utility with methods for different message types and consistent formatting.
/**
* Main logging utility object with formatted output methods
*/
export const logger: {
/** Logs warning messages in yellow */
warn(s: string | any): void;
/** Logs error messages in red, handles NX-prefixed messages and Error objects with stack traces */
error(s: string | Error | any): void;
/** Logs info messages with NX branding */
info(s: string | any): void;
/** Basic console.log wrapper */
log(...s: any[]): void;
/** Console debug wrapper */
debug(...s: any[]): void;
/** Console error wrapper for fatal errors */
fatal(...s: any[]): void;
};Usage Examples:
import { logger } from "@nrwl/tao/shared/logger";
// Basic logging
logger.info("Starting workspace operation");
logger.warn("Configuration file not found, using defaults");
logger.error("Failed to read project configuration");
// Error object handling
try {
// some operation
} catch (error) {
logger.error(error); // Automatically handles stack traces
}
// Debug information
logger.debug("Processing file:", filePath);
// Fatal errors
logger.fatal("Critical error: workspace corrupted");Pre-formatted branding constants for consistent message styling.
/** Formatted prefix string with cyan "NX" branding */
export const NX_PREFIX: string;
/** Formatted error prefix string with red "ERROR" branding */
export const NX_ERROR: string;Usage Examples:
import { NX_PREFIX, NX_ERROR } from "@nrwl/tao/shared/logger";
console.log(`${NX_PREFIX} Custom operation completed`);
console.log(`${NX_ERROR} Custom error occurred`);Utility functions for string formatting and processing.
/**
* Removes common leading whitespace from multi-line strings
* @param str - Multi-line string with potential indentation
* @returns String with common leading whitespace removed
*/
export function stripIndent(str: string): string;Usage Examples:
import { stripIndent } from "@nrwl/tao/shared/logger";
const template = stripIndent`
This is a multi-line string
with various indentation levels
that will be normalized
`;
console.log(template);
// Output:
// This is a multi-line string
// with various indentation levels
// that will be normalizedThe logging utilities integrate seamlessly with Nx operations:
import { logger } from "@nrwl/tao/shared/logger";
import { Workspaces } from "@nrwl/tao/shared/workspace";
function processWorkspace(root: string) {
logger.info("Analyzing workspace structure");
try {
const workspaces = new Workspaces(root);
const projects = workspaces.readProjectsConfigurations();
logger.info(`Found ${Object.keys(projects.projects).length} projects`);
} catch (error) {
logger.error("Failed to read workspace configuration");
logger.error(error);
}
}Install with Tessl CLI
npx tessl i tessl/npm-nrwl--tao