CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nrwl--devkit

Legacy wrapper providing comprehensive Nx devkit utilities for creating plugins, generators, and executors

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

project-configuration.mddocs/

Project Configuration Management

APIs for managing workspace projects, reading and updating project configurations, and handling workspace-level settings. These functions provide programmatic access to project metadata, build targets, and workspace structure.

Capabilities

Project Configuration Functions

Core functions for managing individual project configurations.

/**
 * Add a new project configuration to the workspace
 * @param tree - Virtual file system tree
 * @param projectName - Name of the project to add
 * @param projectConfiguration - Project configuration object
 */
function addProjectConfiguration(
  tree: Tree,
  projectName: string,
  projectConfiguration: ProjectConfiguration
): void;

/**
 * Read an existing project's configuration
 * @param tree - Virtual file system tree
 * @param projectName - Name of the project to read
 * @returns Project configuration object
 */
function readProjectConfiguration(tree: Tree, projectName: string): ProjectConfiguration;

/**
 * Update an existing project's configuration
 * @param tree - Virtual file system tree
 * @param projectName - Name of the project to update
 * @param projectConfiguration - Updated project configuration
 */
function updateProjectConfiguration(
  tree: Tree,
  projectName: string,
  projectConfiguration: ProjectConfiguration
): void;

/**
 * Remove a project configuration from the workspace
 * @param tree - Virtual file system tree
 * @param projectName - Name of the project to remove
 */
function removeProjectConfiguration(tree: Tree, projectName: string): void;

/**
 * Get all projects in the workspace
 * @param tree - Virtual file system tree
 * @returns Map of project names to configurations
 */
function getProjects(tree: Tree): Map<string, ProjectConfiguration>;

Usage Examples:

import { 
  Tree, 
  addProjectConfiguration, 
  readProjectConfiguration,
  updateProjectConfiguration,
  ProjectConfiguration 
} from "@nrwl/devkit";

function manageProjects(tree: Tree) {
  // Add a new library project
  const libraryConfig: ProjectConfiguration = {
    root: 'libs/my-lib',
    projectType: 'library',
    sourceRoot: 'libs/my-lib/src',
    targets: {
      build: {
        executor: '@nx/js:tsc',
        options: {
          outputPath: 'dist/libs/my-lib',
          main: 'libs/my-lib/src/index.ts',
          tsConfig: 'libs/my-lib/tsconfig.lib.json'
        }
      },
      test: {
        executor: '@nx/jest:jest',
        options: {
          jestConfig: 'libs/my-lib/jest.config.ts'
        }
      }
    },
    tags: ['scope:shared', 'type:util']
  };
  
  addProjectConfiguration(tree, 'my-lib', libraryConfig);
  
  // Read and modify existing project
  const existingProject = readProjectConfiguration(tree, 'my-lib');
  existingProject.targets!.lint = {
    executor: '@nx/linter:eslint',
    options: {
      lintFilePatterns: ['libs/my-lib/**/*.ts']
    }
  };
  
  updateProjectConfiguration(tree, 'my-lib', existingProject);
  
  // List all projects
  const projects = getProjects(tree);
  for (const [name, config] of projects) {
    console.log(`Project: ${name}, Type: ${config.projectType}`);
  }
}

Workspace Configuration Functions

Functions for managing workspace-level Nx configuration.

/**
 * Read the nx.json configuration file
 * @param tree - Virtual file system tree
 * @returns Nx configuration object
 */
function readNxJson(tree: Tree): NxJsonConfiguration | null;

/**
 * Update the nx.json configuration file
 * @param tree - Virtual file system tree
 * @param nxJson - Updated Nx configuration
 */
function updateNxJson(tree: Tree, nxJson: NxJsonConfiguration): void;

/**
 * Get workspace layout configuration
 * @param tree - Virtual file system tree
 * @returns Workspace layout information
 */
function getWorkspaceLayout(tree: Tree): {
  appsDir: string;
  libsDir: string;
  npmScope?: string;
};

/**
 * Extract directory layout information
 * @param nxJson - Nx configuration object
 * @returns Layout directory configuration
 */
function extractLayoutDirectory(nxJson?: NxJsonConfiguration): {
  appsDir: string;
  libsDir: string;
};

Usage Examples:

import { 
  Tree, 
  readNxJson, 
  updateNxJson, 
  getWorkspaceLayout,
  NxJsonConfiguration 
} from "@nrwl/devkit";

function configureWorkspace(tree: Tree) {
  // Read current nx.json
  const nxJson = readNxJson(tree);
  
  if (nxJson) {
    // Add target defaults
    nxJson.targetDefaults = {
      ...nxJson.targetDefaults,
      build: {
        dependsOn: ['^build'],
        inputs: ['production', '^production']
      }
    };
    
    // Add named inputs
    nxJson.namedInputs = {
      ...nxJson.namedInputs,
      production: [
        'default',
        '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
        '!{projectRoot}/tsconfig.spec.json',
        '!{projectRoot}/jest.config.[jt]s'
      ]
    };
    
    updateNxJson(tree, nxJson);
  }
  
  // Get workspace layout
  const layout = getWorkspaceLayout(tree);
  console.log(`Apps directory: ${layout.appsDir}`);
  console.log(`Libs directory: ${layout.libsDir}`);
}

