Skip to content

Commit 54d7333

Browse files
rubennortefacebook-github-bot
authored andcommitted
Add validation for environment variables for Fantom (#52779)
Summary: Pull Request resolved: #52779 Changelog: [internal] Adds validation for Fantom environment variables at runtime, to catch typos or variables that no longer have an effect. Reviewed By: rshest Differential Revision: D78803045 fbshipit-source-id: efb28a4f3fd6a4be35fb525d91fb093a1e88f7e4
1 parent 3c087fc commit 54d7333

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

private/react-native-fantom/runner/EnvironmentOptions.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
* @format
99
*/
1010

11+
const VALID_ENVIRONMENT_VARIABLES = [
12+
'FANTOM_DEBUG_CPP',
13+
'FANTOM_ENABLE_CPP_DEBUGGING',
14+
'FANTOM_FORCE_CI_MODE',
15+
'FANTOM_FORCE_OSS_BUILD',
16+
'FANTOM_FORCE_TEST_MODE',
17+
'FANTOM_LOG_COMMANDS',
18+
'FANTOM_PRINT_OUTPUT',
19+
];
20+
1121
/**
1222
* Prints the output of the Fantom tester to the test output.
1323
*/
@@ -49,3 +59,20 @@ export const isCI: boolean =
4959
export const forceTestModeForBenchmarks: boolean = Boolean(
5060
process.env.FANTOM_FORCE_TEST_MODE,
5161
);
62+
63+
/**
64+
* Throws an error if there is an environment variable defined with the FANTOM_
65+
* prefix that is not recognized.
66+
*/
67+
export function validateEnvironmentVariables(): void {
68+
for (const key of Object.keys(process.env)) {
69+
if (
70+
key.startsWith('FANTOM_') &&
71+
!VALID_ENVIRONMENT_VARIABLES.includes(key)
72+
) {
73+
throw new Error(
74+
`Unexpected Fantom environment variable: ${key}=${String(process.env[key])}. Accepted variables are: ${VALID_ENVIRONMENT_VARIABLES.join(', ')}`,
75+
);
76+
}
77+
}
78+
}

private/react-native-fantom/runner/global-setup/globalSetup.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
* @format
99
*/
1010

11-
import {isOSS} from '../EnvironmentOptions';
11+
import {isOSS, validateEnvironmentVariables} from '../EnvironmentOptions';
1212
import build from './build';
1313

1414
export default async function globalSetup(
1515
globalConfig: {...},
1616
projectConfig: {...},
1717
): Promise<void> {
18+
validateEnvironmentVariables();
19+
1820
if (!isOSS) {
1921
await build();
2022
}

0 commit comments

Comments
 (0)