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: support unpkg alias path access entry file #674 #675

Merged
merged 10 commits into from
May 16, 2024

Conversation

chilingling
Copy link
Contributor

@chilingling chilingling commented May 8, 2024

closes #674

Summary by CodeRabbit

  • New Features

    • Implemented a feature to handle compatibility with unpkg by searching for and redirecting to possible file entries if the requested file is not found.
  • Tests

    • Added a new test case to ensure the redirection to possible file entries functions correctly.

Copy link
Contributor

coderabbitai bot commented May 8, 2024

Walkthrough

The recent update enhances the PackageVersionFileController to handle compatibility with unpkg by searching for possible file entries and implementing redirection when a requested file is not found. It also includes a new package.json for a test package and additional test cases for redirecting to potential file entries.

Changes

Files Change Summary
app/port/controller/PackageVersionFileController.ts Added #searchPossibleEntries method and redirection logic.
test/fixtures/@cnpm/test-find-entry/package.json Introduced package.json with metadata for a test package.
test/port/controller/PackageVersionFileController/listFiles.test.ts Added a test case for redirecting to a possible file entry.

🐇
In the code's deep warren, changes abound,
New paths and entries, now easily found.
With tests to guide, and logic bright,
Our code hops forward, day and night.
Redirects in place, all errors take flight,
The rabbit's code, a pure delight.
🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

* @return
*/
async #searchPossibleEntries(packageVersion: any, path: string) {
const possiblePath = [ `${path}.js`, `${path}.json`, `${path}/index.js` ];
Copy link
Contributor

Choose a reason for hiding this comment

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

需要考虑 package.json 的 export 么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我看 unpkg 没考虑?我这里参考 unpkg findEntry 文件的逻辑

@fengmk2 fengmk2 added the enhancement New feature or request label May 9, 2024
@fengmk2 fengmk2 changed the title feat(unpkg): support unpkg alias path access entry file #674 feat: support unpkg alias path access entry file #674 May 9, 2024
async #searchPossibleEntries(packageVersion: any, path: string) {
const possiblePath = [ `${path}.js`, `${path}.json`, `${path}/index.js` ];

const possibleFiles = possiblePath.map(pathItem => this.packageVersionFileService.showPackageVersionFile(packageVersion, pathItem));
Copy link
Member

@fengmk2 fengmk2 May 9, 2024

Choose a reason for hiding this comment

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

就按 npm package.json 的描述逻辑逐步尝试吧。
有 exports 的优先,
没有则看看 main,
再没有就是 index.js

Copy link
Contributor

Choose a reason for hiding this comment

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

好像有对应的类库的?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里可能不是 package 的入口,还可能是 package 下面某个文件夹的下面的文件。

比如:

// 这里实际上会找到  '@opentiny/vue-theme/theme/index.js
import { tinySmbTheme } from '@opentiny/vue-theme/theme'

所以我参考 unpkg findEntry 的逻辑。按顺序尝试匹配 ${path}.js${path}.json${path}/index.js${path}/index.json

@chilingling
Copy link
Contributor Author

我想请问下:

  1. 有没有 beta 环境之类的?我想看看在 import-map 场景下使用 unpkg 特性还会不会有什么问题
  2. 编写测试用例有指导文档吗?我加几个测试用例。

@fengmk2 @atian25

@atian25
Copy link
Contributor

atian25 commented May 9, 2024

写单测,以及本地跑 docker 就可以了?

@chilingling
Copy link
Contributor Author

写单测,以及本地跑 docker 就可以了?

单测本地应该没问题,但是测试在 import-map 场景下的使用能力可能要同步太多 package 到本地,有点费劲

@fengmk2
Copy link
Member

fengmk2 commented May 9, 2024

我想请问下:

  1. 有没有 beta 环境之类的?我想看看在 import-map 场景下使用 unpkg 特性还会不会有什么问题
  2. 编写测试用例有指导文档吗?我加几个测试用例。

@fengmk2 @atian25

参考现有的单测用例写吧。

@chilingling
Copy link
Contributor Author

我想请问下:

  1. 有没有 beta 环境之类的?我想看看在 import-map 场景下使用 unpkg 特性还会不会有什么问题
  2. 编写测试用例有指导文档吗?我加几个测试用例。

@fengmk2 @atian25

参考现有的单测用例写吧。

OK,这种推单测用例上来

@chilingling chilingling marked this pull request as ready for review May 14, 2024 07:38
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: 1

Out of diff range and nitpick comments (2)
app/port/controller/PackageVersionFileController.ts (2)

148-149: Remove unnecessary blank line.

The blank line between the variable declaration and the following code is unnecessary and can be removed for better readability.


151-152: Remove unnecessary blank line.

The blank line between the if statement and the following code is unnecessary and can be removed for better readability.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cedb959 and a8afe89.
Files selected for processing (3)
  • app/port/controller/PackageVersionFileController.ts (2 hunks)
  • test/fixtures/@cnpm/test-find-entry/package.json (1 hunks)
  • test/port/controller/PackageVersionFileController/listFiles.test.ts (1 hunks)
Files not reviewed due to errors (1)
  • test/port/controller/PackageVersionFileController/listFiles.test.ts (no review received)
Files skipped from review due to trivial changes (1)
  • test/fixtures/@cnpm/test-find-entry/package.json
Additional comments not posted (1)
app/port/controller/PackageVersionFileController.ts (1)

184-195: Ensure all possible paths are covered.

Verify that the list of possible paths covers all common cases. If there are additional common cases, consider adding them to the list.

@chilingling
Copy link
Contributor Author

@atian25 @fengmk2 大佬们下午好,单元测试加了,麻烦看看这样加是不是正确的,有问题 Or review我及时改。

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a8afe89 and 72bd7d5.
Files selected for processing (3)
  • app/port/controller/PackageVersionFileController.ts (2 hunks)
  • test/fixtures/@cnpm/test-find-entry/package.json (1 hunks)
  • test/port/controller/PackageVersionFileController/listFiles.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • app/port/controller/PackageVersionFileController.ts
  • test/fixtures/@cnpm/test-find-entry/package.json
  • test/port/controller/PackageVersionFileController/listFiles.test.ts

Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -352,5 +352,41 @@ describe('test/port/controller/PackageVersionFileController/listFiles.test.ts',
assert.equal(called, 1);
assert.equal(resList.filter(res => res.status === 409 && res.body.error === '[CONFLICT] Package version file sync is currently in progress. Please try again later.').length, 1);
});
it('should redirect to possible entry', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

单测挂了,看看

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我再看看

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
我想请问下 cnpmcore 对 redis 版本有要求吗?我用的 redis-server 5.0.7,在 window 和 wsl 下都有上面的报错。看起来像是 redis 版本有问题?
@fengmk2

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/cnpm/cnpmcore/blob/master/docs/setup.md 安装的是最新版本 redis server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

确实是版本的问题,现在修复了。麻烦大佬再点一下同意跑跑GitHub的单测。
@fengmk2

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 72bd7d5 and e5fa2a3.
Files selected for processing (1)
  • test/port/controller/PackageVersionFileController/listFiles.test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • test/port/controller/PackageVersionFileController/listFiles.test.ts

@fengmk2 fengmk2 merged commit a51891d into cnpm:master May 16, 2024
10 checks passed
fengmk2 pushed a commit that referenced this pull request May 16, 2024
[skip ci]

## [3.58.0](v3.57.0...v3.58.0) (2024-05-16)

### Features

* support unpkg alias path access entry file [#674](#674) ([#675](#675)) ([a51891d](a51891d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨[Feature request] Support for unpkg-like auto-redirection capabilities
3 participants