Skip to content

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

Merged
merged 1 commit into from
Aug 4, 2025

Conversation

clydin
Copy link
Member

@clydin clydin commented Aug 1, 2025

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.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Aug 1, 2025
@clydin clydin force-pushed the cli/env-vars-cleanup branch from b0db906 to 8ac9cb6 Compare August 1, 2025 17:49
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.
@clydin clydin force-pushed the cli/env-vars-cleanup branch from 8ac9cb6 to 2a7abfa Compare August 1, 2025 17:50
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 1, 2025
@clydin clydin requested a review from dgp1130 August 1, 2025 21:23
return false;
}

return undefined;
}
Copy link
Collaborator

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 */)?

Copy link
Member Author

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;
Copy link
Collaborator

@dgp1130 dgp1130 Aug 1, 2025

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.

Copy link
Member Author

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.

@clydin clydin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 4, 2025
@clydin clydin merged commit b6b2578 into angular:main Aug 4, 2025
31 checks passed
@clydin clydin deleted the cli/env-vars-cleanup branch August 4, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/cli target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants