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

Processing variables on MacOS 10.15.2 only works with single quotes #222

Closed mansn closed 3 years ago

mansn commented 4 years ago

npm run greet See what gets echoed.

This is what I see:

MacOS 10.15.2 Expected(?) Comment
unquoted unquoted Hi Joe
doubleQuotes doubleQuotes Hi Joe I guess this is actually the expected result atm?
singleQuotes Hi Joe singleQuotes Hi Joe

Unfortunately I cannot verify the behavior on Windows.

Problem description: This problem is pretty much the same as described in #148. The README.md example shows that you should wrap commands in (double) quotes ("\) if you want environment variable(s) to apply to a series of commands: https://github.com/kentcdodds/cross-env#cross-env-vs-cross-env-shell. But this example doesn't work on MacOS 10.15.2.

Suggested solution: Unfortunately I haven't had the time to dig into the codebase to propose a solution, other than that "it should work with double qoutes".

danielo515 commented 4 years ago

I am also facing this exact problem. You found any workaround?

mansn commented 4 years ago

@danielo515 No, not really any workaround. I mean, I use single quotes, but then the npm script won't work on Windows.. Maybe asking Windows users to switch script-shell to powershell could work for them? I.e. by following these guidelines, and then just use single quotes.

dwiyatci commented 3 years ago

@danielo515 @mansn How bout this pattern below? 👇

"greetDriver": "cross-env GREETING=Hi NAME=Joe npm run greet",
"greet": "npm run greet0 && npm run greet1 && npm run greet2",
"greet0": "cross-env-shell echo unquoted $GREETING $NAME",
"greet1": "cross-env-shell \"echo doubleQuotes $GREETING $NAME\"",
"greet2": "cross-env-shell 'echo singleQuotes $GREETING $NAME'" 

...and then npm run greetDriver or yarn greetDriver should do the job. 😃✨

kentcdodds commented 3 years ago

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