guybedford / chomp

'JS Make' - parallel task runner for the frontend ecosystem with a JS extension system.
https://chompbuild.com
Apache License 2.0
138 stars 7 forks source link

env variables are spilled between tasks #127

Closed zachsa closed 2 years ago

zachsa commented 2 years ago

With an index.js file:

console.log(process.env.NODE_ENV)

This workflow

[[task]]
name = 'two'
deps = ['one']
run = "node index.js"

[[task]]
name = 'one'
template = 'jspm'
env = ['node', 'production', 'module']

The log is 'production'.

If I change task one: env = ['node', 'development', 'module'], then the log is 'development'.

Is this intentional? I was expecting that the 'two' task would have the default env rather than env variables specified for previous tasks. The specific case is that I want to generate 'production' import maps (I think this will get me production builds of all the libraries), but set my NODE_ENV variable to development for the server start

guybedford commented 2 years ago

I replicated this example with:

version = 0.1
extensions = ['chomp@0.1:jspm']

[[task]]
name = 'two'
deps = ['one']
run = 'node index.js'

[[task]]
name = 'one'
template = 'jspm'
dep = 'in.html'
target = 'out.html'
[task.template-options]
env = ['node', 'production', 'module']

But I get undefined in the log since there is nothing in any of the above that actually sets process.env.NODE_ENV.

I think you may be confusing env in JSPM generator and ENV in Chomp which are completely separate things.

In JSPM generator the development production conditions alter which modules are loaded. If index.js is relying on an import map itself then some dependency is likely writing process.env.NODE_ENV.

zachsa commented 2 years ago

Yes I was confused (and your task template env is correct). Since jspm wasn't using NODE_ENV I was getting mismatched import versions to my NODE_ENV if the second argument to jspm env didn't match how I was specifying NODE_ENV.

I think the issue with seeing 'production' without specifying a value was because I had previously specified that in my shell