From 487241db78eb6343726fe09643b2402a4e920e4e Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Tue, 1 Aug 2017 21:23:53 +0530 Subject: [PATCH] fix: Handle relative path in cmd on windows (#130) * fix: Normalize command to handle relative path on windows * test: Normalize command for embedded env variable conversion test * docs(contributors): Add @sudo-suhas Closes #127 --- .all-contributorsrc | 10 ++++++++++ README.md | 6 +++--- src/command.js | 3 ++- src/command.test.js | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6cda3b0..f5dcec7 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -132,6 +132,16 @@ "code", "test" ] + }, + { + "login": "sudo-suhas", + "name": "Suhas Karanth", + "avatar_url": "https://avatars2.githubusercontent.com/u/22251956?v=4", + "profile": "https://github.com/sudo-suhas", + "contributions": [ + "code", + "test" + ] } ] } diff --git a/README.md b/README.md index e460101..89ce0ed 100755 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Run scripts that set and use environment variables across platforms [![downloads][downloads-badge]][npm-stat] [![MIT License][license-badge]][LICENSE] -[![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -137,9 +137,9 @@ much easier for windows users. Thanks goes to these people ([emoji key][emojis]): -| [
Kent C. Dodds](https://kentcdodds.com)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Documentation") [πŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Tests") | [
Ya Zhuang ](https://zhuangya.me)
[πŸ”Œ](#plugin-zhuangya "Plugin/utility libraries") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=zhuangya "Documentation") | [
James Harris](https://wopian.me)
[πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=wopian "Documentation") | [
compumike08](https://github.com/compumike08)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Acompumike08 "Bug reports") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=compumike08 "Documentation") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=compumike08 "Tests") | [
Daniel RodrΓ­guez Rivero](https://github.com/danielo515)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Adanielo515 "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=danielo515 "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=danielo515 "Documentation") | [
Jonas Keinholz](https://github.com/inyono)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ainyono "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=inyono "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=inyono "Tests") | [
Hugo Wood](https://github.com/hgwood)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ahgwood "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=hgwood "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=hgwood "Tests") | +| [
Kent C. Dodds](https://kentcdodds.com)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) πŸš‡ [⚠️](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds) | [
Ya Zhuang ](https://zhuangya.me)
πŸ”Œ [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=zhuangya) | [
James Harris](https://wopian.me)
[πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=wopian) | [
compumike08](https://github.com/compumike08)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Acompumike08) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=compumike08) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=compumike08) | [
Daniel RodrΓ­guez Rivero](https://github.com/danielo515)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Adanielo515) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=danielo515) [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=danielo515) | [
Jonas Keinholz](https://github.com/inyono)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ainyono) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=inyono) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=inyono) | [
Hugo Wood](https://github.com/hgwood)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ahgwood) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=hgwood) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=hgwood) | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [
Thiebaud Thomas](https://github.com/thomasthiebaud)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Athomasthiebaud "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud "Tests") | [
Daniel Rey LΓ³pez](https://daniel.blog)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Tests") | [
Amila Welihinda](http://amilajack.com)
[πŸš‡](#infra-amilajack "Infrastructure (Hosting, Build-Tools, etc)") | [
Paul Betts](https://twitter.com/paulcbetts)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Apaulcbetts "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=paulcbetts "Code") | [
Turner Hayes](https://github.com/turnerhayes)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Aturnerhayes "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes "Tests") | +| [
Thiebaud Thomas](https://github.com/thomasthiebaud)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Athomasthiebaud) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud) | [
Daniel Rey LΓ³pez](https://daniel.blog)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop) | [
Amila Welihinda](http://amilajack.com)
πŸš‡ | [
Paul Betts](https://twitter.com/paulcbetts)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Apaulcbetts) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=paulcbetts) | [
Turner Hayes](https://github.com/turnerhayes)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Aturnerhayes) [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes) | [
Suhas Karanth](https://github.com/sudo-suhas)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas) [⚠️](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas) | This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome! diff --git a/src/command.js b/src/command.js index e12c299..d549021 100644 --- a/src/command.js +++ b/src/command.js @@ -1,3 +1,4 @@ +import path from 'path' import isWindows from 'is-windows' export default commandConvert @@ -12,5 +13,5 @@ function commandConvert(command) { return command } const envUnixRegex = /\$(\w+)|\${(\w+)}/g // $my_var or ${my_var} - return command.replace(envUnixRegex, '%$1$2%') + return path.normalize(command.replace(envUnixRegex, '%$1$2%')) } diff --git a/src/command.test.js b/src/command.test.js index ccd5d30..8da98ca 100644 --- a/src/command.test.js +++ b/src/command.test.js @@ -1,3 +1,4 @@ +import path from 'path' import isWindowsMock from 'is-windows' import commandConvert from './command' @@ -34,7 +35,7 @@ test(`is stateless`, () => { test(`converts embedded unix-style env variables usage for windows`, () => { isWindowsMock.__mock.returnValue = true expect(commandConvert('$test1/$test2/$test3')).toBe( - '%test1%/%test2%/%test3%', + path.normalize('%test1%/%test2%/%test3%'), ) })