|
9 | 9 | mergeJsonConfig, |
10 | 10 | rewriteScripts, |
11 | 11 | rewriteImport, |
| 12 | + rewriteImportsInDirectory, |
12 | 13 | type DownloadPackageManagerResult, |
13 | 14 | } from '../../binding/index.js'; |
14 | 15 | import { PackageManager, type WorkspaceInfo } from '../types/index.js'; |
@@ -131,6 +132,8 @@ export function rewriteStandaloneProject(projectPath: string, workspaceInfo: Wor |
131 | 132 | rewriteNpmrc(projectPath); |
132 | 133 | rewriteLintStagedConfigFile(projectPath); |
133 | 134 | rewriteViteConfigFile(projectPath); |
| 135 | + // rewrite imports in all TypeScript/JavaScript files |
| 136 | + rewriteAllImports(projectPath); |
134 | 137 | // set package manager |
135 | 138 | setPackageManager(projectPath, workspaceInfo.downloadPackageManager); |
136 | 139 | } |
@@ -160,6 +163,8 @@ export function rewriteMonorepo(workspaceInfo: WorkspaceInfo): void { |
160 | 163 | rewriteNpmrc(workspaceInfo.rootDir); |
161 | 164 | rewriteLintStagedConfigFile(workspaceInfo.rootDir); |
162 | 165 | rewriteViteConfigFile(workspaceInfo.rootDir); |
| 166 | + // rewrite imports in all TypeScript/JavaScript files |
| 167 | + rewriteAllImports(workspaceInfo.rootDir); |
163 | 168 | // set package manager |
164 | 169 | setPackageManager(workspaceInfo.rootDir, workspaceInfo.downloadPackageManager); |
165 | 170 | } |
@@ -623,6 +628,29 @@ function rewriteViteConfigImport(projectPath: string, viteConfigPath: string): v |
623 | 628 | } |
624 | 629 | } |
625 | 630 |
|
| 631 | +/** |
| 632 | + * Rewrite imports in all TypeScript/JavaScript files under a directory |
| 633 | + * This rewrites vite/vitest imports to @voidzero-dev/vite-plus |
| 634 | + * @param projectPath - The root directory to search for files |
| 635 | + */ |
| 636 | +function rewriteAllImports(projectPath: string): void { |
| 637 | + const result = rewriteImportsInDirectory(projectPath); |
| 638 | + |
| 639 | + if (result.modifiedFiles.length > 0) { |
| 640 | + prompts.log.success(`✅ Rewrote imports in ${result.modifiedFiles.length} file(s)`); |
| 641 | + for (const file of result.modifiedFiles) { |
| 642 | + prompts.log.info(` ${displayRelative(file)}`); |
| 643 | + } |
| 644 | + } |
| 645 | + |
| 646 | + if (result.errors.length > 0) { |
| 647 | + prompts.log.warn(`⚠️ ${result.errors.length} file(s) had errors:`); |
| 648 | + for (const error of result.errors) { |
| 649 | + prompts.log.error(` ${displayRelative(error.path)}: ${error.message}`); |
| 650 | + } |
| 651 | + } |
| 652 | +} |
| 653 | + |
626 | 654 | function setPackageManager( |
627 | 655 | projectDir: string, |
628 | 656 | downloadPackageManager: DownloadPackageManagerResult, |
|
0 commit comments