UNPKG

@nxworker/workspace

Version:

Nx plugin providing generators for managing workspace files, including the move-file generator for safely moving files between projects while updating all imports

55 lines (54 loc) 2.38 kB
import { Tree } from '@nx/devkit'; /** * Updates import specifiers in a file using jscodeshift. * * @param tree - The virtual file system tree * @param filePath - Path to the file to update * @param oldSpecifier - The old import specifier to replace * @param newSpecifier - The new import specifier * @returns True if changes were made */ export declare function updateImportSpecifier(tree: Tree, filePath: string, oldSpecifier: string, newSpecifier: string): boolean; /** * Updates import specifiers that match a pattern in a file using jscodeshift. * This is optimized to do a single AST traversal instead of multiple find() calls. * * @param tree - The virtual file system tree * @param filePath - Path to the file to update * @param matcher - Function to test if an import specifier should be updated * @param getNewSpecifier - Function to get the new specifier from the old one * @returns True if changes were made */ export declare function updateImportSpecifierPattern(tree: Tree, filePath: string, matcher: (specifier: string) => boolean, getNewSpecifier: (oldSpecifier: string) => string): boolean; /** * Checks if a file contains imports matching a given specifier. * Optimized with early exits to avoid expensive parsing when possible. * * @param tree - The virtual file system tree * @param filePath - Path to the file to check * @param specifier - The import specifier to search for * @returns True if the file contains imports with the given specifier */ export declare function hasImportSpecifier(tree: Tree, filePath: string, specifier: string): boolean; /** * Checks if a file has an import matching a predicate function. * * @param tree - The virtual file system tree * @param filePath - Path to the file to check * @param matcher - Predicate function to test import specifiers * @returns True if any import matches the predicate */ export declare function hasImportSpecifierMatching(tree: Tree, filePath: string, matcher: (specifier: string) => boolean): boolean; /** * Clears all cached ASTs and content. Should be called at the start of each move operation * to ensure a clean state. */ export declare function clearCache(): void; /** * Gets cache statistics for monitoring/debugging. */ export declare function getCacheStats(): { contentCacheSize: number; astCacheSize: number; failedParseCount: number; };