Repository navigation
fix: resolve commands executed with vp exec - #2285
Conversation
commit: |
|
|
||
| const dir = C ? toAbsolute(C, options.cwd) : undefined; | ||
| const rest = words.slice(commandIndex); | ||
| const script = execOptions['shell-mode'] && rest.length === 1 ? rest[0].value : rest.map(word => word.text).join(' '); |
There was a problem hiding this comment.
With -c, Vite+ joins all arguments and passes the result to the shell, so vp exec -c "node ./scripts/proof.mjs" --flag runs scripts/proof.mjs. With more than one word here, the whole quoted command becomes a single entry and the script is still reported as unused. Using word.value for every word in shell mode covers both cases:
| const script = execOptions['shell-mode'] && rest.length === 1 ? rest[0].value : rest.map(word => word.text).join(' '); | |
| const script = rest.map(word => (execOptions['shell-mode'] ? word.value : word.text)).join(' '); |
| const execOptions = parseArgs(words.slice(execIndex + 1, commandIndex), parseOptions); | ||
| if (execOptions.filter && !execOptions.recursive) return [binary]; | ||
|
|
||
| const dir = C ? toAbsolute(C, options.cwd) : undefined; |
There was a problem hiding this comment.
-w runs the command in the workspace root, so vp exec -w node ./scripts/root.mjs in a package script runs the root's scripts/root.mjs. Since it's resolved against the package, a scripts/root.mjs in the package is marked as used instead, and the root file is still reported as unused:
| const dir = C ? toAbsolute(C, options.cwd) : undefined; | |
| const dir = execOptions['workspace-root'] ? options.rootCwd : C ? toAbsolute(C, options.cwd) : undefined; |
| if (commandIndex === undefined) return [binary]; | ||
|
|
||
| const execOptions = parseArgs(words.slice(execIndex + 1, commandIndex), parseOptions); | ||
| if (execOptions.filter && !execOptions.recursive) return [binary]; |
There was a problem hiding this comment.
Vite+ rejects --filter together with --recursive ("--filter and --recursive cannot be used together"), so this can be simpler:
| if (execOptions.filter && !execOptions.recursive) return [binary]; | |
| if (execOptions.filter) return [binary]; |
|
|
||
| const parseOptions = { | ||
| isStorePositions: true, | ||
| string: ['C', 'filter', 'resume-from'], |
There was a problem hiding this comment.
A leading -C is already handled by parseLeadingChdir, and after exec Vite+ treats -C as the command, so 'C' isn't needed here:
| string: ['C', 'filter', 'resume-from'], | |
| string: ['filter', 'resume-from'], |
| t('vp exec vitest --filter smoke', [toBinary('vp'), toBinary('vitest')]); | ||
| t(`vp -C ${app.dir} exec node ./scripts/task.mjs`, [toBinary('vp'), toBinary('node', app), toDeferResolveEntry('./scripts/task.mjs', { ...opt, ...app })]); | ||
| t('vp -Cpackages/app exec node ./scripts/task.mjs', [toBinary('vp'), toBinary('node', app), toDeferResolveEntry('./scripts/task.mjs', { ...opt, ...app })]); | ||
| t(`vp -C${app.dir} exec node ./scripts/task.mjs`, [toBinary('vp'), toBinary('node', app), toDeferResolveEntry('./scripts/task.mjs', { ...opt, ...app })]); |
There was a problem hiding this comment.
Could you add cases for these? The -c and -w lines fail without the changes above, and the -t line guards the flags that take no value:
| t(`vp -C${app.dir} exec node ./scripts/task.mjs`, [toBinary('vp'), toBinary('node', app), toDeferResolveEntry('./scripts/task.mjs', { ...opt, ...app })]); | |
| t(`vp -C${app.dir} exec node ./scripts/task.mjs`, [toBinary('vp'), toBinary('node', app), toDeferResolveEntry('./scripts/task.mjs', { ...opt, ...app })]); | |
| t('vp exec -c "node ./script.js" --flag', [toBinary('vp'), toBinary('node'), js]); | |
| t('vp exec -t node ./script.js', [toBinary('vp'), toBinary('node'), js]); | |
| t('vp exec -w node ./script.js', [toBinary('vp'), toBinary('node', { dir: cwd }), toDeferResolveEntry('./script.js', { ...opt, dir: cwd })], { cwd: app.dir }); |
|
Fixed in 4b2e73a: shell-mode arguments, workspace-root resolution, the requested tests and both parser cleanups. |
webpro
left a comment
There was a problem hiding this comment.
Thanks, all five are in, and the extra --workspace-root case is a nice touch.
|
π This pull request is included in v6.44.2. See Release 6.44.2 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
Fixes #2284.
Follow the command passed to
vp execso its scripts are discovered without manual entry configuration. The resolver preserves quoted arguments,--and the three leading-Cforms, including absolute paths. Other subcommands return only thevpbinary.Registering
vpas a package manager also lets mise tasks follow its commands and apply the same binary checks as package scripts.Tested with parser regressions that fail without the fix, the CLI reproduction from the issue,
pnpm run ciand the fullpnpm qa.