( cwd: string, scanRootOverrides?: string[], sharedLibOverrides?: string[], )
| 7 | const EXTERNAL_SHARED_LIBS = ['valdi_widgets']; |
| 8 | |
| 9 | export function resolveScanConfig( |
| 10 | cwd: string, |
| 11 | scanRootOverrides?: string[], |
| 12 | sharedLibOverrides?: string[], |
| 13 | ): ScanConfig { |
| 14 | if (scanRootOverrides && scanRootOverrides.length > 0) { |
| 15 | const resolvedRoots = scanRootOverrides.map(r => path.resolve(cwd, r)); |
| 16 | const libNames = sharedLibOverrides ?? EXTERNAL_SHARED_LIBS; |
| 17 | const libPaths = libNames.map(name => discoverSharedLibPath(cwd, resolvedRoots, name)); |
| 18 | return { |
| 19 | scanRoots: resolvedRoots, |
| 20 | sharedLibPaths: libPaths.filter((p): p is string => p !== undefined), |
| 21 | sharedLibNames: libNames, |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | const internalRoot = path.join(cwd, INTERNAL_SCAN_ROOT); |
| 26 | if (fs.existsSync(internalRoot)) { |
| 27 | const libNames = sharedLibOverrides ?? INTERNAL_SHARED_LIBS; |
| 28 | const libPaths = libNames.map(name => discoverSharedLibPath(cwd, [internalRoot], name)); |
| 29 | return { |
| 30 | scanRoots: [internalRoot], |
| 31 | sharedLibPaths: libPaths.filter((p): p is string => p !== undefined), |
| 32 | sharedLibNames: libNames, |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | const srcDir = path.join(cwd, 'src'); |
| 37 | if (fs.existsSync(srcDir)) { |
| 38 | const libNames = sharedLibOverrides ?? EXTERNAL_SHARED_LIBS; |
| 39 | const libPaths = libNames.map(name => discoverSharedLibPath(cwd, [srcDir], name)); |
| 40 | return { |
| 41 | scanRoots: [srcDir], |
| 42 | sharedLibPaths: libPaths.filter((p): p is string => p !== undefined), |
| 43 | sharedLibNames: libNames, |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | const libNames = sharedLibOverrides ?? EXTERNAL_SHARED_LIBS; |
| 48 | const libPaths = libNames.map(name => discoverSharedLibPath(cwd, [cwd], name)); |
| 49 | return { |
| 50 | scanRoots: [cwd], |
| 51 | sharedLibPaths: libPaths.filter((p): p is string => p !== undefined), |
| 52 | sharedLibNames: libNames, |
| 53 | }; |
| 54 | } |
| 55 | |
| 56 | function discoverSharedLibPath(workspaceRoot: string, scanRoots: string[], libName: string): string | undefined { |
| 57 | // 1. Direct child of a scan root |
no test coverage detected