-
Notifications
You must be signed in to change notification settings - Fork 11.9k
refactor(@angular/cli): centralize environment variable parsing #30825
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
Conversation
b0db906
to
8ac9cb6
Compare
Refactors the environment options utility to improve maintainability and clarity. This change introduces a centralized `parseTristate` function to handle all boolean-like parsing from environment variables, removing the previous `isEnabled`, `isDisabled`, and `optional` helpers.
8ac9cb6
to
2a7abfa
Compare
return false; | ||
} | ||
|
||
return undefined; | ||
} |
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.
Consider: Could we remove the "tristate" concept by just providing a default value like parseEnvBoolean(process.env['FOO'], true /* default */)
?
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.
Some of them don't have constant defaults. The third "not present" state is relevant downstream for them.
export const ngDebug = isEnabled(process.env['NG_DEBUG']); | ||
export const forceAutocomplete = optional(process.env['NG_FORCE_AUTOCOMPLETE']); | ||
/** Disables all analytics reporting when the `NG_CLI_ANALYTICS` environment variable is set to '0' or 'false'. */ | ||
export const analyticsDisabled = parseTristate(process.env['NG_CLI_ANALYTICS']) === false; |
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.
Consider: Would it make more sense to frame these in the positive and then fall back to a default value with ??
rather than check equality with a specific boolean? I feel analyticsEnabled = parseTristate(...) ?? true
would be more intuitive to me at least.
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 one is more of "force analytics disabled" and analytics being enabled involves further logic. There is potential to further refactor the usages and adjust the naming but i wanted to avoid usage changes where possible here.
Refactors the environment options utility to improve maintainability and clarity. This change introduces a centralized
parseTristate
function to handle all boolean-like parsing from environment variables, removing the previousisEnabled
,isDisabled
, andoptional
helpers.