{"id":16594877,"url":"https://github.com/symind/taro2-to-3","last_synced_at":"2025-04-12T21:01:57.692Z","repository":{"id":49529647,"uuid":"341762214","full_name":"SyMind/taro2-to-3","owner":"SyMind","description":"让 Taro2 项目自动升级到 Taro3 项目 ⚒️","archived":false,"fork":false,"pushed_at":"2024-09-19T08:26:20.000Z","size":377,"stargazers_count":43,"open_issues_count":0,"forks_count":11,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-16T14:09:48.660Z","etag":null,"topics":["codemod","taro","taro3"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SyMind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-24T03:04:49.000Z","updated_at":"2024-09-19T08:34:45.000Z","dependencies_parsed_at":"2024-10-28T10:27:57.552Z","dependency_job_id":"95b2ca5f-070e-4442-b14d-05d7e7996578","html_url":"https://github.com/SyMind/taro2-to-3","commit_stats":{"total_commits":87,"total_committers":1,"mean_commits":87.0,"dds":0.0,"last_synced_commit":"3e4e2f05299a51e7ec23979a6af97520e731c1bf"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyMind%2Ftaro2-to-3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyMind%2Ftaro2-to-3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyMind%2Ftaro2-to-3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SyMind%2Ftaro2-to-3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SyMind","download_url":"https://codeload.github.com/SyMind/taro2-to-3/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245678901,"owners_count":20654738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codemod","taro","taro3"],"created_at":"2024-10-11T23:47:46.622Z","updated_at":"2025-03-26T15:10:45.974Z","avatar_url":"https://github.com/SyMind.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# taro2-to-3\n\n帮助你将 Taro 2.x 项目升级到 Taro 3.x 项目，基于 [jscodeshift](https://github.com/facebook/jscodeshift) 构建。\n\n该工具的处理规则参考 Taro 官方 [迁移指南](https://taro-docs.jd.com/taro/docs/migration)。\n\n## 动机\n\n愿将 Taro 2.x 项目升级到 Taro 3.x 项目的过程变得轻松愉悦。\n\n## 使用\n\n在运行前，请先提交你的本地代码修改。\n\n```bash\n# 全局安装\nnpm i -g taro2-to-3\n# or for yarn user\n#  yarn global add taro2-to-3\ntaro2-to-3\n```\n\n## 已知问题\n\n1. Taro 内部 `__taroRouterChange` 事件参数变更，h5 中参数发生变化，小程序中不触发 https://github.com/NervJS/taro/issues/7903\n2. Taro 3.2.x 以上版本中 preloadData api 发生变更 https://github.com/NervJS/taro/commit/d2c4aaf5d9d755bc3ca40f9b449340b360c673d5\n3. 缺失对 `this.$scope` api 进行转换 https://github.com/NervJS/taro/issues/7795\n\n## 处理流程\n\n1. 读取 Taro 项目中的编译配置文件 `config/index.js`.\n    1. 读取其中的配置项 `sourceRoot` ，获取项目入口文件所在目录。\n    2. 更新编译配置文件。\n2. 读取当前项目中的入口文件，如 `{sourceRoot}/app.js`。\n    1. 读取其中的配置项 `pages` ，获取项目中所有的页面路径。\n    2. 更新入口文件。\n3. 执行以下脚本。\n4. 读取项目的 `package.json` 文件，检查并更新依赖。\n\n## 脚本包括\n\n### `taro-imports`\n\n在 Taro 2.x 中，所有面向应用开发者的 API 都在 @tarojs/taro 包中。\n\n在 Taro 3.x 中，将 React 的 API 从 react 包中引入，其它的 API 仍然从 @tarojs/taro 引入。\n\n```diff\n- import Taro, { Component } from '@tarojs/taro';\n+ import React, { Component } from 'react';\n+ import Taro from '@tarojs/taro';\n\nclass Wallace extends Component {\n    componentDidMount() {\n        Taro.request().then(() =\u003e {});\n    }\n    render() {\n        return \u003cdiv /\u003e;\n    }\n}\n```\n\n### `page-config`\n\n在 Taro 2.x 中，页面的配置挂载在类组件的类属性或函数式的属性上，通过 AST 分析取出来，然后生成 JSON 文件。\n\n在 Taro 3.x 中，使用 *.config.js ，该文件和页面文件在同一文件夹。\n\n```diff\n// foo.jsx\nexport default class Index extends Component {\n-   config = {\n-       navigationBarTitleText: '首页'\n-   }\n    render() {\n        return null;\n    }\n}\n\n+// foo.config.js\n+export default config = {\n+   navigationBarTitleText: '首页'\n+};\n```\n\n### `router`\n\n在 Taro 2.x 中，通过 this.$router 访问当前组件/页面路由的详情。\n\n在 Taro 3.x 等价的 API 是 @tarojs/taro 包中的 getCurrentInstance().router。\n\n```diff\nclass Foo extends Component {\n+   $instance = getCurrentInstance();\n    componentWillMount() {\n-       console.log(this.$router);\n+       console.log(this.$instance.router)\n    }\n}\n```\n\n## License\n\n[MIT](https://github.com/SyMind/taro2-to-3/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymind%2Ftaro2-to-3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsymind%2Ftaro2-to-3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymind%2Ftaro2-to-3/lists"}