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

fix: Remove Windows => UNIX variable conversion #94

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export default commandConvert
* @returns {String} Converted command
*/
function commandConvert(command) {
const envUseUnixRegex = /\$(\w+)|\${(\w+)}/g // $my_var or ${my_var}
const envUseWinRegex = /%(.*?)%/g // %my_var%
const isWin = isWindows()
const envExtract = isWin ? envUseUnixRegex : envUseWinRegex
return command.replace(envExtract, isWin ? '%$1$2%' : '$$$1')
if (!isWindows()) {
return command
}
const envUnixRegex = /\$(\w+)|\${(\w+)}/g // $my_var or ${my_var}
return command.replace(envUnixRegex, '%$1$2%')
}
22 changes: 9 additions & 13 deletions src/command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ test(`leaves command unchanged when not a variable`, () => {
expect(commandConvert('test')).toBe('test')
})

test(`converts windows-style env variable usage for linux`, () => {
test(`doesn't convert windows-style env variable`, () => {
isWindowsMock.__mock.returnValue = false
expect(commandConvert('%test%')).toBe('$test')
expect(commandConvert('%test%')).toBe('%test%')
})

test(`leaves variable unchanged when using correct operating system`, () => {
Expand All @@ -38,18 +38,14 @@ test(`converts embedded unix-style env variables usage for windows`, () => {
)
})

test(`converts embedded windows-style env variables usage for linux`, () => {
isWindowsMock.__mock.returnValue = false
expect(commandConvert('%test1%/%test2%/%test3%')).toBe(
'$test1/$test2/$test3',
)
})

// eslint-disable-next-line max-len
test(`leaves embedded variables unchanged when using correct operating system`, () => {
isWindowsMock.__mock.returnValue = false
expect(commandConvert('$test1/$test2/$test3')).toBe('$test1/$test2/$test3')
})
test(
`leaves embedded variables unchanged when using correct operating system`,
() => {
isWindowsMock.__mock.returnValue = false
expect(commandConvert('$test1/$test2/$test3')).toBe('$test1/$test2/$test3')
},
)

test(`converts braced unix-style env variable usage for windows`, () => {
isWindowsMock.__mock.returnValue = true
Expand Down