kdreact-migrate
Version:
CLI tool to migrate React applications from version 16 to newer versions (17, 18, 19)
229 lines • 7.43 kB
TypeScript
#!/usr/bin/env node
/**
* Interface for migration options
*/
interface MigrationOptions {
dryRun?: boolean;
verbose?: boolean;
skipDeps?: boolean;
depsOnly?: boolean;
files?: string;
components?: string;
createBackup?: boolean;
}
/**
* Interface for backup information
*/
interface BackupInfo {
id: string;
timestamp: string;
path: string;
description: string;
}
/**
* CLI tool to migrate React applications to newer versions (17, 18, 19).
*
* @remarks
* This tool analyzes your React project, updates dependencies, transforms code, and provides a migration report.
*/
export declare class ReactMigrationTool {
/** The target React version for migration. */
targetVersion: string;
/** The root directory of the project being migrated. */
projectRoot: string;
/** List of issues found during migration. */
issues: string[];
/** List of fixes applied during migration. */
fixes: string[];
/** React files found in the project. */
reactFiles: string[];
/** Migration options. */
options: MigrationOptions;
/** Backup information. */
backupInfo?: BackupInfo;
/**
* Starts the migration process.
* @param targetVersion The React version to migrate to.
* @param projectPath The path to the React project.
* @param options Migration options.
*/
migrate(targetVersion: string, projectPath?: string, options?: MigrationOptions): Promise<void>;
/**
* Creates a backup of the project before migration.
*/
createBackup(): Promise<void>;
/**
* Copies a directory recursively.
* @param src Source directory path.
* @param dest Destination directory path.
*/
private copyDirectory;
/**
* Rolls back to a specific backup.
* @param backupId The backup ID to rollback to.
*/
rollback(backupId: string): Promise<void>;
/**
* Lists available backups.
*/
listBackups(): BackupInfo[];
/**
* Analyzes the project structure and finds React files.
*/
analyzeProject(): Promise<void>;
/**
* Finds React files in the project.
*/
findReactFiles(): void;
/**
* Recursively gets React files from a directory.
* @param dir The directory to search.
* @returns Array of React file paths.
*/
getReactFiles(dir: string): string[];
/**
* Updates dependencies in package.json.
*/
updateDependencies(): Promise<void>;
/**
* Analyzes peer dependencies for potential conflicts.
* @param packageJson The package.json object.
*/
analyzePeerDependencies(packageJson: any): Promise<void>;
/**
* Checks if two version ranges are compatible.
* @param version1 First version range.
* @param version2 Second version range.
* @returns True if versions are compatible.
*/
private isVersionCompatible;
/**
* Gets React-related packages with version mappings.
* @returns Object mapping package names to versions.
*/
getReactRelatedPackages(): Record<string, string>;
/**
* Transforms React code files.
*/
transformCode(): Promise<void>;
/**
* Transforms a single React file.
* @param filePath Path to the file to transform.
*/
transformFile(filePath: string): Promise<void>;
/**
* Transforms ReactDOM.render to createRoot API.
* @param content File content to transform.
* @param fileName Name of the file being transformed.
* @returns Transformed content.
*/
transformReactDOMRender(content: string, fileName: string): string;
/**
* Transforms deprecated lifecycle methods.
* @param content File content to transform.
* @param fileName Name of the file being transformed.
* @returns Transformed content.
*/
transformLifecycleMethods(content: string, fileName: string): string;
/**
* Transforms event handlers for React 17+.
* @param content File content to transform.
* @param fileName Name of the file being transformed.
* @returns Transformed content.
*/
transformEventHandlers(content: string, fileName: string): string;
/**
* Transforms PropTypes imports.
* @param content File content to transform.
* @param fileName Name of the file being transformed.
* @returns Transformed content.
*/
transformPropTypes(content: string, fileName: string): string;
/**
* Transforms React.FC usage.
* @param content File content to transform.
* @param fileName Name of the file being transformed.
* @returns Transformed content.
*/
transformReactFC(content: string, fileName: string): string;
/**
* Transforms simple class components to functional components.
* @param content File content to transform.
* @param fileName Name of the file being transformed.
* @returns Transformed content.
*/
transformClassToFunctional(content: string, fileName: string): string;
/**
* Updates configuration files.
*/
updateConfiguration(): Promise<void>;
/**
* Updates TypeScript configuration.
* @param tsConfigPath Path to tsconfig.json.
*/
updateTsConfig(tsConfigPath: string): void;
/**
* Updates Jest configuration.
* @param jestConfigPath Path to jest.config.js.
*/
updateJestConfig(jestConfigPath: string): void;
/**
* Updates ESLint configuration.
* @param eslintConfigPath Path to .eslintrc.js.
*/
updateEslintConfig(eslintConfigPath: string): void;
/**
* Checks Babel configuration.
*/
checkBabelConfig(): void;
/**
* Checks Webpack configuration.
*/
checkWebpackConfig(): void;
/**
* Generates the migration report.
*/
generateReport(): void;
getTestingLibraryVersion(): string;
getTypesVersion(): string;
getReactRouterVersion(): string;
getReactScriptsVersion(): string;
getReactReduxVersion(): string;
getReduxToolkitVersion(): string;
getReactHookFormVersion(): string;
getFormikVersion(): string;
getStyledComponentsVersion(): string;
getEmotionVersion(): string;
getReactTransitionGroupVersion(): string;
getReactSelectVersion(): string;
getReactDatepickerVersion(): string;
getReactModalVersion(): string;
getReactHelmetVersion(): string;
getReactHelmetAsyncVersion(): string;
getReactVirtualizedVersion(): string;
getReactWindowVersion(): string;
getReactDndVersion(): string;
getReactBeautifulDndVersion(): string;
getReactDropzoneVersion(): string;
getReactTableVersion(): string;
getTanstackReactTableVersion(): string;
getReactQueryVersion(): string;
getTanstackReactQueryVersion(): string;
getReactSpringVersion(): string;
getFramerMotionVersion(): string;
getReactIntlVersion(): string;
getReactI18nextVersion(): string;
getNextVersion(): string;
getGatsbyVersion(): string;
getReactHotToastVersion(): string;
getReactToastifyVersion(): string;
getReactIconsVersion(): string;
getReactUseVersion(): string;
getReactErrorBoundaryVersion(): string;
getReactLoadableVersion(): string;
getLoadableComponentVersion(): string;
getReactLazyloadVersion(): string;
getReactIntersectionObserverVersion(): string;
}
export {};
//# sourceMappingURL=index.d.ts.map