feat: support to control crossorigin for async chunk scripts and links#1539
feat: support to control crossorigin for async chunk scripts and links#1539PeachScript merged 4 commits intomasterfrom
Conversation
Walkthrough本次更改引入了对跨源加载的支持,允许用户在配置中指定 Changes
Assessment against linked issues
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (11)
- crates/mako/src/config/config.rs (3 hunks)
- crates/mako/src/generate/chunk_pot/util.rs (1 hunks)
- crates/mako/src/generate/runtime.rs (1 hunks)
- crates/mako/templates/app_runtime.stpl (2 hunks)
- docs/config.md (2 hunks)
- docs/config.zh-CN.md (2 hunks)
- e2e/fixtures/config.crossOriginLoading/expect.js (1 hunks)
- e2e/fixtures/config.crossOriginLoading/mako.config.json (1 hunks)
- e2e/fixtures/config.crossOriginLoading/src/async.ts (1 hunks)
- e2e/fixtures/config.crossOriginLoading/src/index.ts (1 hunks)
- examples/dead-simple/mako.config.json (1 hunks)
Files skipped from review due to trivial changes (3)
- e2e/fixtures/config.crossOriginLoading/mako.config.json
- e2e/fixtures/config.crossOriginLoading/src/async.ts
- e2e/fixtures/config.crossOriginLoading/src/index.ts
Additional comments not posted (16)
examples/dead-simple/mako.config.json (1)
2-2: 新增属性 crossOriginLoading属性
crossOriginLoading添加到output对象中,值设置为"anonymous",用于控制跨源请求。代码更改已批准。
crates/mako/src/generate/runtime.rs (1)
14-14: 新增字段 cross_origin_loading字段
cross_origin_loading添加到AppRuntimeTemplate结构体中,类型为Option<String>,适用于可选的字符串值。代码更改已批准。
e2e/fixtures/config.crossOriginLoading/expect.js (1)
6-7: 新增断言断言正确地验证了
script.crossOrigin和link.crossOrigin是否设置为'anonymous'。代码更改已批准。
crates/mako/src/generate/chunk_pot/util.rs (1)
106-111: 代码更改通过!函数正确地将新字段添加到结构体中,并在存在时将其克隆并转换为字符串。
代码更改已通过。
docs/config.zh-CN.md (1)
Line range hint
450-462: 文档更改通过!文档正确地添加了新属性及其描述和默认值。
文档更改已通过。
crates/mako/templates/app_runtime.stpl (2)
210-218: 代码更改通过!函数正确地添加了条件逻辑,根据
cross_origin_loading的值设置crossOrigin属性。代码更改已通过。
312-320: 代码更改通过!函数正确地添加了条件逻辑,根据
cross_origin_loading的值设置crossOrigin属性。代码更改已通过。
docs/config.md (3)
449-449: 变更已批准类型定义中正确添加了
crossOriginLoading属性。
450-450: 变更已批准默认输出配置中正确添加了
crossOriginLoading属性。
461-461: 变更已批准正确添加了
crossOriginLoading属性的描述。crates/mako/src/config/config.rs (6)
106-106: 变更已批准正确实现了新的反序列化函数
deserialize_cross_origin_loading。
119-121: 变更已批准在
OutputConfig结构体中正确添加了cross_origin_loading字段。
123-129: 变更已批准正确实现了新的枚举
CrossOriginLoading,包括Anonymous和UseCredentials值。
131-137: 变更已批准正确实现了
CrossOriginLoading枚举的显示功能。
704-705: 变更已批准默认配置字符串中正确添加了
crossOriginLoading属性。
704-705: 变更已批准默认配置字符串中正确添加了
crossOriginLoading属性。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1539 +/- ##
==========================================
+ Coverage 60.78% 60.88% +0.09%
==========================================
Files 126 126
Lines 15028 15118 +90
==========================================
+ Hits 9135 9204 +69
- Misses 5893 5914 +21 ☔ View full report in Codecov by Sentry. |
cc90e19 to
32cb6e7
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (11)
- crates/mako/src/config/config.rs (3 hunks)
- crates/mako/src/generate/chunk_pot/util.rs (1 hunks)
- crates/mako/src/generate/runtime.rs (1 hunks)
- crates/mako/templates/app_runtime.stpl (2 hunks)
- docs/config.md (2 hunks)
- docs/config.zh-CN.md (2 hunks)
- e2e/fixtures/config.crossOriginLoading/expect.js (1 hunks)
- e2e/fixtures/config.crossOriginLoading/mako.config.json (1 hunks)
- e2e/fixtures/config.crossOriginLoading/src/async.ts (1 hunks)
- e2e/fixtures/config.crossOriginLoading/src/index.ts (1 hunks)
- examples/dead-simple/mako.config.json (1 hunks)
Files skipped from review due to trivial changes (1)
- e2e/fixtures/config.crossOriginLoading/src/async.ts
Files skipped from review as they are similar to previous changes (8)
- crates/mako/src/generate/runtime.rs
- crates/mako/templates/app_runtime.stpl
- docs/config.md
- docs/config.zh-CN.md
- e2e/fixtures/config.crossOriginLoading/expect.js
- e2e/fixtures/config.crossOriginLoading/mako.config.json
- e2e/fixtures/config.crossOriginLoading/src/index.ts
- examples/dead-simple/mako.config.json
Additional context used
GitHub Check: codecov/patch
crates/mako/src/generate/chunk_pot/util.rs
[warning] 111-111: crates/mako/src/generate/chunk_pot/util.rs#L111
Added line #L111 was not covered by testscrates/mako/src/config/config.rs
[warning] 123-124: crates/mako/src/config/config.rs#L123-L124
Added lines #L123 - L124 were not covered by tests
[warning] 132-135: crates/mako/src/config/config.rs#L132-L135
Added lines #L132 - L135 were not covered by tests
[warning] 137-137: crates/mako/src/config/config.rs#L137
Added line #L137 was not covered by tests
| cross_origin_loading: context | ||
| .config | ||
| .output | ||
| .cross_origin_loading | ||
| .clone() | ||
| .map(|s| s.to_string()), |
There was a problem hiding this comment.
请添加测试以覆盖新字段。
新字段 cross_origin_loading 需要添加测试以确保其正确性。
您是否需要我生成单元测试代码或打开一个 GitHub issue 来跟踪此任务?
Tools
GitHub Check: codecov/patch
[warning] 111-111: crates/mako/src/generate/chunk_pot/util.rs#L111
Added line #L111 was not covered by tests
| #[serde(deserialize_with = "deserialize_cross_origin_loading")] | ||
| pub cross_origin_loading: Option<CrossOriginLoading>, | ||
| } |
There was a problem hiding this comment.
请添加测试以覆盖新字段。
新字段 cross_origin_loading 需要添加测试以确保其正确性。
您是否需要我生成单元测试代码或打开一个 GitHub issue 来跟踪此任务?
| #[derive(Deserialize, Serialize, Debug, Clone)] | ||
| pub enum CrossOriginLoading { | ||
| #[serde(rename = "anonymous")] | ||
| Anonymous, | ||
| #[serde(rename = "use-credentials")] | ||
| UseCredentials, | ||
| } | ||
|
|
||
| impl fmt::Display for CrossOriginLoading { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| CrossOriginLoading::Anonymous => write!(f, "anonymous"), | ||
| CrossOriginLoading::UseCredentials => write!(f, "use-credentials"), | ||
| } | ||
| } |
There was a problem hiding this comment.
请添加测试以覆盖新枚举。
新枚举 CrossOriginLoading 需要添加测试以确保其正确性。
您是否需要我生成单元测试代码或打开一个 GitHub issue 来跟踪此任务?
Tools
GitHub Check: codecov/patch
[warning] 123-124: crates/mako/src/config/config.rs#L123-L124
Added lines #L123 - L124 were not covered by tests
[warning] 132-135: crates/mako/src/config/config.rs#L132-L135
Added lines #L132 - L135 were not covered by tests
[warning] 137-137: crates/mako/src/config/config.rs#L137
Added line #L137 was not covered by tests
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/bundler-mako/index.js (3 hunks)
Additional comments not posted (3)
packages/bundler-mako/index.js (3)
456-456: 初始化crossOriginLoading变量初始化
crossOriginLoading变量为false是合理的,因为它确保在没有配置的情况下有一个默认值。代码更改已批准。
472-475: 从 Webpack 配置中获取crossOriginLoading确保从 Webpack 配置中正确获取
crossOriginLoading属性是必要的。这段代码实现了这一点。代码更改已批准。
620-620: 在makoConfig中包含crossOriginLoading将
crossOriginLoading包含在makoConfig的输出对象中是必要的,以便正确传递该配置。代码更改已批准。
支持通过
output.crossOriginLoading指定 async chunk 资源加载时的script及link标签的crossorigin值Close #1511
Summary by CodeRabbit
新特性
crossOriginLoading配置选项,以便用户可以控制跨域资源加载的方式(如使用凭证或匿名)。测试
文档
crossOriginLoading属性的说明和默认值。