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

tree-filesystem.mddocs/

Tree & File System Operations

Core virtual file system interface for reading, writing, and manipulating files during code generation and workspace modifications. The Tree interface provides a virtual view of the filesystem that batches changes and applies them atomically.

Capabilities

Tree Interface

The main interface for all file system operations during code generation.

/**
 * Virtual file system tree for batching file operations
 */
interface Tree {
  /** Root directory of the workspace - all paths are relative to this */
  root: string;
  /**
   * Read file contents as Buffer
   * @param filePath - Path to the file to read
   * @returns File contents as Buffer or null if file doesn't exist
   */
  read(filePath: string): Buffer | null;
  
  /**
   * Read file contents as string with specified encoding
   * @param filePath - Path to the file to read
   * @param encoding - Character encoding for the file
   * @returns File contents as string or null if file doesn't exist
   */
  read(filePath: string, encoding: BufferEncoding): string | null;
  
  /**
   * Write content to a file
   * @param filePath - Path where to write the file
   * @param content - File content as Buffer or string
   * @param options - Optional write options
   */
  write(filePath: string, content: Buffer | string, options?: TreeWriteOptions): void;
  
  /**
   * Check if a file or directory exists
   * @param filePath - Path to check
   * @returns True if file exists, false otherwise
   */
  exists(filePath: string): boolean;
  
  /**
   * Delete a file
   * @param filePath - Path to the file to delete
   */
  delete(filePath: string): void;
  
  /**
   * Rename a file or directory
   * @param from - Current path
   * @param to - New path
   */
  rename(from: string, to: string): void;
  
  /**
   * Check if path is a file (not a directory)
   * @param filePath - Path to check
   * @returns True if path is a file, false if directory or doesn't exist
   */
  isFile(filePath: string): boolean;
  
  /**
   * List immediate children of a directory
   * @param dirPath - Directory path
   * @returns Array of child names (not full paths)
   */
  children(dirPath: string): string[];
  
  /**
   * List all changes made to the tree
   * @returns Array of file changes
   */
  listChanges(): FileChange[];
  
  /**
   * Change file permissions
   * @param filePath - Path to the file
   * @param mode - New file mode/permissions
   */
  changePermissions(filePath: string, mode: Mode): void;
}

/**
 * Represents a change to a file in the tree
 */
interface FileChange {
  /** Path to the changed file */
  path: string;
  /** Type of change */
  type: 'CREATE' | 'UPDATE' | 'DELETE';
  /** New content for CREATE/UPDATE operations */
  content?: Buffer;
}

/**
 * Options for writing files to the tree
 */
interface TreeWriteOptions {
  /** File permissions mode */
  mode?: Mode;
}

/**
 * File permission mode
 */
type Mode = string | number;

Usage Examples:

import { Tree } from "@nrwl/devkit";

function myGenerator(tree: Tree) {
  // Read an existing file
  const packageJson = tree.read('package.json', 'utf-8');
  if (packageJson) {
    const config = JSON.parse(packageJson);
    // Modify config...
  }
  
  // Write a new file
  tree.write('src/new-file.ts', `
    export const message = 'Hello World';
  `);
  
  // Check if file exists before reading
  if (tree.exists('tsconfig.json')) {
    const tsConfig = tree.read('tsconfig.json', 'utf-8');
    // Process tsconfig...
  }
  
  // List directory contents
  const srcFiles = tree.children('src');
  console.log('Files in src:', srcFiles);
  
  // Rename a file
  tree.rename('old-file.ts', 'new-file.ts');
  
  // Delete a file
  tree.delete('unwanted-file.ts');
}

File Globbing

Functions for finding files that match specific patterns.

/**
 * Find files matching a glob pattern synchronously
 * @param tree - Virtual file system tree
 * @param patterns - Glob patterns to match
 * @returns Array of matching file paths
 */
function glob(tree: Tree, patterns: string[]): string[];

/**
 * Find files matching a glob pattern asynchronously
 * @param tree - Virtual file system tree
 * @param patterns - Glob patterns to match
 * @returns Promise resolving to array of matching file paths
 */
function globAsync(tree: Tree, patterns: string[]): Promise<string[]>;

Usage Examples:

import { Tree, glob, globAsync } from "@nrwl/devkit";

function findFiles(tree: Tree) {
  // Find all TypeScript files
  const tsFiles = glob(tree, ['**/*.ts']);
  
  // Find test files
  const testFiles = glob(tree, ['**/*.spec.ts', '**/*.test.ts']);
  
  // Async globbing
  const jsFiles = await globAsync(tree, ['**/*.js', '**/*.jsx']);
}

File Visiting

Utility for applying operations to files while respecting ignore patterns.

/**
 * Visit all files that are not ignored by .gitignore patterns
 * @param tree - Virtual file system tree
 * @param dirPath - Directory to start from
 * @param callback - Function to call for each file
 */
function visitNotIgnoredFiles(
  tree: Tree,
  dirPath: string,
  callback: (path: string) => void
): void;

Usage Examples:

import { Tree, visitNotIgnoredFiles } from "@nrwl/devkit";

function processAllFiles(tree: Tree) {
  visitNotIgnoredFiles(tree, '.', (filePath) => {
    if (filePath.endsWith('.ts')) {
      const content = tree.read(filePath, 'utf-8');
      // Process TypeScript files...
    }
  });
}

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