Skip to content

fix: 优化获取web.config路径的逻辑,简化代码结构#663

Merged
ikenxuan merged 3 commits into
mainfrom
fix/npm-web-config-dev-path
Jul 4, 2026
Merged

fix: 优化获取web.config路径的逻辑,简化代码结构#663
ikenxuan merged 3 commits into
mainfrom
fix/npm-web-config-dev-path

Conversation

@ikenxuan

@ikenxuan ikenxuan commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Summary by Sourcery

调整 web.config 路径解析,以更好地处理不同的插件类型和运行环境,同时简化查找逻辑。

Bug 修复:

  • 确保基于 npmnode_modules 的插件在开发环境中也始终使用已发布的 web.config 输出,避免错误地解析到 ts-web 配置。
  • 对本地 TypeScript 运行时插件,在可用时优先使用 ts-web 配置,并在必要时回退到编译后的 web.config

改进:

  • web.config 路径计算重构为可复用的辅助方法,以获得更清晰的结构并减少重复代码。
Original summary in English

Summary by Sourcery

Adjust web.config path resolution to better handle different plugin types and runtime environments while simplifying the lookup logic.

Bug Fixes:

  • Ensure npm and node_modules-based plugins always use the published web config output even in development, avoiding incorrect ts-web resolution.
  • Prefer ts-web config for local TypeScript runtime plugins when available, falling back to the compiled web config when necessary.

Enhancements:

  • Refactor web.config path computation into a reusable helper for cleaner structure and reduced duplication.

Summary by CodeRabbit

  • Bug Fixes
    • Improved how the app locates and loads web configuration for different plugin setups.
    • Fixed fallback behavior so local development and packaged plugins use the most appropriate configuration automatically.
    • Plugins without web configuration are now safely ignored instead of causing lookup issues.

@sourcery-ai

sourcery-ai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

重构解析插件 web.config(或等价配置)绝对路径的逻辑,以适配通过 npm 安装的插件、本地 TypeScript 运行时以及共享的路径解析方式,并简化代码结构。

更新后的 getWebConfigPath 路径解析逻辑流程图

flowchart TD
  A["getWebConfigPath(plugin)"] --> B["pkg = plugin.pkgData"]
  B --> C{"pkg.karin exists?"}
  C -->|no| Z["return null"]
  C -->|yes| D{"plugin.type === npm or plugin.dir includes node_modules"}

  D -->|yes| E["getPath(pkg.karin.web)"]
  E --> F{"fs.existsSync(path.join(plugin.dir, pkg.karin.web))?"}
  F -->|yes| G["return web path"]
  F -->|no| Z

  D -->|no| H{"isTs()"}
  H -->|yes| I["getPath(pkg.karin.ts-web)"]
  I --> J{"fs.existsSync(path.join(plugin.dir, pkg.karin.ts-web))?"}
  J -->|yes| K["return ts-web path"]
  J -->|no| L["getPath(pkg.karin.web)"]

  H -->|no| L
  L --> M{"fs.existsSync(path.join(plugin.dir, pkg.karin.web))?"}
  M -->|yes| G
  M -->|no| Z
Loading

File-Level Changes

Change Details Files
重构 web 配置路径解析,以支持 npm 插件、TypeScript 运行时和共享存在性检查,同时简化控制流。
  • 从 environment 模块导入 isTs,用于检测是否处于 TypeScript 运行时
  • 当 plugin.pkgData.karin 缺失时提前返回,而不是深入检查其 web 属性
  • 引入可复用的 getPath 帮助函数,将插件目录与给定相对路径拼接并验证文件是否存在
  • 新增针对 npm 或 node_modules 插件的特殊处理,使其总是解析到已发布的 web 入口文件,而不受开发环境影响
  • 更新本地源码插件逻辑,在 TypeScript 运行时优先使用 ts-web,当 ts-web 缺失或不存在时回退到 web
  • 移除之前的开发模式分支和内联 fs.existsSync 调用,改为使用集中式的辅助函数
packages/core/src/server/plugins/config/webConfig.ts

Possibly linked issues

  • #Bug: 开发环境获取web配置文件失败: PR 重写 web.config 路径选择逻辑,修复开发环境 npm 与源码插件配置读取错误,与 issue 吻合

Tips and commands

Interacting with Sourcery

  • 触发新的代码审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复审查评论,要求 Sourcery 从该评论创建一个 issue。你也可以直接回复审查评论并写上 @sourcery-ai issue 来创建对应的 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成一个标题。你也可以在 pull request 中评论 @sourcery-ai title 来随时(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文的任意位置写上 @sourcery-ai summary,即可在你指定的位置随时生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来随时(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 批量解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,可标记解决所有 Sourcery 评论。如果你已经处理完所有评论且不再需要看到它们,这会很有用。
  • 批量忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,可忽略所有现有的 Sourcery 审查。特别适合你想在新的审查中“重新开始”——别忘了再评论 @sourcery-ai review 来触发新的审查!

Customizing Your Experience

访问你的 dashboard 以:

  • 启用或停用审查特性,例如 Sourcery 生成的 pull request 摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查相关设置。

Getting Help

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the logic for resolving the absolute path to a plugin's web.config (or equivalent) to account for npm-installed plugins, local TypeScript runtime, and shared path resolution, simplifying the code structure.

Flow diagram for updated getWebConfigPath resolution logic

flowchart TD
  A["getWebConfigPath(plugin)"] --> B["pkg = plugin.pkgData"]
  B --> C{"pkg.karin exists?"}
  C -->|no| Z["return null"]
  C -->|yes| D{"plugin.type === npm or plugin.dir includes node_modules"}

  D -->|yes| E["getPath(pkg.karin.web)"]
  E --> F{"fs.existsSync(path.join(plugin.dir, pkg.karin.web))?"}
  F -->|yes| G["return web path"]
  F -->|no| Z

  D -->|no| H{"isTs()"}
  H -->|yes| I["getPath(pkg.karin.ts-web)"]
  I --> J{"fs.existsSync(path.join(plugin.dir, pkg.karin.ts-web))?"}
  J -->|yes| K["return ts-web path"]
  J -->|no| L["getPath(pkg.karin.web)"]

  H -->|no| L
  L --> M{"fs.existsSync(path.join(plugin.dir, pkg.karin.web))?"}
  M -->|yes| G
  M -->|no| Z
Loading

File-Level Changes

Change Details Files
Refactor web config path resolution to handle npm plugins, TypeScript runtime, and shared existence checks while simplifying control flow.
  • Import isTs from the environment module to detect TypeScript runtime
  • Early-return when plugin.pkgData.karin is missing instead of checking nested web property
  • Introduce a reusable getPath helper to join plugin directory with a given relative path and verify file existence
  • Add special handling so npm or node_modules plugins always resolve the published web entry, regardless of dev environment
  • Update local source plugin logic to prefer ts-web in TypeScript runtime, falling back to web when ts-web is absent or missing
  • Remove previous dev-mode branching and inline fs.existsSync checks in favor of the centralized helper
packages/core/src/server/plugins/config/webConfig.ts

Possibly linked issues

  • #Bug: 开发环境获取web配置文件失败: PR重写web.config路径选择逻辑,修复开发环境npm与源码插件配置读取错误,与issue吻合

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ikenxuan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44c7ece3-0913-405c-bccd-a3bb1cd50bd4

📥 Commits

Reviewing files that changed from the base of the PR and between d4f1132 and f695618.

📒 Files selected for processing (1)
  • packages/core/src/server/plugins/config/webConfig.ts
📝 Walkthrough

Walkthrough

The getWebConfigPath function in webConfig.ts was refactored to select web config artifacts based on plugin origin and TypeScript mode. It now imports isTs, adds a getPath helper, and prefers pkg.karin['ts-web'] for local plugins under TypeScript while npm/node_modules plugins always use pkg.karin.web.

Changes

Web Config Path Selection

Layer / File(s) Summary
Refactor web config artifact selection
packages/core/src/server/plugins/config/webConfig.ts
Imports isTs, introduces a getPath helper guarded by fs.existsSync, and updates getWebConfigPath to return pkg.karin.web for npm/node_modules plugins, pkg.karin['ts-web'] for local plugins under isTs(), and fall back to pkg.karin.web otherwise.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • KarinJS/Karin#654: Both PRs modify getWebConfigPath and related plugin WebUI config loading logic in the same file.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: improving web.config path resolution and simplifying the code structure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/npm-web-config-dev-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - 我已经审查了你的修改,它们看起来非常棒!


Sourcery 对开源项目是免费的——如果你喜欢我们的代码审查,请考虑分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据这些反馈来改进你的代码审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the getWebConfigPath function in webConfig.ts to improve path resolution for npm plugins and local source plugins, prioritizing ts-web in TypeScript environments. The review feedback suggests enhancing robustness by using optional chaining when accessing pkg.karin and adding type validation in the getPath helper to ensure the path value is a valid non-empty string.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/core/src/server/plugins/config/webConfig.ts Outdated
Comment thread packages/core/src/server/plugins/config/webConfig.ts
ikenxuan and others added 2 commits July 4, 2026 16:51
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

你可以通过以下命令安装该版本:

pnpm add https://pkg.pr.new/node-karin@f695618 -w

@ikenxuan ikenxuan merged commit 6ce06d5 into main Jul 4, 2026
5 checks passed
@ikenxuan ikenxuan deleted the fix/npm-web-config-dev-path branch July 4, 2026 08:54
@github-actions github-actions Bot mentioned this pull request Jun 28, 2026
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.

1 participant