Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter/argument passthrough option #33

Closed
MadLittleMods opened this issue Apr 6, 2016 · 20 comments · Fixed by #307
Closed

Add parameter/argument passthrough option #33

MadLittleMods opened this issue Apr 6, 2016 · 20 comments · Fixed by #307

Comments

@MadLittleMods
Copy link

@MadLittleMods MadLittleMods commented Apr 6, 2016

Running npm run dev -- --foo=bar will result in concurrently --raw "npm run start" "gulp watch" "--foo=bar" which doesn't properly add the parameter to any of the commands.

The double dash -- parameter passing is part of npm run so "you can use custom arguments when executing scripts", https://docs.npmjs.com/cli/run-script

{
  "scripts": {
    "dev": "concurrently --raw --parameter-passthrough \"npm run start\" \"gulp watch\""
  }
}

We could add an--parameter-passthrough option to concurrently that would add the last command chunk onto each command piece. The last chunk that would be considered parameters could even be separated by --.

So running npm run dev -- -- --foo=bar would result in the following after npm, concurrently --raw "npm run start" "gulp watch" "--" "--foo=bar" and then finally npm run start --foo=bar && gulp watch --foo=bar

An issue is adding the extra -- for npm run arg passing. As you can see above, for it to be effective, it would actually need to be npm run start -- --foo=bar && gulp watch --foo=bar. Perhaps the npm script should be updated to include the extra -- though: "dev": "concurrently --raw --parameter-passthrough \"npm run start --\" \"gulp watch\""


If we wanted to get fancier could even add separation with --0, --1 which would go to each indexed command chunk respectively, npm run dev -- --0 --foo=bar --1 --qux=dorf which would finally end up at npm run start -- --foo=bar && gulp watch --qux=dorf

@andreieftimie
Copy link

@andreieftimie andreieftimie commented Jun 2, 2016

@MadLittleMods have you found any workaround for this?
I can't use concurrently because I need to pass some configs along to each invoked script.

@kimmobrunfeldt
Copy link
Contributor

@kimmobrunfeldt kimmobrunfeldt commented Jun 2, 2016

if someone has time to create a PR, I'll merge it. Sorry for the delayed response.

@kimmobrunfeldt
Copy link
Contributor

@kimmobrunfeldt kimmobrunfeldt commented Sep 19, 2016

If someone wants to implement this, let's do the simpler way first and think about the fancy tricks later. I don't like the --0 and --1 that much as it complicates the usage.

@MadLittleMods
Copy link
Author

@MadLittleMods MadLittleMods commented Oct 31, 2016

Implemented as --argument-passthrough option here in https://github.com/kimmobrunfeldt/concurrently/pull/68, still need to figure out testing for this new option.

thaggie added a commit to thaggie/concurrently that referenced this issue Jan 25, 2017
Use -- to pass through arguments to the first command.

```
concurrently "echo foo" "echo bar" -- baz
```

```
echo foo baz
echo bar
```

Use the -a or --all option to pass through the arguments to all the commands.

```
concurrently "echo foo" "echo bar" --all -- baz
```

```
echo foo baz
echo bar baz
```
@thaggie
Copy link

@thaggie thaggie commented Jan 25, 2017

My PR is an alternative implementation where the arguments are either passed to the first command (default) or all the commands (--all option).

The unit test has not been tested on windows.

@gustavohenke
Copy link
Member

@gustavohenke gustavohenke commented Jan 26, 2017

Hi @thaggie and @MadLittleMods, I reviewed both PRs.
I'll place my thoughts here as well: isn't it better if we skip any option, and simply pass arguments through if we find --?

However, if you have examples of programs that work similarly, we could review the need of such option.

@thaggie
Copy link

@thaggie thaggie commented Jan 26, 2017

My use case is for npm test, I run the unit tests and linting (css, js and jsx) at the same time - they're different programs that want different arguments. I want to be able to pass arguments through to just the unit test script.

@thaggie
Copy link

@thaggie thaggie commented Jan 26, 2017

After a little thought it might be better to default to the last command as that's the one closest to the --.

@gustavohenke
Copy link
Member

@gustavohenke gustavohenke commented Jan 27, 2017

So isn't it better if you directly specify those args for the process that will use it?

@thaggie
Copy link

@thaggie thaggie commented Jan 27, 2017

Not sure what you mean.

I want to be able to:
npm test -- --reporters progress,junit
or
npm test -- --reporters mocha
or any other commands I want to pass down to karma

and have --reporters progress,junit just go to my unit test command not my linting commands.

From package.json:

"test": "concurrently \"karma start karma.conf.js\" \"eslint src --ext js\" --" 

@csvan
Copy link

@csvan csvan commented Nov 9, 2017

Any news on this? My use case is the same as @thaggie

@carlosasj
Copy link

@carlosasj carlosasj commented Mar 20, 2018

An alternative would be use bash or sh to "build" the command before concurrently starts its execution. For example:

"myScript": "bash -c 'concurrently \"npm run start\" \"npm run _wait-for-server-up && npm run _run-subset-tests -- ${0} && npm run open-report\"'",

So you can use like:

npm run myScript -- --myArgument

It's not the best solution, but could help someone while we don't have an official implementation of this feature.

I read it here: npm/npm#9627

@timster
Copy link

@timster timster commented Oct 25, 2018

I created a run.js file as a workaround. This lets me pass args to whichever process(es) I want.

const concurrently = require('concurrently')

const args = process.argv.slice(2).join(' ')

concurrently(
  [
    { command: 'npm:dev:server', prefixColor: 'blue', name: 'server' },
    { command: 'npm:dev:client -- ' + args, prefixColor: 'magenta', name: 'client' }
  ],
  {
    killOthers: ['failure', 'success']
  }
)

Then I can do:

node run.js --arg1=value

And as an npm script:

"scripts": {
  "dev": "node run.js",
}

npm run dev -- --arg1=value

@stocks29
Copy link

@stocks29 stocks29 commented Nov 24, 2018

While it's not ideal, env vars are pretty easy to use as a short term workaround:

  "scripts": {
    "dev:support": " // some other proc here",
    "test:only": "truffle test $TRUFFLE_TEST",
    "test": "concurrently --kill-others --success first npm:dev:support npm:test:only"
  },

Then you can run the script as:

TRUFFLE_TEST=./test/MyTest.js npm test

@Ore4444
Copy link

@Ore4444 Ore4444 commented Apr 15, 2019

When using Yarn, it works!
"watch:lint:ts": "concurrently \"yarn:client:lint:ts --watch\" \"yarn:server:lint:ts --watch\"",

@csvan
Copy link

@csvan csvan commented Apr 16, 2019

@Ore4444 that is not a passthrough though, you are passing - -watch to each subcommand directly in the script.

@1aurabrown
Copy link

@1aurabrown 1aurabrown commented May 12, 2020

hi, just wondering if this has been implemented or not.

@LoanProKen
Copy link

@LoanProKen LoanProKen commented Dec 2, 2020

well, .,.,. This has been a while, if someone sees my post please put a link to the change implementation...

@205g0
Copy link

@205g0 205g0 commented Jul 16, 2021

any news on this? the env var hack is good as work-around

@kristiannotari
Copy link

@kristiannotari kristiannotari commented Mar 8, 2022

The recent pr #307 looks promising. Hope to see it merged in one way or another in the near future. This would be great to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.