从手动修复到自动升级 — 在Lyft构建Codemod平台

With the right library, you can automate almost any change, but handling all edge cases takes time and patience.

有了合适的库,您几乎可以自动化任何更改,但处理所有边缘情况需要时间和耐心。

Our Goals

我们的目标

To tackle this challenge, we started with several clear goals:

为了解决这个挑战,我们开始时设定了几个明确的目标:

  • Automate dependency upgrades: minor version updates often introduce new features, while major versions come with breaking changes that require fixes. Instead of developers manually reading docs, testing changes, and updating code, we would love codemods to handle everything automatically — seamlessly upgrading APIs and applying necessary fixes without human intervention.
  • 自动化依赖升级:小版本更新通常会引入新功能,而大版本则伴随着需要修复的重大更改。我们希望 codemod 能够自动处理所有内容——无缝升级 API 并在没有人工干预的情况下应用必要的修复,而不是让开发人员手动阅读文档、测试更改和更新代码。
  • Make codemods easier to write: reduce the learning curve by providing helper functions and clear documentation, making it easier for developers to create their own transforms.
  • 使 codemods 更易于编写:通过提供辅助函数和清晰的文档来降低学习曲线,使开发人员更容易创建自己的转换。
  • Make it accessible to all developers: to ensure codemods could run anywhere with Node.js access, we provide our own CLI tool. By executing it with npx, developers can run codemods without needing a global installation or adding them to frontend (FE) repositories.
  • 使所有开发人员都能访问:为了确保 codemods 可以在任何具有 Node.js 访问权限的地方运行,我们提供了自己的 CLI 工具。通过使用 npx 执行,开发人员可以在不需要全局安装或将其添加到前端 (FE) 存储库的情况下运行 codemods。
  • Standardize codemods across Lyft: last but not least, we aimed to unify the different codemod implementations across Lyft.
  • 在 Lyft 统一 codemods:最后但同样重要的是,我们旨在统一 Lyft 中不同的 codemod 实现。

Requirements

要求

Choosing the right library was key. There aren’t many options for transforming code in frontend, and jscodeshift was the best fit — it provides parsing, transformation, and writing in one place. Since we needed to handle TS, TSX, JS, and JSX files, jscodeshift worked out of the box. However, it also had some limitations we wanted to address:

选择合适的库是关键。前端代码转换的选项不多,而 jscodeshift 是最合适的选择——它在一个地方提供了解析、转换和写入。由于我们需要处理 TS、TSX、JS 和 JSX 文件,jscodeshift 开箱即用。然而,它也有一些我们想要解决的限制:

  • ...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2025 iteam. Current version is 2.143.0. UTC+08:00, 2025-05-02 03:05
浙ICP备14020137号-1 $访客地图$