Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this work on windows? #238

Open
amitrai99 opened this issue Feb 19, 2021 · 7 comments
Open

Does this work on windows? #238

amitrai99 opened this issue Feb 19, 2021 · 7 comments

Comments

@amitrai99
Copy link

I tried the basic example in the README and cant get it to run on Windows 10. Does this support Windows?

@mvarendorff
Copy link

I am using env-cmd to run chromatic with the token defined in a .env file in the packages directory and it works without issues on my Windows 10 machine. Maybe a detailed error could help pinpoint the problem?

@phil-lgr
Copy link

phil-lgr commented Oct 5, 2021

On windows 10, running this:

env-cmd -x nr gatsby develop --verbose --port \$APP_PORT --host 0.0.0.0

should output:

env-cmd -x nr gatsby develop --verbose --port 9000 --host 0.0.0.0

but I get:

env-cmd -x nr gatsby develop --verbose --port \\$APP_PORT --host 0.0.0.0

I think env-cmd does not expand properly on powershell

@phil-lgr
Copy link

phil-lgr commented Oct 5, 2021

Simply doing:

    "start": "env-cmd -x nr gatsby develop --verbose --port $APP_PORT --host 0.0.0.0",

with no \\ work on powershell, but not on the mac terminal

There is something funny going on with \ on Windows and powershell

@phil-lgr
Copy link

phil-lgr commented Oct 5, 2021

Simpler test:

# on mac, works correctly
phil$ node_modules/.bin/env-cmd -x echo \$APP_PORT 
9000
# on windows, does not work
PS C:\Users\legep\> ..\..\node_modules\.bin\env-cmd -x echo \$APP_PORT 
"\\"

With verbose flag:

PS C:\Users\legep> ..\..\node_modules\.bin\env-cmd   --verbose  -x echo \$APP_PORT
Options: {"command":"echo","commandArgs":["\\"],"options":{"expandEnvs":true,"noOverride":false,"silent":false,"useShell":false,"verbose":true}}
Found .env file at default path: ./.env
"\\"
Child process exited with code: 0 and signal:. Terminating parent process...

@phil-lgr
Copy link

phil-lgr commented Oct 5, 2021

Potential fix for Windows, since \\$VAR does not get expanded like on unix:

diff --git a/node_modules/env-cmd/dist/expand-envs.js b/node_modules/env-cmd/dist/expand-envs.js
index b46324a..576a651 100644
--- a/node_modules/env-cmd/dist/expand-envs.js
+++ b/node_modules/env-cmd/dist/expand-envs.js
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
  * the environment variable doesn't exist, it leaves it as is.
 */
 function expandEnvs(str, envs) {
-    return str.replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, varName => {
+    return str.replace('\\$', '$').replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, varName => {
         const varValue = envs[varName.slice(1)];
         return varValue === undefined ? varName : varValue;
     });

Let me know if this makes sense, I could open a PR

@toddbluhm

@phil-lgr
Copy link

phil-lgr commented Oct 5, 2021

if you want to add windows to your actions:

jobs:
  build-test:
    runs-on: ${{ matrix.os }}
    strategy:
        fail-fast: false
        matrix:
            os: [ubuntu-latest, windows-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v2

@TomasMorton
Copy link

Thanks for the patch @phil-lgr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants