Skip to content

refactor: optimize release workflow#199

Merged
bytemain merged 2 commits intomainfrom
refactor/release
Oct 21, 2024
Merged

refactor: optimize release workflow#199
bytemain merged 2 commits intomainfrom
refactor/release

Conversation

@bytemain
Copy link
Copy Markdown
Member

@bytemain bytemain commented Oct 21, 2024

Types

  • 🪚 Refactors

Background or solution

之前发版依赖内网 cdn,改造后直接用公共 cdn(alipay/npmmirror)

ChangeLog

Summary by CodeRabbit

  • 新功能

    • 引入了新的 CDN 类型和资源获取功能,支持多种 CDN 访问。
    • 配置对象中新增 useBuiltinWebview 属性,以支持内置 Webview 组件。
  • 修复

    • 移除了不再使用的 WEBVIEW_ENDPOINTWEBVIEW_SCRIPT 常量,简化了配置。
  • 文档

    • 更新了 package.json 文件,新增了对资源目录的支持。
  • 样式

    • 删除了不再使用的 Webview 相关 HTML 和 JS 文件,简化了项目结构。

@bytemain
Copy link
Copy Markdown
Member Author

/next

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 21, 2024

📝 Walkthrough

Walkthrough

此次更改主要涉及多个文件的修改和删除。.gitignore 文件新增了多个忽略项,包括与 Next.js、Nuxt.js 和 Gatsby 相关的缓存目录和构建输出文件,同时移除了对 scripts/utils/_upload.js 的忽略。packages/common/src/cdn.ts 文件引入了新的类型和函数,用于处理 CDN 资源的获取。其他文件的修改包括应用程序和编辑器配置的更新、Webpack 配置的调整以及一些资源文件的删除和更新。

Changes

文件路径 更改摘要
.gitignore 新增多个忽略项,移除对 scripts/utils/_upload.js 的忽略。
packages/common/src/cdn.ts 新增类型 TComponentCDNTypeIComponentCDNTypeMap,新增 CDN_TYPE_MAP 常量和 getResource 函数。
packages/common/src/index.ts 新增导出语句 export * from './cdn';
packages/core/src/api/createApp.tsx 移除 webviewEndpoint 属性,新增 useBuiltinWebview 属性。
packages/core/src/api/createEditor.tsx 移除 webviewEndpoint 属性,新增 useBuiltinWebview 属性。
packages/core/src/core/env.ts 更新 EXT_WORKER_HOST 常量,移除 WEBVIEW_ENDPOINTWEBVIEW_SCRIPT
packages/sumi-core/package.json 更新 files 数组,新增 "resources"
packages/sumi-core/resources/manifest.json 更新 worker-host 条目,移除 webviewwebview/index.html 条目。
packages/sumi-core/resources/webview.25aac54e/index.html 删除文件。
packages/sumi-core/resources/webview.9ae5c833.js 删除文件。
packages/toolkit/package.json 更新 build:host 脚本,移除对 webpack/config.webview.js 的引用。
packages/toolkit/webpack/config.build.js 移除 fs 模块导入,调整 libBundleglobalBundle 的优化设置。
packages/toolkit/webpack/config.integration.js 移除 __WEBVIEW_ENDPOINT____WEBVIEW_SCRIPT__ 的定义。
packages/toolkit/webpack/config.worker.js 新增 JSDoc 注释,简化输出文件名格式,新增 clean: true 属性。
scripts/build-assets.js 移除与资产构建和上传过程相关的多行代码,简化日志和清理逻辑。
scripts/utils/upload.js 删除文件。
typings/global/index.d.ts 新增 IS_DEV 属性,移除 __WEBVIEW_ENDPOINT____WEBVIEW_SCRIPT__ 的声明。

Suggested labels

⚙️ refactor

Suggested reviewers

  • Ricbet

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.

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
Copy Markdown

@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: 3

