AI-first build platform designed for monorepo development that provides task orchestration, project graph generation, and CLI tools for managing complex software projects
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Essential programmatic APIs for workspace and project management, providing direct access to Nx's core functionality for building custom tools and plugins.
Functions for creating and analyzing the project dependency graph.
/**
* Creates the project dependency graph asynchronously
* @param opts - Optional configuration for graph creation
* @returns Promise resolving to complete project graph
*/
function createProjectGraphAsync(
opts?: { exitOnError?: boolean; resetDaemonClient?: boolean }
): Promise<ProjectGraph>;
/**
* Synchronously gets cached project graph (if available)
* @returns Current project graph or null if not cached
*/
function readCachedProjectGraph(): ProjectGraph | null;
interface ProjectGraph {
nodes: Record<string, ProjectGraphProjectNode>;
dependencies: Record<string, ProjectGraphDependency[]>;
allWorkspaceFiles?: FileMap;
}
interface ProjectGraphProjectNode {
name: string;
type: ProjectType;
data: ProjectGraphProjectNodeData;
}
interface ProjectGraphProjectNodeData {
root: string;
sourceRoot?: string;
targets?: { [targetName: string]: TargetConfiguration };
files?: ProjectFileMap;
tags?: string[];
}
interface ProjectGraphDependency {
source: string;
target: string;
type: DependencyType;
}
type DependencyType =
| 'static'
| 'dynamic'
| 'implicit'
| 'direct'
| 'indirect';Functions for reading and updating workspace and project configurations.
/**
* Reads the nx.json configuration file from file system
* @returns Nx workspace configuration
*/
function readNxJson(): NxJsonConfiguration;
/**
* Reads the nx.json configuration from a virtual file tree (for generators)
* @param tree - Virtual file tree
* @returns Nx workspace configuration
*/
function readNxJson(tree: Tree): NxJsonConfiguration;
/**
* Updates the nx.json configuration file
* @param nxJson - Updated configuration object
*/
function updateNxJson(nxJson: NxJsonConfiguration): void;
/**
* Reads configuration for a specific project
* @param projectName - Name of the project
* @returns Project configuration
*/
function readProjectConfiguration(projectName: string): ProjectConfiguration;
/**
* Updates configuration for a specific project
* @param projectName - Name of the project
* @param config - Updated project configuration
*/
function updateProjectConfiguration(
projectName: string,
config: ProjectConfiguration
): void;
/**
* Gets all projects in the workspace
* @returns Map of project names to configurations
*/
function getProjects(): Map<string, ProjectConfiguration>;
/**
* Adds a new project configuration to the workspace
* @param tree - Virtual file tree (for generators)
* @param projectName - Name of the project
* @param config - Project configuration
*/
function addProjectConfiguration(
tree: Tree,
projectName: string,
config: ProjectConfiguration
): void;
/**
* Removes a project configuration from the workspace
* @param tree - Virtual file tree (for generators)
* @param projectName - Name of the project to remove
*/
function removeProjectConfiguration(tree: Tree, projectName: string): void;
/**
* Gets projects configurations from a project graph
* @param projectGraph - Project dependency graph
* @returns Projects configurations
*/
function readProjectsConfigurationFromProjectGraph(
projectGraph: ProjectGraph
): ProjectsConfigurations;
interface NxJsonConfiguration {
workspaceLayout?: WorkspaceLayout;
cli?: CLIOptions;
tasksRunnerOptions?: TasksRunnerOptions;
namedInputs?: NamedInputs;
targetDefaults?: TargetDefaults;
generators?: GeneratorOptions;
plugins?: PluginConfiguration[];
defaultBase?: string;
affected?: AffectedOptions;
parallel?: number;
cacheDirectory?: string;
}
interface WorkspaceLayout {
appsDir?: string;
libsDir?: string;
}
interface ProjectConfiguration {
name?: string;
root: string;
sourceRoot?: string;
projectType?: ProjectType;
targets?: { [targetName: string]: TargetConfiguration };
tags?: string[];
implicitDependencies?: string[];
namedInputs?: NamedInputs;
generators?: GeneratorOptions;
}
type ProjectType = 'application' | 'library';Core workspace information and utility functions.
/**
* Gets the absolute path to the workspace root
* @returns Workspace root directory path
*/
function getWorkspaceRoot(): string;
/**
* Workspace root directory path (constant)
*/
const workspaceRoot: string;
/**
* Gets workspace configuration including all projects
* @returns Complete workspace configuration
*/
function readWorkspaceConfiguration(): WorkspaceConfiguration;
/**
* Updates workspace configuration
* @param config - Updated workspace configuration
*/
function updateWorkspaceConfiguration(config: WorkspaceConfiguration): void;
interface WorkspaceConfiguration {
version: number;
projects: Record<string, ProjectConfiguration>;
}
interface ProjectsConfigurations {
version: number;
projects: Record<string, ProjectConfiguration>;
}Utilities for consistent logging and user output.
/**
* Logger instance for consistent output formatting
*/
interface Logger {
/** Log informational message */
info(message: string): void;
/** Log warning message */
warn(message: string): void;
/** Log error message */
error(message: string): void;
/** Log debug message (only shown in verbose mode) */
debug(message: string): void;
/** Log message without formatting */
log(message: string): void;
}
const logger: Logger;
/**
* Output utilities for formatted console output
*/
interface Output {
/** Log formatted message with title */
log(options: { title: string; bodyLines?: string[] }): void;
/** Log error message with formatting */
error(options: { title: string; bodyLines?: string[] }): void;
/** Log warning message with formatting */
warn(options: { title: string; bodyLines?: string[] }): void;
/** Log success message with formatting */
success(options: { title: string; bodyLines?: string[] }): void;
/** Log note/info message with formatting */
note(options: { title: string; bodyLines?: string[] }): void;
}
const output: Output;Types and utilities for build targets and task configuration.
interface TargetConfiguration {
executor: string;
outputs?: string[];
options?: any;
configurations?: { [config: string]: any };
defaultConfiguration?: string;
dependsOn?: TargetDependency[];
inputs?: (InputDefinition | string)[];
cache?: boolean;
}
interface TargetDependency {
target: string;
projects?: string | string[];
params?: 'forward' | 'ignore';
}
interface Target {
project: string;
target: string;
configuration?: string;
}
interface InputDefinition {
input?: string;
fileset?: string;
projects?: string | string[];
dependencies?: boolean;
externalDependencies?: string[];
}
type NamedInputs = Record<string, (InputDefinition | string)[]>;
type TargetDefaults = Record<string, Partial<TargetConfiguration>>;Types for configuring and managing Nx plugins.
interface PluginConfiguration {
plugin: string;
options?: any;
}
type CreateNodes = (
configFilePath: string,
options: any,
context: CreateNodesContext
) => CreateNodesResult;
interface CreateNodesResult {
projects?: Record<
string,
{
name?: string;
targets?: Record<string, TargetConfiguration>;
metadata?: ProjectMetadata;
}
>;
}
interface CreateNodesContext {
nxJsonConfiguration: NxJsonConfiguration;
workspaceRoot: string;
configFiles: string[];
}import {
createProjectGraphAsync,
readNxJson,
getProjects,
logger
} from "nx/src/devkit-exports";
async function analyzeWorkspace() {
// Read workspace configuration
const nxConfig = readNxJson();
logger.info(`Analyzing workspace with ${Object.keys(nxConfig.projects || {}).length} projects`);
// Get all projects
const projects = getProjects();
// Create project graph for dependency analysis
const graph = await createProjectGraphAsync();
// Find apps vs libraries
const apps = Array.from(projects.entries())
.filter(([_, config]) => config.projectType === 'application')
.map(([name]) => name);
const libs = Array.from(projects.entries())
.filter(([_, config]) => config.projectType === 'library')
.map(([name]) => name);
logger.info(`Found ${apps.length} applications and ${libs.length} libraries`);
return { projects, graph, apps, libs };
}import {
readProjectConfiguration,
updateProjectConfiguration,
logger
} from "nx/src/devkit-exports";
function addTargetToProject(projectName: string, targetName: string, targetConfig: TargetConfiguration) {
try {
// Read current configuration
const projectConfig = readProjectConfiguration(projectName);
// Add new target
const updatedConfig = {
...projectConfig,
targets: {
...projectConfig.targets,
[targetName]: targetConfig
}
};
// Save updated configuration
updateProjectConfiguration(projectName, updatedConfig);
logger.info(`Added target '${targetName}' to project '${projectName}'`);
} catch (error) {
logger.error(`Failed to update project '${projectName}': ${error.message}`);
}
}
// Usage
addTargetToProject('my-app', 'custom-build', {
executor: '@nx/webpack:webpack',
options: {
outputPath: 'dist/my-app',
main: 'src/main.ts',
tsConfig: 'tsconfig.app.json'
},
configurations: {
production: {
optimization: true,
sourceMap: false
}
}
});import { createProjectGraphAsync, logger } from "nx/src/devkit-exports";
async function findProjectDependencies(projectName: string) {
const graph = await createProjectGraphAsync();
// Find direct dependencies
const dependencies = graph.dependencies[projectName] || [];
const directDeps = dependencies
.filter(dep => dep.type === 'static' || dep.type === 'dynamic')
.map(dep => dep.target);
// Find projects that depend on this project
const dependents = Object.keys(graph.dependencies)
.filter(project =>
graph.dependencies[project].some(dep => dep.target === projectName)
);
logger.info(`Project '${projectName}' dependencies:`);
logger.info(` Direct: ${directDeps.join(', ')}`);
logger.info(` Dependents: ${dependents.join(', ')}`);
return { dependencies: directDeps, dependents };
}Install with Tessl CLI
npx tessl i tessl/npm-nx