Configuration Types

Core interfaces for project and workspace configuration.

/**
 * Configuration for a single project
 */
interface ProjectConfiguration {
  /** Optional project name (usually inferred from directory structure) */
  name?: string;
  /** Root directory of the project relative to workspace root */
  root: string;
  /** Source root directory relative to workspace root */
  sourceRoot?: string;
  /** Type of project */
  projectType?: ProjectType;
  /** Build targets available for this project */
  targets?: Record<string, TargetConfiguration>;
  /** Tags for categorizing and filtering projects */
  tags?: string[];
  /** Explicit dependencies on other projects */
  implicitDependencies?: string[];
  /** Named inputs for this project */
  namedInputs?: Record<string, (InputDefinition | string)[]>;
  /** Additional metadata */
  metadata?: Record<string, any>;
}

/**
 * Project type classification
 */
type ProjectType = 'application' | 'library';

/**
 * Configuration for a build target
 */
interface TargetConfiguration<T = any> {
  /** Executor to run for this target */
  executor: string;
  /** Default options for the executor */
  options?: T;
  /** Named configurations with option overrides */
  configurations?: Record<string, Partial<T>>;
  /** Default configuration to use */
  defaultConfiguration?: string;
  /** Dependencies that must run before this target */
  dependsOn?: TargetDependencyConfig[];
  /** Input definitions for cache invalidation */
  inputs?: (InputDefinition | string)[];
  /** Output paths for caching */
  outputs?: string[];
  /** Whether to cache this target */
  cache?: boolean;
  /** Additional metadata */
  metadata?: Record<string, any>;
}

/**
 * Target dependency configuration
 */
interface TargetDependencyConfig {
  /** Target name */
  target: string;
  /** Project to run target on (defaults to current project) */
  projects?: string | string[];
  /** Configuration to use */
  params?: 'forward' | 'ignore' | Record<string, any>;
}

/**
 * Workspace-level Nx configuration
 */
interface NxJsonConfiguration {
  /** Configuration to extend */
  extends?: string;
  /** NPM scope for the workspace */
  npmScope?: string;
  /** Affected command configuration */
  affected?: NxAffectedConfig;
  /** Implicit dependencies between projects */
  implicitDependencies?: Record<string, string[] | '*'>;
  /** Default target configurations */
  targetDefaults?: TargetDefaults;
  /** CLI configuration */
  cli?: {
    defaultCollection?: string;
    packageManager?: PackageManager;
    analytics?: boolean;
  };
  /** Generator defaults */
  generators?: Record<string, any>;
  /** Task runner configuration */
  tasksRunnerOptions?: Record<string, any>;
  /** Named input definitions */
  namedInputs?: Record<string, (InputDefinition | string)[]>;
  /** Plugin configurations */
  plugins?: PluginConfiguration[];
  /** Maximum parallel processes */
  parallel?: number;
  /** Cache directory location */
  cacheDirectory?: string;
  /** Default base branch for affected calculations */
  defaultBase?: string;
  /** Nx Cloud access token */
  nxCloudAccessToken?: string;
  /** Whether to use the Nx daemon */
  useDaemonProcess?: boolean;
}

/**
 * Plugin configuration
 */
interface PluginConfiguration {
  plugin: string;
  options?: any;
}

/**
 * Input definition for caching
 */
interface InputDefinition {
  input?: string;
  projects?: string | string[];
  dependencies?: boolean;
}

Usage Examples:

import { 
  ProjectConfiguration, 
  TargetConfiguration, 
  NxJsonConfiguration 
} from "@nrwl/devkit";

// Define a React application project
const reactAppConfig: ProjectConfiguration = {
  root: 'apps/my-app',
  projectType: 'application',
  sourceRoot: 'apps/my-app/src',
  targets: {
    build: {
      executor: '@nx/webpack:webpack',
      options: {
        outputPath: 'dist/apps/my-app',
        index: 'apps/my-app/src/index.html',
        main: 'apps/my-app/src/main.tsx'
      },
      configurations: {
        production: {
          fileReplacements: [
            {
              replace: 'apps/my-app/src/environments/environment.ts',
              with: 'apps/my-app/src/environments/environment.prod.ts'
            }
          ]
        }
      }
    },
    serve: {
      executor: '@nx/webpack:dev-server',
      options: {
        buildTarget: 'my-app:build'
      }
    }
  },
  tags: ['scope:app', 'type:web']
};

Install with Tessl CLI

npx tessl i tessl/npm-nrwl--devkit

docs

executors.md

generators.md

index.md

json-utilities.md

package-management.md

plugins.md

project-configuration.md

project-graph.md

string-path-utilities.md

testing-utilities.md

tree-filesystem.md

tile.json