-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix(codemod): configPath maybe .umirc.ts or .umirc.js #11936
base: master
Are you sure you want to change the base?
Conversation
schifred
commented
Dec 7, 2023
- 问题:当应用使用 .umirc.ts 作为配置文件,执行 pnpm dlx @umijs/codemod@latest 命令报配置文件未找到错误
- 处理:prepare 过程获知配置文件路径,通过 context 传入 ConfigRunner
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 codemod 现在用的人非常少,也没公开提到过,另外目前 umi 4 的发布非常缓慢,存在较大的滞后性,如果能自己解决就先自己本地解决吧。
@@ -123,17 +121,12 @@ export class Runner { | |||
setKeys['layout.locale'] = false; | |||
} | |||
|
|||
const configFile = join(this.cwd, 'config/config.ts'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不直接改这一行而是要改下面很多行呢。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这里改的话,需要使用 tryPaths 或者 prepare 中的逻辑推断下用户实际使用的配置文件是否是 config/config.ts, config/config.js 还是 .umirc.ts, .umirc.js,而这个逻辑在前置流程里 prepare 已经做了,所以通过 context 传递可以避免重复开发
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以这样获得最少的代码更改吧:
const configFile = this.context.configPath;
@@ -75,6 +75,7 @@ export async function prepare(opts: { cwd: string; pattern: any; args?: any }) { | |||
|
|||
return { | |||
config, | |||
configPath: mainConfigFile, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议这个命名最好叫 mainConfigPath
或者 mainConfigFile
,因为 configPath
指代哪个 config 文件不明确。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的