keithamus / sort-package-json

Sort an Object or package.json based on the well-known package.json keys
MIT License
790 stars 83 forks source link

feat: add --stdin flag #296

Closed danielpza closed 1 year ago

danielpza commented 1 year ago

Passing the --stdin flag would make it so it reads from stdin and outputs to stdout. This is useful for some tools/editors integration

Usage example:

$ cat package.json | sort-package-json --stdin

Closes https://github.com/keithamus/sort-package-json/issues/293

fisker commented 1 year ago

Is it possible to test?

fisker commented 1 year ago

Maybe we can use child_process or worker_thread to do that.

danielpza commented 1 year ago

Is it possible to test? Maybe we can use child_process or worker_thread to do that.

Added some tests in 14bb2fb (#296)

fisker commented 1 year ago

I forgot we already use child_process to run CLI test, we can add an option to accept stdin. https://github.com/keithamus/sort-package-json/blob/2789f2f440bfc67e6a8aeddf8a9605166e0d567d/tests/_helpers.js#L175 But it can be done in future, since it's not important.

danielpza commented 1 year ago

I forgot we already use child_process to run CLI test, we can add an option to accept stdin.

Applied these changes in f7c3b6f (#296)

fisker commented 1 year ago

We have --check flag. Do you think we should support cat package.json | sort-package-json --stdin --check?

danielpza commented 1 year ago

We have --check flag do you think we should support cat package.json | sort-package-json --stdin --check?

I considered adding support for the other flags, but it's not a priority for my use case. I guess we can add more support in the future if needed

danielpza commented 1 year ago

Is there any blocker for this PR, any chance to get it merged otherwise?

keithamus commented 1 year ago

Thanks for the reminder @danielpza! 🎉🎉

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 2.5.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: