Skip to content

Commit 10affc4

Browse files
committed
Ignore built-in env vars when checking for env vars, and allow continuing the deployment even if missing env vars were detected
1 parent 226805c commit 10affc4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

packages/cli-v3/src/commands/deploy.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { Glob } from "glob";
4848
const DeployCommandOptions = CommonCommandOptions.extend({
4949
skipTypecheck: z.boolean().default(false),
5050
skipDeploy: z.boolean().default(false),
51+
ignoreEnvVarCheck: z.boolean().default(false),
5152
env: z.enum(["prod", "staging"]),
5253
loadImage: z.boolean().default(false),
5354
buildPlatform: z.enum(["linux/amd64", "linux/arm64"]).default("linux/amd64"),
@@ -73,7 +74,11 @@ export function configureDeployCommand(program: Command) {
7374
"Deploy to a specific environment (currently only prod and staging are supported)",
7475
"prod"
7576
)
76-
.option("-T, --skip-typecheck", "Whether to skip the pre-build typecheck")
77+
.option("--skip-typecheck", "Whether to skip the pre-build typecheck")
78+
.option(
79+
"--ignore-env-var-check",
80+
"Detected missing environment variables won't block deployment"
81+
)
7782
.option("-c, --config <config file>", "The name of the config file, found at [path]")
7883
.option(
7984
"-p, --project-ref <project ref>",
@@ -425,7 +430,11 @@ async function checkEnvVars(
425430
environmentVariablesSpinner.stop(
426431
`Found missing env vars in ${options.env}: ${arrayToSentence(
427432
missingEnvironmentVariables
428-
)}. Aborting deployment. ${chalk.bgBlueBright(
433+
)}. ${
434+
options.ignoreEnvVarCheck
435+
? "Continuing deployment because of --ignore-env-var-check. "
436+
: "Aborting deployment. "
437+
}${chalk.bgBlueBright(
429438
terminalLink(
430439
"Manage env vars",
431440
`${apiUrl}/projects/v3/${config.project}/environment-variables`
@@ -437,7 +446,12 @@ async function checkEnvVars(
437446
"envVars.missing": missingEnvironmentVariables,
438447
});
439448

440-
throw new SkipLoggingError("Found missing environment variables");
449+
if (!options.ignoreEnvVarCheck) {
450+
throw new SkipLoggingError("Found missing environment variables");
451+
} else {
452+
span.end();
453+
return;
454+
}
441455
}
442456

443457
environmentVariablesSpinner.stop(`Environment variable check passed`);
@@ -1309,15 +1323,19 @@ async function findAllEnvironmentVariableReferencesInFile(filePath: string) {
13091323
return findAllEnvironmentVariableReferences(fileContents);
13101324
}
13111325

1326+
const IGNORED_ENV_VARS = ["NODE_ENV", "SHELL", "HOME", "PWD", "LOGNAME", "USER", "PATH"];
1327+
13121328
function findAllEnvironmentVariableReferences(code: string): string[] {
13131329
const regex = /\bprocess\.env\.([a-zA-Z_][a-zA-Z0-9_]*)\b/g;
13141330

13151331
const matches = code.matchAll(regex);
13161332

13171333
const matchesArray = Array.from(matches, (match) => match[1]).filter(Boolean) as string[];
13181334

1335+
const filteredMatches = matchesArray.filter((match) => !IGNORED_ENV_VARS.includes(match));
1336+
13191337
// Make sure and remove duplicates
1320-
return Array.from(new Set(matchesArray));
1338+
return Array.from(new Set(filteredMatches));
13211339
}
13221340

13231341
function arrayToSentence(items: string[]): string {

0 commit comments

Comments
 (0)