Skip to content

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

Merged
pi0 merged 3 commits into
unjs:mainfrom
mandarini:feat/return-cmd-result
Nov 20, 2023
Merged

pi0 merged 3 commits into
unjs:mainfrom
mandarini:feat/return-cmd-result

Conversation

@mandarini

Copy link
Copy Markdown
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.

Comment thread src/command.ts Outdated
cmd: CommandDef<T>,
opts: RunCommandOptions,
): Promise<void> {
): Promise<void | any> {

@pi0 pi0 Nov 3, 2023 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

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
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