-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import * as t from '@umijs/bundler-utils/compiled/babel/types'; | ||
import { lodash } from '@umijs/utils'; | ||
import assert from 'assert'; | ||
import { existsSync, readFileSync, writeFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { update as appJSUpdate } from '../appJSUpdater'; | ||
import { update } from '../configUpdater'; | ||
import { info } from '../logger'; | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 这里可以这样获得最少的代码更改吧: const configFile = this.context.configPath; |
||
assert( | ||
existsSync(configFile), | ||
`Could not find config file at ${configFile}`, | ||
); | ||
const { | ||
config: { code }, | ||
routesConfig: { filePath: routeFilePath, code: routeCode } = {} as any, | ||
} = update({ | ||
code: readFileSync(configFile, 'utf-8'), | ||
filePath: configFile, | ||
code: readFileSync(this.context.configPath, 'utf-8'), | ||
filePath: this.context.configPath, | ||
updates: { | ||
del: deleteKeys, | ||
set: setKeys, | ||
|
@@ -164,7 +157,7 @@ export class Runner { | |
}, | ||
}, | ||
}); | ||
writeFileSync(configFile, code); | ||
writeFileSync(this.context.configPath, code); | ||
if (routeCode) { | ||
writeFileSync(routeFilePath, routeCode); | ||
} | ||
|
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.
好的