-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overrides.ts
36 lines (30 loc) · 926 Bytes
/
overrides.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* A tree map to match service names to
* their overridden values at run/build time
*/
export type Overrides = { [key: string]: Overrides | string };
export const OVERRIDES = '$overrides';
export function pickOverridenName(
overrides: Overrides,
servicesNames: [...string[], string],
) {
const servicesDepth = servicesNames.length;
for (let i = 0; i < servicesDepth; i++) {
let currentDepth = i;
let currentOverrides = overrides;
while (currentDepth < servicesDepth) {
const candidateOverride = currentOverrides[servicesNames[currentDepth]];
if (typeof candidateOverride === 'string') {
if (currentDepth === servicesDepth - 1) {
return candidateOverride;
}
} else if (candidateOverride) {
currentOverrides = candidateOverride;
} else {
break;
}
currentDepth++;
}
}
return servicesNames[servicesDepth - 1];
}