[heft] set-environment-variables-plugin
variables remain set in unrelated phases
#4661
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!
Summary
The
@rushstack/heft
pluginset-environment-variables-plugin
sets the environment variable for the entire Heft process, not just the currently running phase. Since it is ataskPlugin
, ideally it should only impact the phase that the plugin is declared in. However, since it sets the value on theprocess.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 variableObserve 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:
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 Heftset-environment-variables-plugin
into alifecyclePlugin
, 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 ataskPlugin
Ideally, both of the above suggestions could be implemented, allowing the plugin to be both a
lifecyclePlugin
and ataskPlugin
for increased utility, while also introducing phase-level process isolation.The text was updated successfully, but these errors were encountered: