In a monorepo setting, a workspace script invoking a top-level script which takes positional parameters gets these parameters incorrectly interpreted as scripts (and reported) by knip
Top-level package.json:
"scripts": {
"echo": "echo"
},
Here, the echo
script just calls the echo
shell command, which takes extra parameters on the command line.
Workspace (packages/shared
) package.json:
"scripts": {
"foo": "yarn run --top-level echo hello"
}
This uses the --top-level
flag which seems to not exist in yarn 1. It simply calls the top-level script, providing a parameter to it.
When running (from the toplevel) yarn workspace @monorepo/shared run foo
, or (from the workspace directory) yarn foo
, I get the correct behaviour (display hello
in the terminal).
When running yarn knip
, I get:
Unlisted binaries (2)
...
hello packages/shared/package.json
So, it seems that knip is interpreting the command as running echo
and hello
scripts.
Adding a hello
script inside the package does remove the reporting. Adding one at toplevel doesn't.
This may be related to #735 but I believe it is different.
I was not able to reproduce this in a basic (single workspace) setting; Without the --top-level
option (and using an echo
script in the workspace), hello
is not reported, so the option may have something to do with it.
Somehow, removing the echo
script from the top-level is not reported. Maybe knip interpretes yarn run --top-level echo hello
as being an option --top-level echo
and calling script hello
(instead of option --top-level
and calling script echo
with parameter hello
).
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too