🧹 Outside diff range and nitpick comments (5)
packages/common/src/index.ts (1)

4-4: 导出 CDN 模块看起来不错!

新增的 CDN 模块导出与 PR 的目标一致,即重构发布工作流以使用公共 CDN。这个改动使得 CDN 相关的功能可以被项目的其他部分访问到。

为了保持代码的一致性和可读性,建议考虑按字母顺序排列导出语句。例如:

+export * from './cdn';
 export * from './mutex';
 export * from './request';
 export * from './types';
-export * from './cdn';

这样可以使模块的组织结构更加清晰,便于未来的维护。

packages/core/src/core/env.ts (1)

7-10: EXT_WORKER_HOST 的新实现看起来不错,但可以稍作改进。

新的实现使用 getResource 函数动态获取 worker URL,这与使用公共 CDN 的目标一致,并提供了更灵活的资源管理。使用 VERSION 常量确保加载正确版本的 worker 也是一个很好的做法。

为了提高代码的可读性,建议将这个长行拆分成多行:

export const EXT_WORKER_HOST = getResource(
  "@codeblitzjs/ide-sumi-core",
  "resources/worker-host.js",
  VERSION
);

这样可以使代码更易于阅读和维护。

packages/common/src/cdn.ts (1)

18-22: CDN 特定逻辑处理得当,但建议审查 'alipay' 的包名处理

针对 'alipay' 和 'npmmirror' 的条件逻辑处理得当,允许为不同的 CDN 使用特定的 URL 结构。使用模板字面量构建 URL 是一个很好的做法。

然而,对于 'alipay' CDN,packageName.slice(1) 的处理方式可能存在潜在问题。如果包名不是以特定字符开头,这种切片方法可能会导致错误。建议审查这部分逻辑,确保它能够正确处理所有可能的包名。

考虑添加一个断言或验证步骤,以确保包名符合预期的格式。例如:

if (cdnType === 'alipay') {
  if (!packageName.startsWith('@')) {
    throw new Error('Package name for alipay CDN must start with "@"');
  }
  return `${CDN_TYPE_MAP['alipay']}/${packageName.slice(1)}/${version}/${filePath}`;
}

这样可以提前捕获潜在的错误,提高代码的健壮性。

packages/toolkit/webpack/config.worker.js (1)

21-21: 清理输出目录的好做法

添加 clean: true 配置是一个很好的做法,它可以确保每次构建前清理输出目录,防止旧文件引起的问题。

建议:考虑使用 cleanStaleWebpackAssets: true 选项来只清理过时的资源,这可能会略微提高构建性能:

clean: {
  keep: /ignored\/dir\//,
},

这样可以在清理输出目录的同时,保留某些特定的文件或目录。

packages/core/src/api/createApp.tsx (1)

77-77: 新增的 useBuiltinWebview 配置看起来不错。

添加 useBuiltinWebview: true 配置项符合重构的目标,表明现在默认使用内置的 webview 组件。这可能会提高性能并减少外部依赖。

建议更新相关文档,以反映这一新的默认行为,并说明它可能对现有集成产生的影响。

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ed1f678 and c4f0205.

📒 Files selected for processing (17)
  • .gitignore (0 hunks)
  • packages/common/src/cdn.ts (1 hunks)
  • packages/common/src/index.ts (1 hunks)
  • packages/core/src/api/createApp.tsx (2 hunks)
  • packages/core/src/api/createEditor.tsx (2 hunks)
  • packages/core/src/core/env.ts (1 hunks)
  • packages/sumi-core/package.json (1 hunks)
  • packages/sumi-core/resources/manifest.json (1 hunks)
  • packages/sumi-core/resources/webview.25aac54e/index.html (0 hunks)
  • packages/sumi-core/resources/webview.9ae5c833.js (0 hunks)
  • packages/toolkit/package.json (1 hunks)
  • packages/toolkit/webpack/config.build.js (0 hunks)
  • packages/toolkit/webpack/config.integration.js (0 hunks)
  • packages/toolkit/webpack/config.worker.js (2 hunks)
  • scripts/build-assets.js (1 hunks)
  • scripts/utils/upload.js (0 hunks)
  • typings/global/index.d.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • .gitignore
  • packages/sumi-core/resources/webview.25aac54e/index.html
  • packages/sumi-core/resources/webview.9ae5c833.js
  • packages/toolkit/webpack/config.build.js
  • packages/toolkit/webpack/config.integration.js
  • scripts/utils/upload.js
