|
1 | 1 | /* eslint-disable no-console */ |
2 | 2 | import { readFileSync, writeFileSync } from 'fs'; |
3 | 3 | import { cp } from 'fs/promises'; |
4 | | -import { join } from 'path'; |
| 4 | +import { isAbsolute, join } from 'path'; |
5 | 5 |
|
6 | 6 | export async function copyToTemp(originalPath: string, tmpDirPath: string): Promise<void> { |
7 | 7 | // copy files to tmp dir |
@@ -47,15 +47,22 @@ function fixPackageJson(cwd: string): void { |
47 | 47 |
|
48 | 48 | function fixFileLinkDependencies(dependencyObj: Record<string, string>): void { |
49 | 49 | for (const [key, value] of Object.entries(dependencyObj)) { |
50 | | - if (value.startsWith('link:')) { |
51 | | - const dirPath = value.replace('link:', ''); |
52 | | - |
53 | | - // We add a virtual dir to ensure that the relative depth is consistent |
54 | | - // dirPath is relative to ./../test-applications/xxx |
55 | | - const newPath = join(__dirname, 'virtual-dir/', dirPath); |
| 50 | + const prefix = value.startsWith('link:') ? 'link:' : value.startsWith('file:') ? 'file:' : null; |
| 51 | + if (!prefix) { |
| 52 | + continue; |
| 53 | + } |
56 | 54 |
|
57 | | - dependencyObj[key] = `link:${newPath}`; |
58 | | - console.log(`Fixed ${key} dependency to ${newPath}`); |
| 55 | + const dirPath = value.slice(prefix.length); |
| 56 | + if (isAbsolute(dirPath)) { |
| 57 | + continue; |
59 | 58 | } |
| 59 | + |
| 60 | + // We add a virtual dir to ensure that the relative depth is consistent |
| 61 | + // dirPath is relative to ./../test-applications/xxx |
| 62 | + const newPath = join(__dirname, 'virtual-dir/', dirPath); |
| 63 | + console.log({ key, value, newPath }); |
| 64 | + |
| 65 | + dependencyObj[key] = `${prefix}${newPath}`; |
| 66 | + console.log(`Fixed ${key} dependency to ${newPath}`); |
60 | 67 | } |
61 | 68 | } |
0 commit comments