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

fix(search): author is ??? in result #741

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Conversation

BlackHole1
Copy link
Contributor

@BlackHole1 BlackHole1 commented Dec 18, 2024

改动原因

在今年 4 月份,npm cli 对 search 做了一些改动,在 4 月份以前(npm cli < v10.6.0),采用的是 maintainers 字段,而在 npm/cli#7407 后,改为使用: publisher 字段。

导致当 npm 版本大于等于 v10.6.0 后,search 结果中的 author 将变成 ???,如图:

CleanShot 2024-12-18 at 16 46 58@2x

预期的结果应该为:

CleanShot 2024-12-18 at 16 47 33@2x

技术细节说明

当前改动没有为 es 增加新的索引,原因是处于以下考虑:

  1. es 的 mapping 一旦创建,就无法修改(虽然使用了 dynamic: true 但无法细粒度的进行控制)
  2. 源数据中的 _npmUser 已经有相关信息了,没有必要为此浪费额外的磁盘空间
  3. 如果想对以前的数据进行更新会比较麻烦,性价比较低

npm cli 老版本: https://github.com/npm/cli/pull/7407/files#diff-4bc15933c685fc9a9ce8be0c13a2f067f5e2b3334bacd6664bdfa7ddc46aedb6L58
npm cli 新版本: https://github.com/npm/cli/pull/7407/files#diff-4bc15933c685fc9a9ce8be0c13a2f067f5e2b3334bacd6664bdfa7ddc46aedb6R162

其他

相关 PR: #513

PTAL @Beace @fengmk2 @elrrrrrrr

Signed-off-by: Kevin Cui <bh@bugs.cc>
Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

The pull request introduces modifications to the PackageSearchService and SearchRepository to enhance compatibility with npm CLI version 10.6.0. The changes focus on handling the publisher field in package search results, ensuring backward compatibility by mapping the _npmUser field when the publisher is absent. Additionally, error handling in the package removal process has been refined to provide more precise logging for package-not-found scenarios.

Changes

File Change Summary
app/core/service/PackageSearchService.ts - Updated searchPackage method to map _npmUser to publisher
- Improved error handling in removePackage method to log 404 errors specifically
app/repository/SearchRepository.ts - Added optional publisher property to SearchMappingType
- New type includes username and email fields

Poem

🐰 A Rabbit's Ode to Package Search Delight

In npm's realm, where packages dance and sway,
A publisher's touch, now finding its way
With graceful mapping and errors so neat
Our search service makes the CLI's beat complete! 🔍📦

Hop, hop, hooray! 🐇

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/core/service/PackageSearchService.ts (1)

144-152: LGTM! Publisher field mapping looks correct

The implementation properly maps the _npmUser field to the new publisher field format required by npm CLI v10.6.0+, while maintaining backward compatibility.

Consider adding a test case to verify this mapping behavior, especially for packages with and without the publisher field. Would you like me to help create the test cases?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between feba680 and 29977e1.

📒 Files selected for processing (2)
  • app/core/service/PackageSearchService.ts (1 hunks)
  • app/repository/SearchRepository.ts (1 hunks)
🔇 Additional comments (2)
app/repository/SearchRepository.ts (1)

20-23: LGTM! Type changes align with npm CLI requirements

The addition of the optional publisher type with username and email fields correctly matches the structure expected by npm CLI v10.6.0+, while maintaining backward compatibility.

app/core/service/PackageSearchService.ts (1)

144-152: Verify the impact on search functionality

Let's verify the usage of publisher/author fields in the codebase.

✅ Verification successful

Let me analyze the search results and generate the final response.

Publisher field change is safe and properly implemented

The code change to use publisher field instead of _npmUser field is safe and properly implemented because:

  1. The change only adds publisher field when it's missing and _npmUser exists, maintaining backward compatibility
  2. The search functionality in PackageSearchService.ts only uses these fields for display purposes
  3. The publisher field is consistently used across the codebase, mainly in test files and core services
  4. The _npmUser field is only used in test data and sync operations, not in core functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other occurrences of publisher or author field usage that might need updates

# Search for publisher field usage
echo "Checking publisher field usage:"
rg -p "publisher['\"]?\s*[:=]" --type ts

# Search for _npmUser field usage
echo "\nChecking _npmUser field usage:"
rg -p "_npmUser['\"]?\s*[:=]" --type ts

# Search for author-related field usage
echo "\nChecking author field usage:"
rg -p "author['\"]?\s*[:=]" --type ts

# Search for maintainers field usage that might need updates
echo "\nChecking maintainers field usage:"
rg -p "maintainers['\"]?\s*[:=]" --type ts

Length of output: 103099

@fengmk2 fengmk2 added the bug Something isn't working label Dec 18, 2024
@fengmk2 fengmk2 self-assigned this Dec 18, 2024
@fengmk2
Copy link
Member

fengmk2 commented Dec 18, 2024

@BlackHole1 Nice work!

@fengmk2 fengmk2 merged commit acffb14 into cnpm:master Dec 18, 2024
15 of 16 checks passed
fengmk2 pushed a commit that referenced this pull request Dec 18, 2024
[skip ci]

## [3.71.2](v3.71.1...v3.71.2) (2024-12-18)

### Bug Fixes

* **search:** author is `???` in result ([#741](#741)) ([acffb14](acffb14)), closes [/github.com/npm/cli/pull/7407/files#diff-4bc15933c685fc9a9ce8be0c13a2f067f5e2b3334bacd6664bdfa7ddc46aedb6L58](https://github.com/cnpm//github.com/npm/cli/pull/7407/files/issues/diff-4bc15933c685fc9a9ce8be0c13a2f067f5e2b3334bacd6664bdfa7ddc46aedb6L58) [/github.com/npm/cli/pull/7407/files#diff-4bc15933c685fc9a9ce8be0c13a2f067f5e2b3334bacd6664bdfa7ddc46aedb6R162](https://github.com/cnpm//github.com/npm/cli/pull/7407/files/issues/diff-4bc15933c685fc9a9ce8be0c13a2f067f5e2b3334bacd6664bdfa7ddc46aedb6R162)
@fengmk2
Copy link
Member

fengmk2 commented Dec 18, 2024

已生效

image

@BlackHole1 BlackHole1 deleted the fix-search branch December 18, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants