Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

schifred
Copy link

@schifred schifred commented Dec 7, 2023

  • 问题:当应用使用 .umirc.ts 作为配置文件,执行 pnpm dlx @umijs/codemod@latest 命令报配置文件未找到错误
  • 处理:prepare 过程获知配置文件路径,通过 context 传入 ConfigRunner

Copy link

vercel bot commented Dec 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
umi ⬜️ Ignored (Inspect) Visit Preview Dec 7, 2023 6:13am

Copy link
Contributor

@fz6m fz6m left a 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么不直接改这一行而是要改下面很多行呢。

Copy link
Author

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 传递可以避免重复开发

Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议这个命名最好叫 mainConfigPath 或者 mainConfigFile ,因为 configPath 指代哪个 config 文件不明确。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants