Skip to content
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

[heft] set-environment-variables-plugin variables remain set in unrelated phases #4661

Open
D4N14L opened this issue Apr 19, 2024 · 0 comments
Labels
effort: easy Probably a quick fix. Want to contribute? :-) enhancement The issue is asking for a new feature or design change help wanted If you're looking to contribute, this issue is a good place to start!

Comments

@D4N14L
Copy link
Member

D4N14L commented Apr 19, 2024

Summary

The @rushstack/heft plugin set-environment-variables-plugin sets the environment variable for the entire Heft process, not just the currently running phase. Since it is a taskPlugin, ideally it should only impact the phase that the plugin is declared in. However, since it sets the value on the process.env, it impacts other Heft phases that are running in parallel, and also remains set for downstream phases.

Repro steps

  • Add the set-environment-variables-plugin task plugin to a phase and set some environment variable

  • Observe the environment variable value in depending phases, or phases that run in parallel

    Expected result: The environment variable does not exist in parallel or downstream phases

    Actual result: Phases or tasks that run after the execution of the task containing the plugin have the environment variable set, regardless of phase

Details

This is caused because there is no process isolation in Heft at the phase level, so any environment variables set by the plugin will apply to all other tasks. There are a couple options here:

  • Implement phase-level process isolation in Heft. This could also have some other benefits in terms of parallelism on multi-core machines, but would be impacted by having to reload all imports in each new process due to missing the node_modules require cache. This is essentially how Rush executes our Heft-based phases in the Rushstack repo already, but would also now do it internal when running Heft
  • Make the set-environment-variables-plugin into a lifecyclePlugin, so that it's implicit that the environment variable should be set on all phases. However, this removes some of the more targeting utility of the plugin if left as a taskPlugin

Ideally, both of the above suggestions could be implemented, allowing the plugin to be both a lifecyclePlugin and a taskPlugin for increased utility, while also introducing phase-level process isolation.

@D4N14L D4N14L changed the title [heft] set-environment-variables-plugin remains set in unrelated phases [heft] set-environment-variables-plugin variables remain set in unrelated phases Apr 19, 2024
@iclanton iclanton added enhancement The issue is asking for a new feature or design change help wanted If you're looking to contribute, this issue is a good place to start! effort: easy Probably a quick fix. Want to contribute? :-) labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: easy Probably a quick fix. Want to contribute? :-) enhancement The issue is asking for a new feature or design change help wanted If you're looking to contribute, this issue is a good place to start!
Projects
Status: Low priority
Development

No branches or pull requests

2 participants