Skip to content

deep merge spawnOptions.env with kernelSpec.env #40

Open
@haraldschilly

Description

@haraldschilly

This ticket is about refining the behavior for setting the environment of a newly started kernel. Right now, as it can be seen in this code reference the various options are shallow-merged. I.e. if there is a kernel-configured environment and a custom one passed in via the spawnOptions object, spawnOptions.env overwrites everything.

My idea about this is -- at least optionally, such that existing behavior isn't broken -- to merge these env configurations before they're passed to execa, i.e. a "deeper merge". In particular, this would allow to overwrite a single environment variable from the kernel config file, while the other ones are kept as they are. I'm for example thinking about a case, where variables like LD_LIBRARY_PATH and PATH are configured in the kernel, but I want to tweak PATH via spawnOptions and keep LD_LIBRARY_PATH as it is.

Since at least I find this confusing, I'm just clarifying this by an example:

> env = { PATH : 1, VAR : 2}
{ PATH: 1, VAR: 2 }
> spawnOptions = {env : { PATH : 3}}
{ env: { PATH: 3 } }
> Object.assign({} , {env : env} , spawnOptions)
{ env: { PATH: 3 } }                  // VAR:2 gone!

merging env one level deeper preserves VAR

> Object.assign({}, env, spawnOptions.env)
{ PATH: 3, VAR: 2 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions