-
Notifications
You must be signed in to change notification settings - Fork 3k
API-based npm search command #15481
API-based npm search command #15481
Conversation
bcoe
left a comment
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 looking pretty solid to me; I like the how you fallback to the old search.
One thing comes to mind, because browserify-zlib check in there fixture directory, we end up with some pretty odd artifacts in the bundled dependencies. e.g., this picture of a person:
It might be worth opening an issue, or simply sending a pull-request to browserify-zlib that removes test files from the package.
| function esearch (opts) { | ||
| var stream = ms.through.obj() | ||
|
|
||
| mapToRegistry('-/v1/search', npm.config, function (er, uri, auth) { |
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 warms my heart 👍
|
@satazor all the current search syntax is supported because we pretty much pass arguments directly to the endpoint. You can do EDIT: oops. You already talked about that! I'd love an invite to the Slack :) |
|
Awesome! :D |
|
🎉 🎈 this is really exciting. |
iarna
left a comment
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 looks great! Can't wait to have it!
I had a couple of nits but nothing blocking.
lib/search/esearch.js
Outdated
| streaming: true | ||
| } | ||
| var q = buildQuery(opts) | ||
| npm.registry.request(uri + '?text=' + encodeURIComponent(q) + '&size=' + opts.limit, params, function (er, res) { |
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.
Absurdly picky style note: If we use err then standard can complaint if we fail to check it. I've been trying to get in the habit of using err instead of er so I can have that validation.
| // Modify how `res` is used here at your own risk. | ||
| var entryStream = ms.pipeline.obj( | ||
| res, | ||
| ms.through(function (chunk, enc, cb) { |
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 just to turn res into a modern stream?
I think usingnew stream.PassThrough() here would be less ambiguous..
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.
No it's just literally that weird and there's something about using this particular type of passthrough that worked through an issue I was having. I didn't do the due diligence of figuring out what was happening back then (during the original rewrite, which this code is based on). So maybe I'll just have to do it but siiiiiggghhhh
| } | ||
|
|
||
| function cleanup () { | ||
| server.done() |
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.
why is this in a different place than server.close()?
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.
close shuts down the server. done does missing-request checks while letting us reuse the same server (so, it errors if we don't hit the mocked endpoint at all)
| @@ -0,0 +1,192 @@ | |||
| var common = require('../common-tap.js') | |||
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.
search.esearch.js? Not search-esearch.js?
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.
That's just me being inconsistent. I've been using the former with pacote and cacache and it just feels nicer for hierarchies of tests in a single flat dir
|
Coverage increased (+0.08%) to 85.94% when pulling d93f97d70eda95558ac44a345f58d7899980e8f8 on zkat/fastsearch into 04fca22 on release-next. |
Yay!
So this PR makes it so the npm CLI actually hits the shiny new search endpoint! Default
npm searchon the main registry should be blazing fast now.No. Seriously:
The search system still falls back to cache or
/-/all-based searches for registries that don't support this endpoint, and if you happen to have a cache while running offline, it'll use that cache with classic search.To-Do
Note: The PR is basically ready to review of the bulk of the changes, but below are a couple of items that are still pending.
esearchgunzip-maybebecause it adds almost 2MB--searchlimitwhen usingall-package-searchall-package-search