kentcdodds / cross-env

🔀 Cross platform setting of environment scripts
https://www.npmjs.com/package/cross-env
MIT License
6.32k stars 243 forks source link

PATH variable replacement on Windows envirement #216

Closed aberkovsky closed 3 years ago

aberkovsky commented 5 years ago

Relevant code or config

"test": "cross-env-shell PATH=\"../node_modules/.bin:$PATH\" echo $PATH"

What you did: Im try to add to PATH environment variable the parent .bin directory

What happened: 'echo' printed all paths, but wihtout my

Problem description: Problem in the name of 'PATH' variable in Windows envirement, it has lower case 'Path' Line below was fine "test": "cross-env-shell Path=\"../node_modules/.bin:$Path\" echo $Path"

Suggested solution: Use the 'path-key' module for PATH variable replacement.

kentcdodds commented 5 years ago

Yes, this is an interesting problem. I think it's a worthwhile feature, so I'd be happy to accept a pull request for this. Would you be willing to implement that? I'm not sure we need to use path-key because the code will literally just be: const pathKey = isWindows ? 'Path' : 'PATH' (thanks to https://github.com/kentcdodds/cross-env/blob/master/src/is-windows.js).

Would you be interested in implementing this?

aberkovsky commented 5 years ago

The problem was deeper...

On Windows operating systems, environment variables are case-insensitive. However, if when you spawn a new process and pass the env with two variables (PATH and Path), in this new process process.env will contains both variables, and this breaks the subsequent logic.

Npm has logic to set both Path and PATH (if exist) variables on Windows, and by default used Path on Windows. But if I use cgwin terminal on Windows for example, process.env contains PATH.

kentcdodds commented 3 years ago

https://github.com/kentcdodds/cross-env/issues/257