MCPcopy Create free account
hub / github.com/vercel/vercel / validateEnvConfig

Method validateEnvConfig

packages/cli/src/util/dev/server.ts:928–968  ·  view source on GitHub ↗
(type: string, env: Env = {}, localEnv: Env = {})

Source from the content-addressed store, hash-verified

926 }
927
928 validateEnvConfig(type: string, env: Env = {}, localEnv: Env = {}): Env {
929 // Validate if there are any missing env vars defined in `vercel.json`,
930 // but not in the `.env` / `.build.env` file
931 const missing: string[] = Object.entries(env)
932 .filter(
933 ([name, value]) =>
934 typeof value === 'string' &&
935 value.startsWith('@') &&
936 !hasProp(localEnv, name)
937 )
938 .map(([name]) => name);
939
940 if (missing.length > 0) {
941 throw new MissingDotenvVarsError(type, missing);
942 }
943
944 const merged: Env = { ...env, ...localEnv };
945
946 // Validate that the env var name satisfies what Vercel's platform accepts.
947 let hasInvalidName = false;
948 for (const key of Object.keys(merged)) {
949 if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key)) {
950 output.warn(
951 `Ignoring ${type
952 .split('.')
953 .slice(1)
954 .reverse()
955 .join(' ')} var ${JSON.stringify(key)} because name is invalid`
956 );
957 hasInvalidName = true;
958 delete merged[key];
959 }
960 }
961 if (hasInvalidName) {
962 output.log(
963 'The name contains invalid characters. Only letters, digits, and underscores are allowed. Furthermore, the name should not start with a digit'
964 );
965 }
966
967 return merged;
968 }
969
970 injectSystemValuesInDotenv(env: Env): Env {
971 for (const name of Object.keys(env)) {

Callers 1

getLocalEnvMethod · 0.95

Calls 8

filterMethod · 0.80
testMethod · 0.80
reverseMethod · 0.80
splitMethod · 0.80
hasPropFunction · 0.70
keysMethod · 0.45
joinMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected