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: 声明 loader 包、加载器增加默认值、声明 env 包 #16

Merged
merged 3 commits into from
Oct 24, 2024

Conversation

waset
Copy link
Owner

@waset waset commented Oct 24, 2024

Summary by CodeRabbit

  • 新功能

    • 扩展了@waset/unplugin-iconify包的关键词,增强了可发现性。
    • 新增模块导出,支持astroesbuildfarmrspackloader,提升了模块的使用灵活性。
    • Iconify类的默认输出路径已更新为动态配置,增强了灵活性。
    • UnocssLoadergetOutputFiles函数支持默认参数,简化了使用方式。
  • 修复

    • 修正了public字段的拼写错误,确保包发布配置正确。
  • 文档

    • 更新了README.md文件,增加了中文翻译,提升了对中文用户的可访问性。

Copy link

coderabbitai bot commented Oct 24, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

在此次变更中,@waset/unplugin-iconifypackage.json 文件进行了多项修改。keywords 数组被扩展,增加了新的关键词,以提高包的可发现性。此外,exports 部分新增了多个模块的导入和引用路径。public 字段的拼写错误已被修正,确保了包发布的正确配置。整体而言,这些更改增强了模块支持并进行了小幅配置修正。

Changes

文件 更改摘要
package.json - keywords 新增: "astro", "esbuild", "rspack", "loader", "farm", "unocss"
- 新增导出: "./astro", "./esbuild", "./farm", "./rspack", "./loader",各自指定 importrequire 路径
- public 字段修正为 "public": true
- publishConfig 指定包应以公共访问发布
README.md - 安装和配置部分翻译为中文,增加中文注释
- 更新 convert 配置对象的路径
- 使用部分标题翻译为中文,增加新子部分
src/core/index.ts - 更新 defaultOptions 中的 output 字段,引用 OUTPUT 常量
src/env.ts - 新增常量 OUTPUT,值为 'node_modules/.unplugin-iconify'
src/loader.ts - 更新 UnocssLoadergetOutputFiles 函数的参数,使用 OUTPUT 常量作为默认值

Possibly related PRs

Suggested labels

enhancement

在代码的海洋中,
我们扬帆起航,
新的关键词如星星闪耀,
模块支持更强大,
小小修正如春风拂面,
让我们一起欢呼,
代码的未来更美好! 🎉


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@github-actions github-actions bot added the bugfix 修复漏洞 label Oct 24, 2024
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

🧹 Outside diff range and nitpick comments (1)
package.json (1)

Line range hint 155-155: 哎呀呀,这里有个可爱的小拼写错误!

瞧瞧这个可爱的小typo:"pubilc": true!这简直就像我第一次试图念"Chimichangas"时一样搞笑!让我们把它改正过来吧!

-  "pubilc": true,
+  "public": true,

别担心,我们都会犯错,就像我有时候会不小心炸掉不该炸的东西一样... 😅

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 314a766 and 8baee25.

📒 Files selected for processing (1)
  • package.json (2 hunks)
🔇 Additional comments (3)
package.json (3)

26-32: 嘿嘿,关键词大军来袭!

哇哦!看看这些新增的关键词,简直就像我的武器库一样丰富多彩!astroesbuildrspackloaderfarmunocss,每一个都闪闪发光!这波操作绝对能让你的包在 npm 上更容易被发现,就像我在漫威宇宙中一样出名!🎯


76-78: 终于!loader 模块露出真面目啦!

漂亮!这就是我们要找的那个神秘的 loader 包!现在它终于有了正式的出场方式:

"./loader": {
  "import": "./dist/loader.js",
  "require": "./dist/loader.cjs"
}

完美解决了 PR 标题中提到的"未声明 loader 包"的问题。就像我说的,每个演员都需要他们的特写镜头,现在 loader 终于有了属于自己的主场!🎬


Line range hint 1-158: 让我们确认一下所有声明的模块都有对应的文件!

作为一个注重细节的雇佣兵(咳咳,我是说代码审查员),我们得确保所有在 exports 中声明的模块都有对应的实现文件。毕竟没人想要遇到 404 Not Found,那比遇到 Francis 还要糟糕!

✅ Verification successful

嘿嘿,好消息!所有模块都完美对应,就像我和小蜘蛛的bromance一样配!

哇哦!让我给你们解释一下这个超赞的发现:

  • 所有在 package.json 中声明的模块(astroesbuildfarmrspackloader 等)都在 src/ 目录下有对应的 .ts 文件
  • tsup 配置文件完美处理了所有构建需求:
    • 把所有 src/**/*.ts 文件都编译成 cjsesm 格式
    • 生成类型声明文件(dts: true
    • 构建完成后还会执行 build:fix 脚本来处理 CommonJS 模块的兼容性

啧啧,这构建系统比我的愈合因子还靠谱!所有声明的模块都会被正确构建到 dist/ 目录,就像 Colossus 的金属皮肤一样坚不可摧!🤘

顺便说一句,那个后处理脚本简直就是双刀出鞘一样帅气,完美解决了 CommonJS 模块的导出问题。这代码写得,我都想给它一个小抱抱了!❤️

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查所有声明的模块文件是否存在
echo "🔍 检查声明的模块文件..."
for module in astro esbuild farm rspack loader; do
  fd -e js -e cjs "^${module}\.(js|cjs)$" dist/
done

Length of output: 973


Script:

#!/bin/bash
# 让我们看看源代码目录里都有什么好东西
echo "🔍 检查源码目录中的模块文件..."
fd -e ts "^(astro|esbuild|farm|rspack|loader|nuxt|rollup|vite|webpack)\.(ts)$" src/

echo -e "\n📦 检查 package.json 中声明的构建脚本..."
cat package.json | jq -r '.scripts.build'

echo -e "\n🎯 检查 tsup 配置文件..."
fd -e ts "tsup.config" .

Length of output: 472


Script:

#!/bin/bash
# 让我们瞧瞧这个构建配置到底在搞什么鬼
echo "🎭 tsup 配置文件的内容是..."
cat tsup.config.ts

echo -e "\n🚀 让我们看看有没有构建后处理脚本..."
cat scripts/postbuild.ts 2>/dev/null || echo "没找到后处理脚本,有点可疑啊!"

Length of output: 1082

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 24, 2024
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

🧹 Outside diff range and nitpick comments (4)
src/loader.ts (1)

Line range hint 26-37: 嘿,这个函数需要一点我的特殊关照!

虽然默认参数很棒,但是亲爱的,我觉得这里的错误处理还可以更性感一点!就像我在打斗场景中总是准备各种备选方案一样~

来看看这个更带劲的版本:

 export function getOutputFiles(dir: string = OUTPUT): string[] {
   // 构建 manifest 文件路径
   const srcDir = join(cwd(), dir)
 
   if (!existsSync(srcDir)) {
-    console.error(`\x1B[31m UnocssLoader: ${srcDir} not exists! \x1B[0m`)
+    console.error(`\x1B[31m UnocssLoader: 糟糕!目录 ${srcDir} 不存在!别担心,我们还能继续!\x1B[0m`)
+    console.warn(`\x1B[33m 提示:请确保目录 ${dir} 已经正确创建。\x1B[0m`)
     return []
   }
 
-  const files = readdirSync(srcDir).filter(file => file.endsWith('.json'))
+  try {
+    const files = readdirSync(srcDir).filter(file => file.endsWith('.json'))
+    if (files.length === 0) {
+      console.warn(`\x1B[33m 警告:在 ${srcDir} 中没有找到任何 JSON 文件,这正常吗?🤔\x1B[0m`)
+    }
+    return files.map(file => join(srcDir, file))
+  } catch (error) {
+    console.error(`\x1B[31m 哎呀!读取目录时出错了:${error.message}\x1B[0m`)
+    return []
+  }
-  return files.map(file => join(srcDir, file))
 }

就像我说的,多一点错误处理,生活就会像我的漫画一样精彩!😉

src/core/index.ts (1)

Line range hint 77-82: 这个错误处理比我的脸还要简单!

嘿,伙计们!👋 我注意到这里的错误处理就跟我的独角兽玩偶一样简单(什么?你不知道我有独角兽玩偶?)。只是打印个 console.error 就完事了?

建议考虑以下几点改进:

  1. 添加错误类型区分
  2. 提供错误重试机制
  3. 考虑将错误传递给上层处理

来个示例代码:

  async toConvert(): Promise<void> {
    try {
      await Generateds(this.options)
    }
    catch (error) {
-     console.error('toConvert 出错了:', error)
+     const err = error instanceof Error ? error : new Error('Unknown error');
+     console.error('toConvert 出错了:', err.message);
+     throw new IconifyError('CONVERT_ERROR', err);
    }
  }

顺便说一句,这个类的职责比我的任务清单还要多!也许可以考虑把一些功能拆分出去?就像我的个性一样,总是可以分裂出不同的版本!😉

Also applies to: 93-98

README.md (2)

49-49: VSCode 配置说明很清晰!

漂亮!这段说明简单明了,就像我的双刀一样干脆利落!不过既然都说到 .vscode/settings.json 了,不如再贴个配置示例?

要不要我帮你写个配置示例?反正闲着也是闲着~


113-113: UnocssLoader 配置示例需要补充!

哎呀呀,这个 UnocssLoader(/** output */) 的注释也太敷衍了吧!就像我的电影里删减掉的精彩片段一样让人意犹未尽!

要不要我帮你写个更详细的示例?比如:

// 示例
UnocssLoader('dist/icons')  // 输出目录路径
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8baee25 and a5f1e71.

📒 Files selected for processing (5)
  • README.md (3 hunks)
  • package.json (3 hunks)
  • src/core/index.ts (2 hunks)
  • src/env.ts (1 hunks)
  • src/loader.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/env.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🪛 Markdownlint
README.md

55-55: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)

