MCPcopy Create free account
hub / github.com/Snapchat/Valdi / resolveScanConfig

Function resolveScanConfig

npm_modules/cli/src/core/analyze/scanner.ts:9–54  ·  view source on GitHub ↗
(
  cwd: string,
  scanRootOverrides?: string[],
  sharedLibOverrides?: string[],
)

Source from the content-addressed store, hash-verified

7const EXTERNAL_SHARED_LIBS = ['valdi_widgets'];
8
9export 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
56function discoverSharedLibPath(workspaceRoot: string, scanRoots: string[], libName: string): string | undefined {
57 // 1. Direct child of a scan root

Callers 1

analyzeDuplicatesFunction · 0.90

Calls 5

discoverSharedLibPathFunction · 0.85
filterMethod · 0.80
resolveMethod · 0.65
mapMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected