can`t pass command line args using lerna
Asked Answered
Z

2

5

I try run the script from the root but got the error:

ERR! lerna Unknown argument: d

the command from root package.json:

"start:scripts:api-football:start:collectDayMatches:dev": "lerna run start:collectDayMatches:dev --stream"

try run yarn start:scripts:api-football:start:collectDayMatches:dev -- -d 2002-02-02

Zama answered 29/4, 2020 at 6:14 Comment(0)
S
5

It seems you are trying to pass command arguments to the npm script of each package.

For example:

packages/pkg-a/package.json:

"scripts": {
  "start:collectDayMatches:dev": "ls"
}

root package.json:

"scripts": {
  "start:scripts:api-football:start:collectDayMatches:dev": "lerna run start:collectDayMatches:dev --stream"
}

Let's pass the -a option to the ls command.

You should run the npm script with three double-dash (--) like this:

[main] ⚡  yarn start:scripts:api-football:start:collectDayMatches:dev -- -- -- -a
yarn run v1.22.10
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ lerna run start:collectDayMatches:dev --stream -- -- -a
lerna notice cli v3.22.1
lerna info Executing command in 1 package: "npm run start:collectDayMatches:dev -- -a"
pkg-a: > [email protected] start:collectDayMatches:dev /Users/dulin/workspace/github.com/mrdulin/lerna-codelab/packages/pkg-a
pkg-a: > ls "-a"
pkg-a: .
pkg-a: ..
pkg-a: app.js
pkg-a: app.test.js
pkg-a: docs
pkg-a: jest.config.js
pkg-a: node_modules
pkg-a: package-lock.json
pkg-a: package.json
lerna success run Ran npm script 'start:collectDayMatches:dev' in 1 package in 0.2s:
lerna success - pkg-a
✨  Done in 0.60s.

As you can see, the final command is ls "-a".

Subscript answered 5/2, 2021 at 9:25 Comment(0)
P
2

Solution

Add -- -- -- between the lerna command and the argument you want passed in.

As per the question example...

For the command:

yarn start:collectDayMatches:dev

add the -- -- -- syntax:

yarn start:collectDayMatches:dev -- -- -- d

(This is the same solution as https://mcmap.net/q/1999708/-can-t-pass-command-line-args-using-lerna, but simplified)

Patchy answered 28/6, 2023 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.