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
Make npm run-script completion faster with jq
#4241
Make npm run-script completion faster with jq
#4241
Conversation
When jq is available, it's actually faster to invoke jq and parse the `package.json` invoking the `npm` command. Also, prior to this commit, both `__fish_complete_npm` and `__fish_npm_run` were being run whenever completions for `npm run` subcommand was being used, which was actually making repetitive work (invoking npm command twice). This pull request is supposed to make completion without `jq` faster as well
I'm actually not sure. Should there be tests for completions? Also, should I check one of the other checkboxes? |
share/completions/npm.fish
Outdated
if command -sq npm | ||
if command -sq jq; and test -e package.json | ||
jq -r '.scripts | to_entries[] | .key,.value' <package.json | while read -l name | ||
set -l trim 20 |
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.
This is actually repeated code from the while
loop below, as I'm not proficient in fish scripting.
How could I improve this? Suggestions would be appreciated.
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.
Currently, the best you could do is make a function that calls either jq -r [...]
or command npm run | string match [...]
, and then only do the while read
stuff here.
Ideally, yes. But at this time we do not have any unit tests specifically for completions. If you think you can implement unit tests for your completions we would be happy to consider how that could be expanded to all completion scripts. |
@krader1961 Is there any API that could be used to:
|
share/completions/npm.fish
Outdated
if command -sq npm | ||
if command -sq jq; and test -e package.json | ||
jq -r '.scripts | to_entries[] | .key,.value' <package.json | while read -l name | ||
set -l trim 20 |
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.
Currently, the best you could do is make a function that calls either jq -r [...]
or command npm run | string match [...]
, and then only do the while read
stuff here.
share/completions/npm.fish
Outdated
jq -r '.scripts | to_entries[] | .key,.value' <package.json | while read -l name | ||
set -l trim 20 | ||
read -l value | ||
echo "$value" | cut -c1-$trim | read -l value |
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.
set value (string sub -l $trim -- $value)
We do that via
The real problem with tests for completions is a different one:
Currently, this hasn't been done. I'd appreciate any good ideas. |
Created function to handle both cases of npm run completion parse, with or without `jq` completion.
@faho I've refactor my original pull request. Would you be kind to take a look?
Regarding completion testing, would it be reasonable to use docker as a dependency for testing the project? By doing so, it would be possible to many different test environments, so it would be possible to test completions. Also, I think it would be pretty straightforward to execute only one test script using docker, or maybe skip completion testing in the main test suite. What do you think?
That could be accomplished with a fixtures directory. Would be complicated, but doable, I think.
By using docker, we could guarantee we're always testing the same environment. Anyhow, all of these look like a lot of changes for a simple pull request regarding a small completion improvement. Maybe we could foward this discussion to an issue? |
Yes, please. See #4249. |
Description
When jq is available, it's actually faster to invoke jq and parse the
package.json
invoking the
npm
command.Also, prior to this commit, both
__fish_complete_npm
and__fish_npm_run
were being runwhenever completions for
npm run
subcommand was being used, which was actually makingrepetitive work (invoking npm command twice). This pull request is supposed to make completion
without
jq
faster as wellTODOs: