-
Notifications
You must be signed in to change notification settings - Fork 89
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: add --stdin flag #296
Conversation
Is it possible to test? |
Maybe we can use child_process or worker_thread to do that. |
Added some tests in |
I forgot we already use child_process to run CLI test, we can add an option to accept stdin. sort-package-json/tests/_helpers.js Line 175 in 2789f2f
But it can be done in future, since it's not important. |
Applied these changes in |
We have |
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 |
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.
LGTM, thank you!
@@ -89,6 +89,14 @@ $ sort-package-json "**/package.json" --check --quiet | |||
$ sort-package-json "**/package.json" --quiet | |||
``` | |||
|
|||
### `--stdin` flag |
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'm not particularly precious about this, but it makes me think; would --file <path>
/-F <path>
be a better option here - where one can use -
to use stdin. This is how git
does it (git commit -F my-template
or echo foo | git commit -F -
).
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.
We plan to use util.parseArgs
#283, not sure if it supports that.
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.
> util.parseArgs({args: ['-f', '-'], options: {file: {type: 'string', short: 'f' }}})
{ values: [Object: null prototype] { file: '-' }, positionals: [] }
Looks like it does?
Is there any blocker for this PR, any chance to get it merged otherwise? |
Thanks for the reminder @danielpza! 🎉🎉 |
🎉 This PR is included in version 2.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [sort-package-json](https://togithub.com/keithamus/sort-package-json) | [`2.4.1` -> `2.5.0`](https://renovatebot.com/diffs/npm/sort-package-json/2.4.1/2.5.0) | [![age](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/compatibility-slim/2.4.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/confidence-slim/2.4.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>keithamus/sort-package-json (sort-package-json)</summary> ### [`v2.5.0`](https://togithub.com/keithamus/sort-package-json/releases/tag/v2.5.0) [Compare Source](https://togithub.com/keithamus/sort-package-json/compare/v2.4.1...v2.5.0) ##### Features - add --stdin flag ([#​296](https://togithub.com/keithamus/sort-package-json/issues/296)) ([cefbbcb](https://togithub.com/keithamus/sort-package-json/commit/cefbbcbda23fc4caaad0fd3b9a5968d7b1adc96e)), closes [/github.com/keithamus/sort-package-json/pull/296#discussion_r1170890491](https://togithub.com//github.com/keithamus/sort-package-json/pull/296/issues/discussion_r1170890491) [/github.com/keithamus/sort-package-json/pull/296#discussion_r1170896656](https://togithub.com//github.com/keithamus/sort-package-json/pull/296/issues/discussion_r1170896656) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/UK-Export-Finance/mdm-api). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNDQuMiIsInVwZGF0ZWRJblZlciI6IjM1LjE0NC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Passing the
--stdin
flag would make it so it reads fromstdin
and outputs tostdout
. This is useful for some tools/editors integrationUsage example:
$ cat package.json | sort-package-json --stdin
Closes #293