✅ Files skipped from review due to trivial changes (1)
  • packages/sumi-core/resources/manifest.json
🧰 Additional context used
🔇 Additional comments (16)
packages/core/src/core/env.ts (2)

1-1: 导入语句看起来不错。

新增的 getResource 导入与 EXT_WORKER_HOST 的新实现相符,并且与 PR 目标中提到的使用公共 CDN 的重构一致。


1-10: 请确认移除 WEBVIEW_ENDPOINTWEBVIEW_SCRIPT 常量的影响。

这些常量的移除表明 webview 功能的处理方式可能已经发生了变化。请确保:

  1. 所有之前依赖这些常量的代码都已经相应地进行了更新。
  2. 如果有任何替代方案,它们已经在整个代码库中得到了正确实施。
  3. 这个变更不会导致任何功能regression。

为了验证这些常量的移除没有遗漏任何使用点,请运行以下脚本:

如果脚本返回任何结果,请检查这些位置并确保它们已经被适当地更新或移除。

✅ Verification successful

已验证 WEBVIEW_ENDPOINTWEBVIEW_SCRIPT 常量的移除不会影响代码库中的其他部分。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:搜索整个代码库中是否还有 WEBVIEW_ENDPOINT 和 WEBVIEW_SCRIPT 的使用

echo "Searching for WEBVIEW_ENDPOINT usage:"
rg "WEBVIEW_ENDPOINT" --type ts --type tsx

echo "Searching for WEBVIEW_SCRIPT usage:"
rg "WEBVIEW_SCRIPT" --type ts --type tsx

Length of output: 305


Script:

#!/bin/bash
# 描述:搜索整个代码库中是否还有 WEBVIEW_ENDPOINT 和 WEBVIEW_SCRIPT 的使用

echo "Searching for WEBVIEW_ENDPOINT usage:"
rg "WEBVIEW_ENDPOINT" --type typescript --type typescriptreact

echo "Searching for WEBVIEW_SCRIPT usage:"
rg "WEBVIEW_SCRIPT" --type typescript --type typescriptreact

Length of output: 359


Script:

#!/bin/bash
# 描述:搜索整个代码库中是否还有 WEBVIEW_ENDPOINT 和 WEBVIEW_SCRIPT 的使用

echo "Searching for WEBVIEW_ENDPOINT usage:"
rg "WEBVIEW_ENDPOINT" -g "*.ts" -g "*.tsx"

echo "Searching for WEBVIEW_SCRIPT usage:"
rg "WEBVIEW_SCRIPT" -g "*.ts" -g "*.tsx"

Length of output: 249

typings/global/index.d.ts (3)

Line range hint 7-7: 新增的 IS_DEV 环境变量定义看起来不错。

这个新增的布尔类型属性 IS_DEV 为 ProcessEnv 接口提供了类型安全的访问。这与重构发布工作流的 PR 目标一致,并遵循了开发环境标志的常见命名约定。


25-25: 文件末尾添加换行符是个好习惯。

在文件末尾添加换行符是一个常见的最佳实践。这样做可以确保与各种文本处理工具和版本控制系统的兼容性。


Line range hint 15-17: 移除 WEBVIEW_ENDPOINT 和 WEBVIEW_SCRIPT 声明的改动看起来合理。

