(cwd: string)
| 11 | } |
| 12 | |
| 13 | function fixPackageJson(cwd: string): void { |
| 14 | const packageJsonPath = join(cwd, 'package.json'); |
| 15 | const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as { |
| 16 | dependencies?: Record<string, string>; |
| 17 | devDependencies?: Record<string, string>; |
| 18 | volta?: Record<string, unknown>; |
| 19 | }; |
| 20 | |
| 21 | // 1. Fix file dependencies |
| 22 | if (packageJson.dependencies) { |
| 23 | fixFileLinkDependencies(packageJson.dependencies); |
| 24 | } |
| 25 | if (packageJson.devDependencies) { |
| 26 | fixFileLinkDependencies(packageJson.devDependencies); |
| 27 | } |
| 28 | |
| 29 | // 2. Fix volta extends |
| 30 | if (!packageJson.volta) { |
| 31 | throw new Error("No volta config found, please add one to the test app's package.json!"); |
| 32 | } |
| 33 | |
| 34 | if (typeof packageJson.volta.extends === 'string') { |
| 35 | const extendsPath = packageJson.volta.extends; |
| 36 | // We add a virtual dir to ensure that the relative depth is consistent |
| 37 | // dirPath is relative to ./../test-applications/xxx |
| 38 | const newPath = resolve(__dirname, 'virtual-dir/', extendsPath); |
| 39 | packageJson.volta.extends = newPath; |
| 40 | console.log(`Fixed volta.extends to ${newPath}`); |
| 41 | } else { |
| 42 | console.log('No volta.extends found'); |
| 43 | } |
| 44 | |
| 45 | writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); |
| 46 | } |
| 47 | |
| 48 | // Exported for pnpmOverrides as well |
| 49 | export function fixFileLinkDependencies(dependencyObj: Record<string, string>): void { |
no test coverage detected