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

No cross-platform way of setting environment values containing spaces #248

Closed ed-graham closed 3 years ago

ed-graham commented 4 years ago

Relevant code or config:

{
  "scripts": {
    "worksOnWin": "cross-env AUTHORIZER={\\\"claims\\\":{\\\"permissions\\\":\\\"\"[view:accounts manage:accounts]\"\\\",\\\"sub\\\":\\\"auth0|5cfe0adce3c4c50ea072ea9f\\\"}} AWS_PROFILE=elit_nonprd npm run env",
    "worksOnNix": "cross-env AUTHORIZER=\"{\\\"claims\\\":{\\\"permissions\\\":\\\"[view:accounts manage:accounts]\\\",\\\"sub\\\":\\\"auth0|5cfe0adce3c4c50ea072ea9f\\\"}}\" AWS_PROFILE=elit_nonprd npm run env",
}

What you did: I tried to create a single npm script that would set an environment variable called AUTHORIZER (needed when running an AWS Serverless app in offline mode) that took a value containing a space (here an array of permissions). The intended result is that the environment variable AUTHORIZER takes the following value:

{
  "claims":
  {
    "permissions": "[view:accounts manage:accounts]",
    "sub": "auth0|5cfe0adce3c4c50ea072ea9f"
  }
}

The best I could manage (with help from the Stack Overflow community) was the two platform-specific scripts above.

What happened: I failed to write a single script for both Windows and Nix platforms and instead had to ditch cross-env altogether and resort to writing custom JavaScript code. See this issue on Stack Overflow. Trying to run the Nix script on Windows gives the error The system cannot find the path specified..

Reproduction repository:

None.

Problem description:

There appears to be a bug in cross-env when setting environment variables that take values containing spaces.

Suggested solution:

None.

kentcdodds commented 3 years ago

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