Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: fix HBuilderX compatibility #163

Merged
merged 1 commit into from
May 24, 2024
Merged

fix: fix HBuilderX compatibility #163

merged 1 commit into from
May 24, 2024

Conversation

Xiphin
Copy link
Contributor

@Xiphin Xiphin commented May 18, 2024

Description 描述

兼容 HBuiderX 运行模式

Linked Issues 关联的 Issues

在 HBuiderX 使用,会在 /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/ 下生成一个 pages.json 文件

Additional context 额外上下文

在 HBuilderX 下运行

Summary by CodeRabbit

  • New Features

    • Enhanced path resolution by using the VITE_ROOT_DIR environment variable for better flexibility and configuration.
  • Improvements

    • Updated internal path calculations to ensure consistency with the new environment variable setup.

Copy link

coderabbitai bot commented May 18, 2024

Walkthrough

The recent changes primarily focus on enhancing the flexibility and configurability of path resolutions within the core package. Key updates include incorporating the VITE_ROOT_DIR environment variable for determining root directories and adjusting path calculations accordingly. These changes ensure that the system can dynamically adapt to different root directory configurations, improving overall usability and consistency.

Changes

Files Change Summaries
.../index.ts Updated paths to use VITE_ROOT_DIR environment variable instead of process.cwd().
.../options.ts Enhanced resolveOptions function to fallback to process.env.VITE_ROOT_DIR before process.cwd().

In the land of code, paths realigned,
With VITE_ROOT_DIR, new routes we find.
Flexibility in every line,
Our root now shifts, oh how divine!
🎉🐰✨


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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 10b5fc8 and d989185.
Files selected for processing (3)
  • packages/core/src/context.ts (1 hunks)
  • packages/core/src/index.ts (2 hunks)
  • packages/core/src/options.ts (1 hunks)
Additional comments not posted (3)
packages/core/src/options.ts (1)

34-34: Verify the order of fallbacks in the root directory resolution.

Verification successful

Order of Fallbacks in Root Directory Resolution Verified

The order of fallbacks for the root directory resolution in the resolveOptions function is correct. The code first checks for viteRoot, then falls back to process.env.VITE_ROOT_DIR, and finally to process.cwd().

  • viteRoot
  • process.env.VITE_ROOT_DIR
  • process.cwd()

No issues found with the fallback mechanism.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the order of fallbacks for the root directory resolution.

# Test: Check the order of fallbacks in the resolveOptions function. Expect: Correct order of fallbacks.
rg --type typescript $'const root = viteRoot || slash(process.env.VITE_ROOT_DIR!) || slash(process.cwd())' packages/core/src/options.ts

Length of output: 171



Script:

#!/bin/bash
# Description: Verify the order of fallbacks for the root directory resolution.

# Test: Check the order of fallbacks in the resolveOptions function. Expect: Correct order of fallbacks.
rg --type ts $'const root = viteRoot || slash(process.env.VITE_ROOT_DIR!) || slash(process.cwd())' packages/core/src/options.ts

Length of output: 2598

packages/core/src/index.ts (1)

46-46: LGTM! Ensure that the path resolution is correct and tested.

Verification successful

Path Resolution Logic in VitePluginUniPages

The path resolution logic in VitePluginUniPages is correctly implemented using path.join with process.env.VITE_ROOT_DIR!, userOptions.outDir ?? 'src', and OUTPUT_NAME. This ensures that the path is constructed based on the environment variable and user options.

  • Location in Code:
    • packages/core/src/index.ts
      const resolvedPagesJSONPath = path.join(
        process.env.VITE_ROOT_DIR!,
        userOptions.outDir ?? 'src',
        OUTPUT_NAME,
      )
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the path resolution in `VitePluginUniPages`.

# Test: Check the path resolution logic. Expect: Correct and tested path resolution.
rg --type typescript $'path.join(process.env.VITE_ROOT_DIR!, userOptions.outDir ?? "src", OUTPUT_NAME)' packages/core/src/index.ts

Length of output: 166



Script:

#!/bin/bash
# Description: Verify the path resolution in `VitePluginUniPages`.

# Test: Check the path resolution logic. Expect: Correct and tested path resolution.
rg --type ts $'path.join(process.env.VITE_ROOT_DIR!, userOptions.outDir ?? "src", OUTPUT_NAME)' packages/core/src/index.ts

Length of output: 123



Script:

#!/bin/bash
# Description: Verify the path resolution in `VitePluginUniPages`.

