uni-helper / vite-plugin-uni-layouts

为 Vite 下的 uni-app 提供类 nuxt 的 layouts 系统
MIT License
25 stars 6 forks source link

fix: fix HBuilderX compatibility #39

Closed Xiphin closed 2 months ago

Xiphin commented 2 months ago

解决优化: issues: https://github.com/uni-helper/vite-plugin-uni-layouts/issues/36 pr: https://github.com/uni-helper/vite-plugin-uni-layouts/pull/37 提到的 路径 和 HBuilderX 环境兼容的问题

Summary by CodeRabbit

coderabbitai[bot] commented 2 months ago

Walkthrough

The recent changes involve enhancing the Context class in src/context.ts with a new pageJsonPath property, updating its usage in various methods, and adjusting the behavior in loadPagesJson function in src/utils.ts to align with CLI mode checks. Additionally, a new buildStart method was introduced in the VitePluginUniLayouts function in src/index.ts to handle setting ctx.pageJsonPath based on options.

Changes

File Path Change Summary
src/context.ts Added pageJsonPath property to Context class with updated usage
src/index.ts Introduced buildStart method in VitePluginUniLayouts function
src/utils.ts Modified loadPagesJson to check CLI mode for pageJsonPath

In the code's dance, a tale unfolds, Paths and modes, their story told. With tweaks and tunes, our code refines, A rabbit's touch, in lines it shines. CLI whispers, paths align, Code evolves, a tale 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
Skiyee commented 2 months ago

https://github.com/Skiyee/vite-plugin-uni-layouts/commit/84e6bc41ba6fb1dea1eb76c4d46eef7a795242f3

刚才有试着从 vite 入手,抛弃 existsSync ,应该能保证是否为CLI创建的项目,可以看一下

Xiphin commented 2 months ago

Skiyee@84e6bc4

刚才有试着从 vite 入手,抛弃 existsSync ,应该能保证是否为CLI创建的项目,可以看一下

不考虑正则效率的问题,这个设计更合理

Xiphin commented 2 months ago

Skiyee@84e6bc4

刚才有试着从 vite 入手,抛弃 existsSync ,应该能保证是否为CLI创建的项目,可以看一下

你再兼容一下用户配置传参的问题,就可以 PR 了

Skiyee commented 2 months ago

会是自动检测的,不需要配置 原理就是判断 src 下是否有这个 main 文件,若有自动识别为 cli 的路径

Skiyee commented 2 months ago

这个replace性能还可以,因为是对字符串操作,其次就是整个周期只操作一次

Xiphin commented 2 months ago

Skiyee@84e6bc4

会是自动检测的,不需要配置 原理就是判断 src 下是否有这个 main 文件,若有自动识别为 cli 的路径

buidStart 自动检测 没问题,我说的是当用户配置了一个 pagesJsonPath 选项的情况下,自动检测会直接覆盖掉它。

Xiphin commented 2 months ago

这个replace性能还可以,因为是对字符串操作,其次就是整个周期只操作一次

https://github.com/uni-helper/vite-plugin-uni-layouts/blob/4ca0e5dbe343ff3b1c76b6c752ddf9e8d8e06000/src/context.ts#L49 https://github.com/uni-helper/vite-plugin-uni-layouts/blob/4ca0e5dbe343ff3b1c76b6c752ddf9e8d8e06000/src/utils.ts#L49 getTarget 函数是每个项目文件编译时都会走一遍,应该是 N 次调用

Skiyee commented 2 months ago

没关系的,约定没有 pagesJsonPath,出错就是用户自己配置的问题了

没有N次调用,识别 是否为CLI创建 只做一次

Xiphin commented 2 months ago

没关系的,约定没有 pagesJsonPath,出错就是用户自己配置的问题了

没有N次调用,识别 是否为CLI创建 只做一次

LGTM 💖

Xiphin commented 2 months ago

@Skiyee 我把你的提交合过来了 你看一下

Skiyee commented 2 months ago

我来发吧,这边有开着的PR

Xiphin commented 2 months ago

重开一个 PR:https://github.com/uni-helper/vite-plugin-uni-layouts/pull/40

Skiyee commented 2 months ago

谢谢大佬一起讨论 ❤

Xiphin commented 2 months ago

没关系的,约定没有 pagesJsonPath,出错就是用户自己配置的问题了

没有N次调用,识别 是否为CLI创建 只做一次

@Skiyee 我刚去验证了一下 slash 函数是 N 次调用,不过这点性能问题可以忽略不计

Skiyee commented 2 months ago

@Skiyee 我刚去验证了 slash 函数是 N 次调用,不过这点性能问题可以忽略不计

是的

slash 是在 getTarget 里头的,由于所有路径都需要被转换

每次热更新都会被 .vue|.nvue 结尾的文件路径所调用

这个replace性能还OK,pages那个仓库就有用到类似的工具函数

Xiphin commented 2 months ago

@Skiyee 我刚去验证了 slash 函数是 N 次调用,不过这点性能问题可以忽略不计

是的

slash 是在 getTarget 里头的,由于所有路径都需要被转换

每次热更新都会被 .vue|.nvue 结尾的文件路径所调用

这个replace性能还OK,pages那个仓库就有用到类似的工具函数

挺好的 👍