这个改动与重构发布工作流的 PR 目标一致,并且与其他文件中的相关更改保持一致。这可能表明 webview 相关配置的处理方式发生了变化。

建议运行以下脚本来验证这个更改的影响:

✅ Verification successful

验证通过:移除 WEBVIEW_ENDPOINT 和 WEBVIEW_SCRIPT 声明不会影响现有代码。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否还有其他地方使用了 __WEBVIEW_ENDPOINT__ 和 __WEBVIEW_SCRIPT__

# 测试:搜索整个代码库中是否还有这两个变量的使用。预期:没有匹配项。
echo "Searching for __WEBVIEW_ENDPOINT__:"
rg "__WEBVIEW_ENDPOINT__"
echo "Searching for __WEBVIEW_SCRIPT__:"
rg "__WEBVIEW_SCRIPT__"

Length of output: 461

packages/common/src/cdn.ts (4)

1-3: 类型定义看起来不错!

这些类型定义清晰明确,为CDN类型提供了良好的类型安全性。命名约定也遵循了TypeScript的最佳实践。这些类型将在整个代码库中用于类型检查,提高代码的可靠性。


12-17: getResource 函数签名设计合理

getResource 函数的签名清晰明了,类型定义完善。默认 CDN 类型设置为 'alipay',这与使用公共 CDN 的 PR 目标相符。函数的设计具有灵活性,允许指定不同的 CDN 类型。这种设计既满足了当前需求,又为未来可能的 CDN 变更预留了空间。


23-25: 其他 CDN 类型的默认处理逻辑合理

对于其他 CDN 类型的默认处理逻辑设计得很好。它提供了一个通用的回退方案,增强了函数的可扩展性。URL 结构符合常见的 CDN 实践,包含了版本信息。

使用索引访问器 CDN_TYPE_MAP[cdnType] 是类型安全的,这要归功于之前定义的类型。这种方法既灵活又安全,能够轻松地支持未来可能添加的新 CDN 类型。


5-10: CDN_TYPE_MAP 常量定义合理,但建议审查 'alipay' CDN URL

常量 CDN_TYPE_MAP 为不同的 CDN 类型提供了集中的 URL 管理,这有利于代码的可维护性。所有 URL 都使用 HTTPS 是很好的安全实践。

然而,'alipay' CDN URL 似乎是一个通用的库 URL。建议审查这个 URL 是否适合用于特定包的资源。您可能需要考虑使用更具体的 URL 路径来确保资源的正确性和安全性。

请运行以下脚本来验证 'alipay' CDN URL 的使用情况:

✅ Verification successful

'alipay' CDN URL 使用验证通过

经过验证,'alipay' CDN URL 仅在 packages/common/src/cdn.ts 文件中使用,符合预期。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 'alipay' CDN URL 的使用情况

# 测试:搜索 'alipay' CDN URL 的使用。预期:仅在此文件中使用。
rg "https://gw.alipayobjects.com/os/lib"

Length of output: 116

packages/toolkit/webpack/config.worker.js (2)

6-8: 良好的类型注释添加!

添加的 JSDoc 注释明确了导出函数的返回类型,这有助于提高代码的可读性和可维护性。正确指定返回类型为 Webpack Configuration 对象也有助于开发工具提供更好的类型提示。


Line range hint 1-48: 总体评估:配置简化和构建一致性的改进

这些更改整体上简化了 worker 的 Webpack 配置,并提高了构建过程的一致性。主要改进包括:

  1. 添加了返回类型注释,提高了代码可读性。
  2. 简化了输出文件名,使其在所有环境中保持一致。
  3. 添加了清理输出目录的配置,有助于防止旧文件引起的问题。

这些变更与 PR 的目标(重构发布工作流程)相符。然而,建议进一步考虑以下几点:

  1. 验证移除文件名哈希是否符合项目的缓存策略。
  2. 考虑优化清理配置以提高构建性能。

总的来说,这些更改是积极的,但可能需要在团队内进行进一步讨论,以确保它们完全符合项目的长期目标和最佳实践。

packages/sumi-core/package.json (1)

8-9: 更改看起来不错,但请验证resources目录的内容。

将"resources"添加到"files"数组中是一个合理的更改,与优化发布工作流的目标相符。这确保了resources目录中的文件将包含在发布的包中。

请运行以下脚本以验证resources目录的内容:

这将帮助确保正确的文件被包含在发布包中,并且manifest.json不包含任何不应该存在的webview相关组件。

✅ Verification successful

验证通过,resources目录内容正确。

  • resources目录包含以下文件:
    • manifest.json
    • worker-host.js
    • worker-host.js.LICENSE.txt
  • manifest.json中不包含任何webview相关组件。
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证resources目录的内容

# 测试:列出resources目录中的文件
echo "resources目录内容:"
fd . packages/sumi-core/resources -t f

# 测试:检查manifest.json文件
echo "manifest.json内容:"
cat packages/sumi-core/resources/manifest.json

Length of output: 442

packages/core/src/api/createEditor.tsx (2)

23-23: 导入语句的修改看起来不错。

新增的 EXT_WORKER_HOST 导入与 getDefaultEditorAppConfig 函数中的使用一致。同时,删除 WEBVIEW_ENDPOINT 的导入(虽然在提供的代码中不可见)与配置中移除 webviewEndpoint 属性的变更保持一致。这些更改符合重构发布工作流程的目标。


61-61: 配置更改看起来合理,但需要验证其影响。

新增的 useBuiltinWebview: true 配置与重构发布工作流程的目标一致,并且与代码库其他部分的类似修改保持一致。这个更改表明项目正在转向使用内置的 webview 组件。

为了确保这些更改不会对 webview 功能产生意外影响,建议运行以下验证脚本:

请确保在相关的测试用例中验证 webview 功能是否正常工作。

packages/core/src/api/createApp.tsx (2)

33-33: 导入语句的清理看起来不错。

移除未使用的 WEBVIEW_ENDPOINT 导入有助于保持代码整洁,并与其他相关更改保持一致。


33-33: 建议验证这些更改对整体应用行为和性能的影响。

移除 WEBVIEW_ENDPOINT 并启用内置 webview 是重要的架构变更。虽然这些更改看起来是正确的,但建议:

  1. 确保在不同环境和场景下测试应用,以验证 webview 功能正常工作。
  2. 评估这些更改对应用性能的影响,特别是在加载时间和资源使用方面。
  3. 更新相关文档,确保开发团队了解这一架构变更。

可以运行以下脚本来检查是否有其他文件仍在使用 WEBVIEW_ENDPOINT

Also applies to: 77-77

✅ Verification successful

已验证

没有其他文件中使用 WEBVIEW_ENDPOINT

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否有其他文件仍在使用 WEBVIEW_ENDPOINT

# 测试:搜索 WEBVIEW_ENDPOINT 的使用。预期:没有匹配项。
rg 'WEBVIEW_ENDPOINT' --type ts --type tsx

Length of output: 70


Script:

#!/bin/bash
# 描述:检查是否有其他文件仍在使用 WEBVIEW_ENDPOINT

# 测试:搜索 WEBVIEW_ENDPOINT 的使用。预期:没有匹配项。
rg 'WEBVIEW_ENDPOINT' -g '*.ts' -g '*.tsx'

Length of output: 42

Comment thread packages/toolkit/webpack/config.worker.js
Comment thread packages/toolkit/package.json
Comment thread scripts/build-assets.js
@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented Oct 21, 2024

🎉 PR Next publish successful!

0.0.20241021032759-refaease.0

@bytemain
Copy link
Copy Markdown
Member Author

@bytemain bytemain merged commit f7ec30b into main Oct 21, 2024
@bytemain bytemain deleted the refactor/release branch October 21, 2024 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants