Skip to content

Commit

Permalink
feat(bin): two bins (shell, non-shell)
Browse files Browse the repository at this point in the history
Revert the default bin (cross-env) to its v3 behavior (not using the shell option). Add a new
(cross-env-shell)  which uses the shell option.

BREAKING CHANGE: Scripts using quotes or escape sequences will see a difference in behavior.
Switching to the second bin should resolve any issue.

Closes kentcdodds#99.
  • Loading branch information
hgwood committed Apr 9, 2017
1 parent 6994a24 commit c14366c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/bin/cross-env-shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const crossEnv = require('..')

crossEnv(process.argv.slice(2), {shell: true})
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module.exports = crossEnv

const envSetterRegex = /(\w+)=('(.+)'|"(.+)"|(.+))/

function crossEnv(args) {
function crossEnv(args, options = {}) {
const [envSetters, command, commandArgs] = parseCommand(args)
if (command) {
const proc = spawn(
commandConvert(command),
commandArgs.map(commandConvert),
{
stdio: 'inherit',
shell: true,
shell: options.shell,
env: getEnvVars(envSetters),
},
)
Expand Down
6 changes: 4 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ it(`should handle equality signs in quoted strings`, () => {
})

it(`should handle quoted scripts`, () => {
crossEnv(['GREETING=Hi', 'NAME=Joe', 'echo $GREETING && echo $NAME'])
crossEnv(['GREETING=Hi', 'NAME=Joe', 'echo $GREETING && echo $NAME'], {
shell: true,
})
expect(
crossSpawnMock.spawn,
).toHaveBeenCalledWith('echo $GREETING && echo $NAME', [], {
Expand Down Expand Up @@ -94,7 +96,7 @@ function testEnvSetting(expected, ...envSettings) {
expect(crossSpawnMock.spawn).toHaveBeenCalledTimes(1)
expect(crossSpawnMock.spawn).toHaveBeenCalledWith('echo', ['hello world'], {
stdio: 'inherit',
shell: true,
shell: undefined,
env: Object.assign({}, process.env, env),
})

Expand Down

0 comments on commit c14366c

Please sign in to comment.