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

feat: sass option support function #1461

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

xiaohuoni
Copy link
Member

@xiaohuoni xiaohuoni commented Jul 31, 2024

sass 配置支持传函数,因为 importers 这些配置也是函数,且没办法用其他手段规避

Summary by CodeRabbit

  • 新功能
    • 允许在 Sass 配置中直接包含函数,增强了 Sass 的灵活性。
    • 引入自定义 Sass 函数 pow($base, $exponent),支持在 Sass 样式表中进行复杂的数学运算。
  • 文档更新
    • 更新了 Sass 配置文档,反映了新的函数支持和类型定义。
  • 测试改进
    • 增加了对 font-size 属性的测试断言,确保 CSS 正确处理。

Copy link
Contributor

coderabbitai bot commented Jul 31, 2024

Walkthrough

此次更改主要集中在增强Sass配置的灵活性和简化代码结构。通过允许直接使用Options<'async'>类型而不再省略functions属性,开发者现在可以在SCSS文件中定义和使用函数。同时,增加了resources属性,以便指定额外的资源文件。这些调整使得Sass的使用更为直观,并提高了样式处理的能力。

Changes

文件路径 更改摘要
docs/config.md, docs/config.zh-CN.md 修改Sass配置类型,从Omit<sass.Options<'async'>, 'functions'>变更为Options<'async'>,允许包含函数属性。
e2e/fixtures.umi/config.sassLoader/.umirc.ts sassLoader配置中新增functions属性,定义了自定义Sass函数pow($base, $exponent),增强了Sass的数学能力。
e2e/fixtures.umi/config.sassLoader/expect.js 新增对font-size属性的测试,确保生成的CSS包含font-size: 32px
e2e/fixtures.umi/config.sassLoader/pages/index.scss .title类中新增font-size属性,动态计算为pow(2, 5) * 1px,结果为32像素。
packages/mako/src/index.ts Config类型的sass属性更改为Options<'async'> & { resources: string[] },增强配置灵活性。
packages/mako/src/sassLoader/index.ts 修改sassLoader函数的参数类型为Options<'async'>,简化了Sass加载器的实现。
packages/mako/src/sassLoader/render.ts 更改render函数的参数类型为Options<'async'> & { resources: string[] },并采用ES模块导出。

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant SCSSFile
    participant SassLoader
    participant RenderFunction

    Developer->>SCSSFile: Write SCSS with functions
    SCSSFile->>SassLoader: Load SCSS
    SassLoader->>RenderFunction: Render with options
    RenderFunction-->>SassLoader: Output CSS
    SassLoader-->>Developer: Deliver CSS
Loading

🐰 在草丛间,我蹦蹦跳跳,
Sass功力大幅提升,真是妙!
函数与资源齐飞舞,
代码简化,流畅如水流。
兔子欢腾,庆祝这变化,
一起为样式喝彩,真美妙! 🎉


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.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Copy link
Contributor

@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, codebase verification and nitpick comments (2)
e2e/fixtures.umi/config.sassLoader/.umirc.ts (2)

1-1: 移除未使用的 sass 导入

如果 sass 模块未被使用,请移除该导入以保持代码整洁。

- import sass from 'sass';

7-16: 验证 pow 函数的实现

当前的 pow 函数实现没有包含输入验证和错误处理。建议在函数中加入这些机制,以确保能正确处理所有可能的输入情况,包括边界条件。

  • 文件: e2e/fixtures.umi/config.sassLoader/.umirc.ts
  • 代码段:
    'pow($base, $exponent)': function(args) {
      const base = args[0].assertNumber('base').assertNoUnits('base');
      const exponent = args[1].assertNumber('exponent').assertNoUnits('exponent');
      return new sass.SassNumber(Math.pow(base.value, exponent.value));
    }
Analysis chain

验证 pow 函数的实现

请确保 pow 函数的实现正确处理所有可能的输入情况,包括边界条件。建议在实现中加入输入验证和错误处理。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `pow` function in the Sass configuration.

# Test: Search for the `pow` function implementation. Expect: Correct implementation with input validation and error handling.
rg --type ts $'pow'

Length of output: 350


Script:

#!/bin/bash
# Display the full implementation of the `pow` function in the specified file.
rg -A 10 --type ts $'pow\\(\\$base, \\$exponent\\)' e2e/fixtures.umi/config.sassLoader/.umirc.ts

Length of output: 408

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5124395 and 6508fe3.

Files selected for processing (8)
  • docs/config.md (1 hunks)
  • docs/config.zh-CN.md (1 hunks)
  • e2e/fixtures.umi/config.sassLoader/.umirc.ts (1 hunks)
  • e2e/fixtures.umi/config.sassLoader/expect.js (1 hunks)
  • e2e/fixtures.umi/config.sassLoader/pages/index.scss (1 hunks)
  • packages/mako/src/index.ts (2 hunks)
  • packages/mako/src/sassLoader/index.ts (2 hunks)
  • packages/mako/src/sassLoader/render.ts (2 hunks)
Additional comments not posted (11)
e2e/fixtures.umi/config.sassLoader/pages/index.scss (1)

5-5: 验证 pow 函数的正确性

请确保 pow 函数在所有可能的输入情况下都能正确计算结果。建议在样式文件中加入注释,说明 pow 函数的作用和使用方法。

Verification successful

验证 pow 函数的正确性

pow 函数在 SCSS 文件中被使用,但未找到其定义或导入。根据 Sass 官方文档,pow 是一个有效的内置函数,可以安全使用。

请在样式文件中加入注释,说明 pow 函数的作用和使用方法,以便其他开发者理解其用途。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the `pow` function usage in the SCSS file.

# Test: Search for the `pow` function usage. Expect: Correct usage of the function.
rg --type scss $'pow'

Length of output: 49


Script:

#!/bin/bash
# Description: Verify the correctness of the `pow` function usage in SCSS files.

# Find all SCSS files and search for the `pow` function usage within them.
fd -e scss -x rg 'pow' {}

Length of output: 57


Script:

#!/bin/bash
# Description: Verify the definition or import of the `pow` function in SCSS files to ensure its correctness.

# Find all SCSS files and search for the definition or import of the `pow` function within them.
fd -e scss -x rg 'pow'

Length of output: 52

e2e/fixtures.umi/config.sassLoader/expect.js (1)

8-8: LGTM! 但请验证测试覆盖率

代码更改已批准。请确保测试覆盖了所有可能的情况,包括 pow 函数的边界条件。

packages/mako/src/sassLoader/index.ts (3)

4-4: 函数签名更新

函数 sassLoader 的参数类型从 Omit<Options<'async'>, 'functions'> 更新为 Options<'async'>,这允许更灵活的配置选项。


14-15: 简化的渲染逻辑

引入了 render 模块来处理 .scss 文件的渲染逻辑,简化了代码流。


21-21: 终止方法的空实现

terminate 方法现在是空实现,这表明不再需要管理并行加载器的生命周期。

packages/mako/src/sassLoader/render.ts (2)

3-5: 函数签名更新

函数 render 的参数类型更新为 Options<'async'> & { resources: string[] },这允许传递额外的资源文件。


23-23: 使用 ES 模块语法导出

module.exports 更改为 export { render };,这提高了与现代 JavaScript 环境的兼容性。

packages/mako/src/index.ts (2)

14-14: 类型更新

Config 类型中的 sass 属性更新为 Options<'async'> & { resources: string[] },这允许指定额外的资源文件。


120-120: 简化的构建逻辑

移除了对 sassOptsfunctions 属性的检查,简化了代码。

docs/config.zh-CN.md (1)

672-672: 更改确认:更新了 sass 配置的类型声明

类型声明从 Omit<sass.Options<'async'>,'functions'> 更新为 Options<'async'>,这使得 functions 属性现在可以包含在配置中。这一更改是准确的,并且文档清晰。

docs/config.md (1)

672-672: 更改确认:更新了 sass 配置的类型声明

类型声明从 Omit<sass.Options<'async'>,'functions'> 更新为 Options<'async'>,这使得 functions 属性现在可以包含在配置中。这一更改是准确的,并且文档清晰。

@sorrycc
Copy link
Member

sorrycc commented Jul 31, 2024

是去掉并发 worker 的方式了吗?

@xiaohuoni
Copy link
Member Author

@sorrycc 是的,因为子进程不能传递函数参数, piscinajs/piscina#130 (comment)

@sorrycc sorrycc merged commit 7913e5f into master Jul 31, 2024
8 checks passed
@xiaohuoni xiaohuoni deleted the feat-sass-options-support-function branch July 31, 2024 07:59
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.

2 participants