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

feat: Convert list delimiters for PATH-style env variables #93

Merged
merged 3 commits into from
Mar 23, 2017

Conversation

DanReyLop
Copy link
Contributor

@DanReyLop DanReyLop commented 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, UNIX-style delimiters (:) will be converted to Windows-style delimiters (;) on Windows systems at runtime. To interpret a colon literally instead, preced it with a backslash, like this: "cross-env VAR=foo\\:bar"

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

Closes #80

PS: Sorry for the delay, I was on vacation for a while and I didn't feel like coming near a computer :)

@codecov-io
Copy link

codecov-io commented Mar 22, 2017

Codecov Report

Merging #93 into next will not change coverage.
The diff coverage is 100%.

@@         Coverage Diff         @@
##           next    #93   +/-   ##
===================================
  Coverage   100%   100%           
===================================
  Files         2      3    +1     
  Lines        32     43   +11     
===================================
+ Hits         32     43   +11
Impacted Files Coverage Δ
src/variable.js 100% <100%> (ø)
src/index.js 100% <100%> (ø) ⬆️
src/command.js 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8679f4...021e1df. Read the comment docs.

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic. Thank you!

I'm going to consider this a breaking change and merge it into next instead so it's lumped in with the other breaking changes queued up for our next major release. Thanks!

"avatar_url": "https://avatars1.githubusercontent.com/u/1715800?v=3",
"profile": "https://daniel.blog",
"contributions": [
"code"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, do you wanna add "test" to this?

@kentcdodds kentcdodds changed the base branch from master to next March 22, 2017 23:51
@kentcdodds
Copy link
Owner

There are some merge conflicts with the next branch. If you could fix those, that'd be great.

To update the contributors table in the README, you can hand-fix the .all-contributorsrc file, then run: npm start generate

Daniel Rey Lopez added 2 commits March 22, 2017 23:58
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
Copy link
Contributor Author

@kentcdodds Done. The conflicts were just in the all-contributors thing, easy to fix :)

It makes total sense to consider this a breaking change, I didn't see you had a separate branch for that.

Glad to be of (a very little) help :)

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thanks!

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just realized one little detail. I hope it's not too inconvenient!

expect(varValueConvert('foo:bar')).toBe('foo;bar')
})

test(`converts a ; into a : on UNIX`, () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, could we simplify things a little bit? @hgwood and I have decided that it would be nicer if cross-env allowed you to only use the unix notation for things and not convert the other way. That would make the implementation simpler and the API simpler. Could you back these things out and even add a test or two to make sure that ; is not converted whether on unix or not? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, done. That was my first approach but I followed the existing logic on command.js: https://github.com/kentcdodds/cross-env/blob/master/src/command.js#L15

You folks should also simplify that to be consistent :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should. Want to do that? 😏

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thank you!

@kentcdodds kentcdodds merged commit 293c73d into kentcdodds:next Mar 23, 2017
kentcdodds pushed a commit that referenced this pull request 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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants