AI-first build platform designed for monorepo development that provides task orchestration, project graph generation, and CLI tools for managing complex software projects
npx @tessl/cli install tessl/npm-nx@21.4.0Nx is an AI-first build platform designed for monorepo development that provides task orchestration, project graph generation, and CLI tools for managing complex software projects. Originally, @nrwl/tao was a separate CLI package for generating code and running commands, but it has been deprecated and merged into the main nx package as of v19. The nx package now incorporates all the functionality that was previously provided by @nrwl/tao, including code generation, workspace management, task execution, and monorepo orchestration.
npm install nximport { createProjectGraphAsync, readNxJson, logger } from "nx/src/devkit-exports";For CommonJS:
const { createProjectGraphAsync, readNxJson, logger } = require("nx/src/devkit-exports");CLI Usage:
# Global installation
npm install -g nx
# Local installation (recommended)
npm install --save-dev nx
npx nx <command>import {
createProjectGraphAsync,
readNxJson,
readProjectConfiguration,
logger
} from "nx/src/devkit-exports";
// Read workspace configuration
const nxConfig = readNxJson();
console.log('Workspace name:', nxConfig.workspaceLayout);
// Create project dependency graph
const projectGraph = await createProjectGraphAsync();
console.log('Projects:', Object.keys(projectGraph.nodes));
// Read specific project configuration
const projectConfig = readProjectConfiguration('my-app');
console.log('Project targets:', Object.keys(projectConfig.targets));
// Use logger for consistent output
logger.info('Operation completed successfully');CLI Basic Usage:
# Create new workspace
npx create-nx-workspace@latest my-workspace
# Generate new project
nx generate @nx/react:app my-app
# Run tasks
nx build my-app
nx test my-app
nx lint my-app
# Run tasks on multiple projects
nx run-many --target=build --all
nx affected --target=test
# View project graph
nx graphNx is built around several key architectural components:
Complete CLI toolkit for monorepo management including project generation, task execution, dependency analysis, workspace maintenance, and cloud integration.
// All CLI commands export command objects for programmatic access
export * from './add/command-object';
export * from './affected/command-object';
export * from './generate/command-object';
export * from './run/command-object';
// ... 20 more CLI commandsEssential APIs for workspace and project management, providing programmatic access to Nx's core functionality.
function createProjectGraphAsync(): Promise<ProjectGraph>;
function readNxJson(): NxJsonConfiguration;
function readProjectConfiguration(projectName: string): ProjectConfiguration;
function updateProjectConfiguration(projectName: string, config: ProjectConfiguration): void;
function getProjects(): Map<string, ProjectConfiguration>;
interface ProjectGraph {
nodes: Record<string, ProjectGraphProjectNode>;
dependencies: Record<string, ProjectGraphDependency[]>;
}
interface NxJsonConfiguration {
workspaceLayout?: WorkspaceLayout;
tasksRunnerOptions?: TasksRunnerOptions;
namedInputs?: NamedInputs;
targetDefaults?: TargetDefaults;
}File system utilities and virtual file tree operations for generators and automated code modifications.
function readJsonFile<T = any>(path: string): T;
function writeJsonFile<T = any>(path: string, data: T): void;
function updateJsonFile<T = any>(path: string, updater: (data: T) => T): void;
interface Tree {
read(filePath: string): Buffer | null;
write(filePath: string, content: Buffer | string): void;
exists(filePath: string): boolean;
delete(filePath: string): void;
rename(from: string, to: string): void;
}Task execution, caching, and orchestration APIs for building advanced build tools.
function runExecutor<T = any>(
targetDescription: Target,
overrides: Partial<T>,
context: ExecutorContext
): Promise<AsyncIterableIterator<{ success: boolean }>>;
interface Task {
id: string;
target: Target;
projectRoot: string;
overrides: any;
}
interface TaskGraph {
tasks: Record<string, Task>;
dependencies: Record<string, string[]>;
roots: string[];
}Built-in code generation and task execution tools, plus APIs for creating custom generators and executors.
function formatFiles(tree: Tree): Promise<void>;
function generateFiles(tree: Tree, templatePath: string, targetPath: string, substitutions: any): void;
function installPackagesTask(tree: Tree): GeneratorCallback;
interface GeneratorCallback {
(): void | Promise<void>;
}
interface ExecutorContext {
root: string;
cwd: string;
workspace: WorkspaceJsonConfiguration;
isVerbose: boolean;
projectName?: string;
targetName?: string;
configurationName?: string;
}APIs for creating custom plugins that extend Nx's project detection, dependency analysis, and task configuration.
interface NxPlugin {
name: string;
createNodes?: CreateNodes;
createDependencies?: CreateDependencies;
processProjectGraph?: ProcessProjectGraph;
}
type CreateNodes = (configFilePath: string) => CreateNodesResult;
type CreateDependencies = (opts: CreateDependenciesContext) => RawProjectGraphDependency[];interface ProjectConfiguration {
name?: string;
root: string;
sourceRoot?: string;
projectType?: ProjectType;
targets?: { [targetName: string]: TargetConfiguration };
tags?: string[];
implicitDependencies?: string[];
}
interface TargetConfiguration {
executor: string;
outputs?: string[];
options?: any;
configurations?: { [config: string]: any };
defaultConfiguration?: string;
dependsOn?: TargetDependency[];
}
interface Target {
project: string;
target: string;
configuration?: string;
}
type ProjectType = 'application' | 'library';