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

feat(command): return result of run command #101

Merged
merged 3 commits into from
Nov 20, 2023

Conversation

mandarini
Copy link
Contributor

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Changes

This will return the result of the run function of the command being executed.

Why is this needed?

Sometimes a command may return some output or something. It would be nice to be able to get this result.
Please see this related PR I submitted to the Nuxt nuxi CLI. They are using runCommand from citty here: https://github.com/nuxt/cli/blob/3401917c1852918171e23013d6522bda31762e5d/src/run.ts#L33

And they are returning the result or runCommand like this:

return await _runCommand(await commands[name as keyof typeof commands](),

now, if the command they are calling/running returns something, it would be lost, since runCommand does not return anything as it is.

I hope this change makes sense. We need it in Nx, but in any case I think it could benefit others as well.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

src/command.ts Outdated
@@ -17,7 +17,7 @@ export interface RunCommandOptions {
export async function runCommand<T extends ArgsDef = ArgsDef>(
cmd: CommandDef<T>,
opts: RunCommandOptions,
): Promise<void> {
): Promise<void | any> {
Copy link
Member

@pi0 pi0 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the forward compatibility, we might return { result: unknown } object format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pi0 made the change you requested! Thanks!

@mandarini mandarini force-pushed the feat/return-cmd-result branch from 8b7ab64 to f238816 Compare November 6, 2023 08:50
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Made minor changes to always preserve { result } returned value

@pi0 pi0 merged commit 0179be0 into unjs:main Nov 20, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants