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: handle dumi file path #12350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

s1v
Copy link

@s1v s1v commented May 2, 2024

Description

Fixed an error that occurred when running pnpm umi plugin list

Motivation

.dumi file path is not handled correctly

Summary by CodeRabbit

  • 新功能
    • 更新了路径处理功能,现在可以更准确地识别和处理以 '.''/' 开头的路径字符串。

Copy link

vercel bot commented May 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
umi ⬜️ Ignored (Inspect) Visit Preview May 2, 2024 2:29am

Copy link

coderabbitai bot commented May 2, 2024

漫步解读

此次更新主要对 routes.ts 文件中的 localPath 函数进行了修改,增强了路径字符串的检查逻辑。现在,该函数会检查路径字符串的开头是否为 '.''/',如果不是,则会自动添加 './'

变更

文件路径 变更摘要
packages/.../routes.ts localPath 函数增强了路径字符串的开头检查逻辑。

🐰
小兔乖乖,代码跳跳,
更新一下,错误少少。
路径检查,多了个斜,
代码安全,心情好。


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d16471a and 4feff25.
Files selected for processing (1)
  • packages/preset-umi/src/features/tmpFiles/routes.ts (2 hunks)

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.

Copy link

@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: 2

@@ -17,7 +17,7 @@ export async function getApiRoutes(opts: { api: IApi }) {
});

function localPath(path: string) {
if (path.charAt(0) !== '.') {
if (path.charAt(0) !== '.' || path.charAt(1) !== '/') {
Copy link

Choose a reason for hiding this comment

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

请确保在访问 path.charAt(1) 之前,字符串长度至少为2。

-    if (path.charAt(0) !== '.' || path.charAt(1) !== '/') {
+    if (path.length > 1 && (path.charAt(0) !== '.' || path.charAt(1) !== '/')) {
      return `./${path}`;
    }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (path.charAt(0) !== '.' || path.charAt(1) !== '/') {
if (path.length > 1 && (path.charAt(0) !== '.' || path.charAt(1) !== '/')) {

@@ -79,7 +79,7 @@ export async function getRoutes(opts: {
}

function localPath(path: string) {
if (path.charAt(0) !== '.') {
if (path.charAt(0) !== '.' || path.charAt(1) !== '/') {
Copy link

Choose a reason for hiding this comment

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

请确保在访问 path.charAt(1) 之前,字符串长度至少为2。

-    if (path.charAt(0) !== '.' || path.charAt(1) !== '/') {
+    if (path.length > 1 && (path.charAt(0) !== '.' || path.charAt(1) !== '/')) {
      return `./${path}`;
    } else {
      return path;
    }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (path.charAt(0) !== '.' || path.charAt(1) !== '/') {
if (path.length > 1 && (path.charAt(0) !== '.' || path.charAt(1) !== '/')) {
return `./${path}`;
} else {
return path;
}

@fz6m
Copy link
Member

fz6m commented May 2, 2024

这个是用在哪个用例上啊,有详细上下文吗,什么情况会发生错误。

@s1v
Copy link
Author

s1v commented May 7, 2024

@fz6m Thank you for your confirmation.
This issue is sure to occur. This is because the .dumi directory exists within the source.

The following is the error log.

$ pnpm umi plugin list
info  - @local
fatal - Error: Cannot find module '.dumi/tmp/dumi/theme/slots/PreviewerActionsExtra.ts' from '/Users/user/Projects/github/umijs/umi/docs'
    at Function.resolveSync [as sync] (/Users/user/Projects/github/umijs/umi/packages/utils/compiled/resolve/index.js:1:12304)
    at Proxy.getRoutes (/Users/user/Projects/github/umijs/umi/packages/preset-umi/dist/features/tmpFiles/routes.js:138:37)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Hook.fn (/Users/user/Projects/github/umijs/umi/packages/preset-umi/dist/features/appData/appData.js:51:19)
    at async /Users/user/Projects/github/umijs/umi/packages/core/dist/service/service.js:136:27 {
  code: 'MODULE_NOT_FOUND'
}
fatal - A complete log of this run can be found in:
fatal - /Users/user/Projects/github/umijs/umi/node_modules/.cache/logger/umi.log
fatal - Consider reporting a GitHub issue on https://github/umijs/umi/issues
fatal - 如果你需要进交流群,请访问 https://fb.umijs.org 。

@fz6m
Copy link
Member

fz6m commented May 9, 2024

dumi 的项目是没有 umi 这个命令的,只有 dumi 这个命令。

我初始化了一个 dumi 项目,运行 pnpm dumi plugin list 是正常输出的。

如有问题,给一个最小复现吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants