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(help): refactor npm help/help-search #2859

Merged
merged 0 commits into from Mar 18, 2021
Merged

Conversation

wraithgar
Copy link
Member

@wraithgar wraithgar commented Mar 11, 2021

Lots of dead code removed thanks to streamlining of logic.

npm help npm <command> and npm help-search are all now separated
concerns, handling their own use cases. help calls help-search as a
last resort, but npm <command> no longer tries to wind its way through
to help-search just to get the basic npm usage displayed.

The did you mean output has been expanded. It now always suggests top
level commands, scripts, and bins, and suggests them in the way they
should be called.

Screen Shot 2021-03-17 at 12 32 02 PM

References

Closes npm/statusboard#277

@wraithgar wraithgar requested a review from a team as a code owner March 11, 2021 22:59
@wraithgar wraithgar force-pushed the gar/help-search branch 6 times, most recently from 0c9d405 to bf6c3a8 Compare March 12, 2021 15:30
lib/access.js Outdated
@@ -20,6 +20,10 @@ const subcommands = [
]

class Access extends BaseCommand {
static get description () {
return 'Set access level on published packages'
Copy link
Member Author

Choose a reason for hiding this comment

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

These all now should match the descriptions in the docs for all the commands, which means we are one step away from being able to programmatically generate everything before the longhand "Description" sections of those docs.

@wraithgar wraithgar force-pushed the gar/help-search branch 2 times, most recently from 2e175cf to 7f6195e Compare March 12, 2021 16:23
lib/docs.js Outdated
constructor (npm) {
this.npm = npm
const BaseCommand = require('./base-command.js')
class Docs extends BaseCommand {
Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test to test/lib/load-all-commands.js that caught this bug. Yay.

lib/docs.js Outdated
}

/* istanbul ignore next - see test/lib/load-all-commands.js */
get usage () {
return usageUtil('docs', 'npm docs [<pkgname> [<pkgname> ...]]')
static get usage () {
Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test to test/lib/load-all-commands.js that caught this bug. Yay.

@@ -26,28 +27,17 @@ class HelpSearch extends BaseCommand {

async helpSearch (args) {
if (!args.length)
throw this.usage
return this.npm.output(this.usage)
Copy link
Member Author

Choose a reason for hiding this comment

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

Now that this isn't pulling triple duty it can just work like everything else and return usage on no params

const formatted = this.formatResults(args, results)
if (!formatted.trim())
npmUsage(this.npm, false)
else {
this.npm.output(`No matches in help for: ${args.join(' ')}\n`)
Copy link
Member Author

Choose a reason for hiding this comment

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

Now that this isn't the usage output for the cli itself we can act in isolation and not have to return usage here.

lib/help.js Outdated

let pref = [1, 5, 7]
Copy link
Member Author

Choose a reason for hiding this comment

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

The old method would treat the number in the args as a suggestion, there is no need to search everywhere if we are explicitly asking for a given man number. This was the source of most of the streamlining here.

lib/help.js Outdated Show resolved Hide resolved
@darcyclarke darcyclarke added semver:patch semver patch level for changes Release 7.x work is associated with a specific npm 7 release release: next These items should be addressed in the next release labels Mar 12, 2021
@ruyadorno ruyadorno changed the base branch from latest to release-next March 18, 2021 20:11
@ruyadorno ruyadorno closed this Mar 18, 2021
@ruyadorno ruyadorno merged commit 41facf6 into release-next Mar 18, 2021
This was referenced Mar 23, 2021
@wraithgar wraithgar deleted the gar/help-search branch November 2, 2021 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: next These items should be addressed in the next release Release 7.x work is associated with a specific npm 7 release semver:patch semver patch level for changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor(help-search): consolidate help and help-search
3 participants