-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
CLI: Fix throwing in readonly environments #31785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,24 @@ export const stringifyProcessEnvs = (raw: Record<string, string>): Record<string | |
// envs['process.env'] = JSON.stringify(raw); | ||
return envs; | ||
}; | ||
|
||
export const optionalEnvToBoolean = (input: string | undefined): boolean | undefined => { | ||
if (input === undefined) { | ||
return undefined; | ||
} | ||
if (input.toUpperCase() === 'FALSE' || input === '0') { | ||
return false; | ||
} | ||
if (input.toUpperCase() === 'TRUE' || input === '1') { | ||
return true; | ||
} | ||
return Boolean(input); | ||
}; | ||
|
||
/** | ||
* Consistently determine if we are in a CI environment | ||
* | ||
* Doing Boolean(process.env.CI) or !process.env.CI is not enough, because users might set CI=false | ||
* or CI=0, which would be truthy, and thus return true in those cases. | ||
*/ | ||
export const isCI = optionalEnvToBoolean(process.env.CI); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it OK for this file to read There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant right.. do we think it's better for brevity? Should this function be unit tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm you mean that the strings
'TRUE'
and'1'
are truthy anyways, soBoolean(input)
would returntrue
anyway? I hadn't thought of that. I should remove it, that should also make it more obvious that'blah'
also makes ittrue
.I can add tests.