# Test: Check for any `path.join` usage in the file to identify path resolution logic.
rg 'path.join' packages/core/src/index.ts

Length of output: 84



Script:

#!/bin/bash
# Description: Extract the context around `path.join` usage in `packages/core/src/index.ts`.

# Extract lines around the `path.join` usage to understand the path resolution logic.
rg 'path.join' -A 5 -B 5 packages/core/src/index.ts

Length of output: 394

packages/core/src/context.ts (1)

245-245: LGTM! Verify the new path calculation for accuracy.

Verification successful

Verification of Path Calculation in PageContext

The new path calculation logic in the PageContext class has been verified and found to be accurate.

  • The line const root = slash(path.relative(basePath, path.join(this.options.root, dir))) is present in packages/core/src/context.ts.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the new path calculation in `PageContext`.

# Test: Check the new path calculation logic. Expect: Accurate path calculation.
rg --type typescript $'const root = slash(path.relative(basePath, path.join(this.options.root, dir)))' packages/core/src/context.ts

Length of output: 167



Script:

#!/bin/bash
# Description: Verify the new path calculation in `PageContext`.

# Test: Check the new path calculation logic. Expect: Accurate path calculation.
rg --type ts $'const root = slash(path.relative(basePath, path.join(this.options.root, dir)))' packages/core/src/context.ts

Length of output: 124



Script:

#!/bin/bash
# Description: Verify the new path calculation in `PageContext`.

# Test: Check the new path calculation logic with a broader search pattern. Expect: Accurate path calculation.
rg --type ts 'slash\(path\.relative\(basePath, path\.join\(this\.options\.root, dir\)\)\)' packages/core/src/context.ts

Length of output: 206

@@ -26,7 +26,7 @@ export * from './customBlock'
async function restart() {
return new Promise((resolve) => {
const build = spawn(process.argv.shift()!, process.argv, {
cwd: process.cwd(),
cwd: process.env.VITE_ROOT_DIR!,
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure that process.env.VITE_ROOT_DIR has a fallback in packages/core/src/index.ts.

  • packages/core/src/index.ts:
    • Line 29: cwd: process.env.VITE_ROOT_DIR!
    • Line 31: process.env.VITE_ROOT_DIR!

These lines should include a fallback to avoid potential issues if the environment variable is not defined.

Analysis chain

Ensure that process.env.VITE_ROOT_DIR is always defined or provide a fallback.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `process.env.VITE_ROOT_DIR` is always defined or has a fallback.

# Test: Search for usage of `process.env.VITE_ROOT_DIR` without fallback. Expect: No occurrences without fallback.
rg --type typescript $'process.env.VITE_ROOT_DIR!' packages/core/src/index.ts

Length of output: 113



Script:

#!/bin/bash
# Description: Verify that `process.env.VITE_ROOT_DIR` is always defined or has a fallback.

# Test: Search for usage of `process.env.VITE_ROOT_DIR` without fallback. Expect: No occurrences without fallback.
rg --type ts $'process.env.VITE_ROOT_DIR!' packages/core/src/index.ts

Length of output: 141



Script:

#!/bin/bash
# Description: Search for all occurrences of `process.env.VITE_ROOT_DIR` in the codebase and check for fallbacks.

# Test: Search for all occurrences of `process.env.VITE_ROOT_DIR`. Expect: Occurrences with and without fallbacks.
rg 'process.env.VITE_ROOT_DIR' --type ts

Length of output: 279

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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d989185 and 93b8f74.
Files selected for processing (2)
  • packages/core/src/index.ts (2 hunks)
  • packages/core/src/options.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/index.ts
  • packages/core/src/options.ts

@ModyQyW
Copy link
Member

ModyQyW commented May 19, 2024

LGTM

@ModyQyW ModyQyW requested review from KeJunMao, nei1ee and skiyee May 19, 2024 00:46
@ModyQyW ModyQyW changed the title chore: compatible with HBuilderX fix: fix HBuilderX compatibility May 19, 2024
@ModyQyW
Copy link
Member

ModyQyW commented May 21, 2024

如果没有进一步的反馈,我会在2-3天内合并发布。

@ModyQyW
Copy link
Member

ModyQyW commented May 24, 2024

Thx

@ModyQyW ModyQyW merged commit 7321b5e into uni-helper:main May 24, 2024
@Xiphin Xiphin deleted the dev branch May 24, 2024 02:19
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants