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
feat: run scripts without -- #4290
Conversation
@@ -207,13 +207,59 @@ test('any unknown command is treated as a script', async () => { | |||
fallbackCommand: 'run', | |||
getCommandLongName: () => null, | |||
universalOptionsTypes: { filter: [String, Array] }, | |||
}, ['foo', '--recursive']) | |||
}, ['--recursive', 'foo']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to rearrange the --recursive
flag here to fix the test after these changes. This was expected from the behavior change described in the pull request description.
@@ -134,6 +134,11 @@ export async function handler ( | |||
) { | |||
let dir: string | |||
const [scriptName, ...passedThruArgs] = params | |||
// For backward compatibility | |||
const firstDoubleDash = passedThruArgs.findIndex((arg) => arg === '--') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pattern matched this from the same change in pnpm exec
: #3492
pnpm/packages/plugin-commands-script-runners/src/exec.ts
Lines 76 to 79 in 0355d30
// For backward compatibility | |
if (params[0] === '--') { | |
params.shift() | |
} |
pnpm v6 allowed --
anywhere in the args
portion of pnpm run <command> [..args]
, so this extra .findIndex
logic tries to maintain full backwards compatible behavior for that.
Although perhaps we should only swallow the first --
like pnpm exec
does. I could see the behavior in the scenario below being a bit surprising. This is how pnpm behaves before and after this pull request.
❯ pnpm run --silent echo a -- b
a b
You might expect:
❯ pnpm run --silent echo a -- b
a -- b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the behavior above didn't change in this PR, I do worry this will come back to bite someone that thinks --
can be dropped entirely after this change. Just a heads up @zkochan.
Happy to make any additional followup changes before the pnpm v7 release if we want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine if we don't swallow --
at all. This is a breaking change in v7. So it won't be a surprise to anyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Cool. I'll open a pull request reverting this block later tonight when I'm near my computer.
"@pnpm/parse-cli-args": major | ||
"@pnpm/plugin-commands-script-runners": major | ||
"pnpm": major |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these all be major
?
const indexOfRunScriptName = 1 + | ||
(recursiveCommandUsed ? 1 : 0) + | ||
(fallbackCommandUsed && opts.fallbackCommand === 'run' ? -1 : 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here might be a bit of a hacky way to do things. We could also:
- run
nopt
again to find the script name to use as the escape arg. That would result in 3nopt
calls here. - add additional behavior in pnpm's
nopt
fork to dynamically determine whether something is an escape arg. I'm imagining a closure that gets passed the partial CLI parsing up to that point.
@@ -107,7 +107,7 @@ For options that may be used with `-r`, see "pnpm help recursive"', | |||
FILTERING, | |||
], | |||
url: docsUrl('run'), | |||
usages: ['pnpm run <command> [-- <args>...]'], | |||
usages: ['pnpm run <command> [--] [<args>...]'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just drop the [--]
part here like pnpm --help exec
does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop it
An alternative (probably easier to implement) solution would be to escape everything after run. So you could only pass options to run before the This would work: |
Cherry picked by Brandon Cheng from feat/3778 branch.
c575e75
to
098bc93
Compare
That would be much easier to implement. I had an initial approach last week that just added pnpm/packages/pnpm/src/parseCliArgs.ts Line 20 in 376c304
It did end up confusing me that Are the implementation complexities reasonable given the improved UX of this approach? I personally believe so, but happy for you to make that call. |
OK, if it is supported by Yarn, then we don't really have a choice. We need to support it as well. |
Thanks for taking a look so quickly!
I am a bit surprised by this. Although in this case I do like yarn's behavior, I would hope pnpm deviates in other situations we think it can do better. I think you should feel free to make those calls @zkochan, even if individuals like me disagree. 🙂 |
I would love to but then we'll have a lot of issues from users that switch from Yarn. So it is easier just to support it. |
Fixes #3778.
Behavior Change
There's a lot of scenarios mentioned in the original issue that make all solutions ambiguous/non-ideal. While still not perfect, I think the behavior below will cause the least amount of confusion:
<command>
portion ofpnpm run <command>
is passed directly to<command>
itself.<command>
portion is treated as an option topnpm run
.--
anywhere after<command>
is swallowed.For example:
pnpm run --help
to still show the help text forpnpm run
.pnpm run changeset --help
will show the help text of whatever command drives thechangeset
script.Notes
feat/3778
branch: 624b8a7 Hope that was okay @zkochan.escapeArgs
option innopt
: pnpm/nopt@446cfbe