🔇 Additional comments (5)
src/loader.ts (2)

5-5: 哟,这不是我最爱的常量导入嘛!

嘿嘿,看到你把 OUTPUT 常量从 env 模块引入了!这就像我从武器库里取出我最爱的双刀一样顺滑~ 完美的选择,让代码更容易维护,就像我的自愈能力一样靠谱!


Line range hint 12-21: 默认参数!?天才般的改动!

哇哦!给 UnocssLoader 加上默认参数,这波操作太秀了!就像我的再生能力一样方便,不用的时候它就在那默默保护我~

不过作为一个负责任的雇佣兵,我建议确认一下其他地方是不是都能正确处理这个改动。毕竟我们可不想遇到比我脸还糟糕的意外,对吧?

✅ Verification successful

让我再检查一下 core/index.ts 中是如何使用这个函数的。


嘿嘿,这个默认参数简直完美!就像我最爱的墨西哥卷饼一样美味!

让我给你解释一下为什么这么说:在 core/index.ts 里,getLoaders 方法已经在使用默认参数 this.options.output 了,而这个值恰好就是我们的 OUTPUT 常量!这波改动简直是天衣无缝,就像我的自愈能力一样完美!

看看这个优雅的调用链:

  • getLoaders 默认使用 this.options.output
  • this.options.output 默认值就是 OUTPUT
  • 现在 UnocssLoader 也默认使用 OUTPUT

这简直就是一个完美的三明治!所有的默认值都完美对齐,没有任何副作用。就像我说的,这改动太棒了!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 让我们来看看谁在调用这个小可爱
rg "UnocssLoader\(" --type ts

Length of output: 183


Script:

#!/bin/bash
# 让我们看看 core/index.ts 中的具体使用情况
cat src/core/index.ts

Length of output: 2268

src/core/index.ts (2)

2-2: 导入语句看起来不错!

嘿嘿,看到你把硬编码的输出路径改成了常量,这波操作很帅!👍 把配置集中管理确实是明智之举,就像我的双刀一样,放对地方才好用!


19-19: 验证一下这个 OUTPUT 常量的使用情况!

哇哦!把硬编码的 'node_modules/.unplugin-iconify' 替换成 OUTPUT 常量,这操作可以说是相当明智了!但是作为一个专业的雇佣兵(咳咳,我是说代码审查员),我觉得我们最好确认一下这个常量在其他地方的使用情况。

让我们来查查这个 OUTPUT 到底在哪些地方露过面:

顺便说一句,这个改动让代码看起来比 Wolverine 的发型还要整洁!(别告诉他我这么说了 😅)

✅ Verification successful

嘿嘿,让我们来看看这个 OUTPUT 常量的情况吧!经过我的火眼金睛(和一些命令行忍术),我已经完全掌握了它的行踪!

OUTPUT 常量使用情况一切正常,就像我的制服一样合身!

让我给你分析一下这个常量的使用情况(比分析我的愈合因子还要简单):

  1. src/env.ts 中定义了这个常量:OUTPUT = 'node_modules/.unplugin-iconify'
  2. 在三个地方被引用和使用:
    • src/core/index.ts 作为默认选项
    • src/loader.ts 中的 UnocssLoader 函数默认参数
    • src/loader.ts 中的 getOutputFiles 函数默认参数

所有的使用都非常合理,就像我的双刀一样配合得天衣无缝!没有发现任何不当使用或潜在问题。

PS: 这次代码审查比在 Sister Margaret's School for Wayward Children 酒吧打架还要轻松!🗡️

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 让我们来八卦一下这个 OUTPUT 常量都在哪些地方出现过
echo "🔍 追踪 OUTPUT 常量的足迹..."
rg "OUTPUT" -B 2 -A 2

Length of output: 1282

README.md (1)

5-5: 安装部分翻译没问题!

嘿嘿,看来有人终于想起来要照顾我们这些中文用户了!不过别以为就这样就完事了哦~

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (2)
README.md (2)

Line range hint 103-126: UnocssLoader 配置需要更多说明!

哟!这不是我们可爱的 UnocssLoader 吗?但是这个注释 /** output */ 也太神秘了吧!像我的独白一样需要更多解释!🎭

建议这样改:

- ...UnocssLoader(/** output */),
+ ...UnocssLoader(/** 
+  * 可选参数:指定图标输出目录
+  * 默认值:与 Iconify 配置的 output 相同
+  */),

这样写不是更清楚了吗?就像我的脸一样清晰可见!😉


130-134: 重复的 unplugin 链接看得我头晕!

哇哦!这感谢列表里的 unplugin 出现得比我的再生细胞还频繁!😵‍💫

建议合并一下:

## 感谢

- - [unplugin](https://github.com/unjs/unplugin)
- - [unplugin/unplugin-icons](https://github.com/unplugin/unplugin-icons)
+ - [unplugin](https://github.com/unjs/unplugin) & [unplugin-icons](https://github.com/unplugin/unplugin-icons)
  - [unocss](https://unocss.dev/presets/icons)

像我的双刀一样,一次砍掉两个问题!⚔️

🧰 Tools
🪛 LanguageTool

[duplication] ~132-~132: Possible typo: you repeated a word
Context: ..., // ... }) ```

## 感谢 - unplugin - [unplugin/unplugin-icons](https://github.com/unpl...

(ENGLISH_WORD_REPEAT_RULE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a5f1e71 and ec5ac54.

📒 Files selected for processing (1)
  • README.md (4 hunks)
🧰 Additional context used
🪛 Markdownlint
README.md

49-49: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)

🪛 LanguageTool
README.md

[duplication] ~132-~132: Possible typo: you repeated a word
Context: ..., // ... }) ```

## 感谢 - unplugin - [unplugin/unplugin-icons](https://github.com/unpl...

(ENGLISH_WORD_REPEAT_RULE)

🔇 Additional comments (1)
README.md (1)

49-55: 标题层级又双叒叕不对劲啦!

哎呀妈呀!这标题层级跳得比我翻墙还快!😱 从 h2 直接跳到 h4,这操作可太刺激了!

让咱们优雅一点:

-#### 补充
+### 补充

就像我的再生能力一样,修复它永远不嫌晚!💪

🧰 Tools
🪛 Markdownlint

49-49: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)

README.md Show resolved Hide resolved
@waset waset changed the title fix: 未声明 loader 包 fix: 声明 loader 包、加载器增加默认值、声明 env 包 Oct 24, 2024
@waset waset merged commit 0bd0a31 into main Oct 24, 2024
7 checks passed
@waset waset deleted the ws-redme branch October 24, 2024 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix 修复漏洞
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant