Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Handle platform-specific list delimiters #80

Closed
DanReyLop opened this issue Mar 5, 2017 · 5 comments
Closed

Handle platform-specific list delimiters #80

DanReyLop opened this issue Mar 5, 2017 · 5 comments

Comments

@DanReyLop
Copy link
Contributor

For more context: elijahmanor/cross-var#3

Variables like $PATH or $NODE_PATH contain lists of items that are separated by ; in Windows and : in Unix. If would be good if cross-env handled this transparently.

Previous proposed solution: $: is converted to : on Unix, ; on Windows.
Example:

  • Input: PATH=$PATH$:lib npm start
  • Output (Win): PATH=%PATH%;lib npm start
  • Output (Unix): PATH=$PATH:lib npm start

The drawback is that syntax is a bit confusing, it looks like the variable is $PATH$.

Alternate solution: : in the value of a variable is converted to ; on Windows, ; is converted to : on Unix. To put the literal : or ; values, escape with a backslash (\:, \;).
Example:

  • Input: PATH=$PATH:lib GREET=Hello\:you npm start
  • Output (Win): PATH=%PATH%;lib GREET=Hello:you npm start
  • Output (Unix): PATH=$PATH:lib GREET=Hello:you npm start

Note that this would technically be a breaking change, and such a semver major release.

@DanReyLop
Copy link
Contributor Author

DanReyLop commented Mar 5, 2017

cc/ @kentcdodds @elijahmanor @hekard2l

@kentcdodds
Copy link
Owner

Thanks for bringing this up @DanReyLop!

What if we made the escaping required on the variable side of things? So you'd have to do:

PATH=$PATH\:lib GREET=Hello:you npm start

Would that work?

@DanReyLop
Copy link
Contributor Author

Well it would work, and it would be more backwards-compatible, but I feel like the other way is more natural.

Just like in a RegExp, you use the "reserved" characters for their intended meaning, and if you want to use them literally, you have to escape them (not the other way around). In implementing this feature, we are basically acknowledging that : (and ; in Windows) are special characters on ENV variables values.

Anyway, this feels like a lot of bikeshedding for a single-char feature, just pick one syntax and I'll make a PR :)

@kentcdodds
Copy link
Owner

Ok, I'm convinced. Let's go with your suggestion 👍 Thanks!

DanReyLop pushed a commit to Automattic/cross-env that referenced this issue Mar 22, 2017
In Windows, env variables that represent a list (such as PATH or NODE_PATH) separate their elements
using a semicolon(;), but in UNIX they're separated using a colon (:).

This commit adds a conversion layer, so regardless of how the delimiter is written when calling
cross-env, it will be converted to the correct platform delimiter at runtime. To interpret a colon/semicolon
literally instead, preced it with a backslash, like this: "cross-env VAR=semi\\;colon\\:"

BREAKING CHANGE: If an env variable has : or ; in its value, it will be converted to : on UNIX
systems or ; on Windows systems. To keep the old functionality, you will need to escape those
characters with a backslash.

kentcdodds#80
DanReyLop pushed a commit to Automattic/cross-env that referenced this issue Mar 23, 2017
In Windows, env variables that represent a list (such as PATH or NODE_PATH) separate their elements
using a semicolon(;), but in UNIX they're separated using a colon (:).

This commit adds a conversion layer, so regardless of how the delimiter is written when calling
cross-env, it will be converted to the correct platform delimiter at runtime. To interpret a colon/semicolon
literally instead, preced it with a backslash, like this: "cross-env VAR=semi\\;colon\\:"

BREAKING CHANGE: If an env variable has : or ; in its value, it will be converted to : on UNIX
systems or ; on Windows systems. To keep the old functionality, you will need to escape those
characters with a backslash.

kentcdodds#80
kentcdodds pushed a commit that referenced this issue Mar 23, 2017
* feat: Convert list delimiters for PATH-style env variables

In Windows, env variables that represent a list (such as PATH or NODE_PATH) separate their elements
using a semicolon(;), but in UNIX they're separated using a colon (:).

This commit adds a conversion layer, so regardless of how the delimiter is written when calling
cross-env, it will be converted to the correct platform delimiter at runtime. To interpret a colon/semicolon
literally instead, preced it with a backslash, like this: "cross-env VAR=semi\\;colon\\:"

BREAKING CHANGE: If an env variable has : or ; in its value, it will be converted to : on UNIX
systems or ; on Windows systems. To keep the old functionality, you will need to escape those
characters with a backslash.

#80

* chore: Add myself (DanReyLop) to the contributors list

* Simplified logic. Now only : (UNIX-style) are converted to ; (Windows-style), not the other way around

BREAKING CHANGE: You now must escape `:` to use it in a value of you don't want it to be swapped with `;` on Windows
@DanReyLop
Copy link
Contributor Author

Fixed in #93

kentcdodds pushed a commit that referenced this issue Mar 31, 2017
* feat: Convert list delimiters for PATH-style env variables

In Windows, env variables that represent a list (such as PATH or NODE_PATH) separate their elements
using a semicolon(;), but in UNIX they're separated using a colon (:).

This commit adds a conversion layer, so regardless of how the delimiter is written when calling
cross-env, it will be converted to the correct platform delimiter at runtime. To interpret a colon/semicolon
literally instead, preced it with a backslash, like this: "cross-env VAR=semi\\;colon\\:"

BREAKING CHANGE: If an env variable has : or ; in its value, it will be converted to : on UNIX
systems or ; on Windows systems. To keep the old functionality, you will need to escape those
characters with a backslash.

#80

* chore: Add myself (DanReyLop) to the contributors list

* Simplified logic. Now only : (UNIX-style) are converted to ; (Windows-style), not the other way around

BREAKING CHANGE: You now must escape `:` to use it in a value of you don't want it to be swapped with `;` on Windows
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants