-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat(create-mako): refactor create-mako #1751
Conversation
概述遍历此次更改主要涉及 变更
诗歌
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
WalkthroughThis pull request refactors the Changes
🪧 TipsFor further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. |
); | ||
const args = selectedPackageManager === 'yarn' ? [] : ['install']; | ||
try { | ||
await execa(selectedPackageManager, args, { |
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.
The execa
function is defined but not imported from any module. This could lead to a runtime error if execa
is not available in the current scope. Consider importing execa
from the appropriate module or replacing it with a suitable alternative.
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.
Actionable comments posted: 5
🧹 Nitpick comments (2)
packages/create-mako/src/cli.ts (1)
39-50
: 更新帮助信息以包含对bun
的支持帮助信息中未列出
bun
作为可选的包管理器,但在代码中支持bun
。应更新帮助信息以反映所有支持的包管理器。修复如下:
--template, -t Specify a template for the project --npm-client, -n Specify the npm client to use (pnpm, yarn, npm) + --npm-client, -n Specify the npm client to use (pnpm, yarn, npm, bun) Examples: create-mako Create a new project
packages/create-mako/src/create.ts (1)
51-51
: 删除多余的console.log('prompting');
语句第 51 行的
console.log('prompting');
似乎是调试代码,建议删除以保持代码简洁。修复如下:
console.log('prompting');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
package.json
(2 hunks)packages/create-mako/bin/create-mako.js
(1 hunks)packages/create-mako/package.json
(2 hunks)packages/create-mako/src/cli.ts
(1 hunks)packages/create-mako/src/create.ts
(1 hunks)packages/create-mako/templates/umi/_gitignore
(0 hunks)scripts/release-create-mako.ts
(0 hunks)
💤 Files with no reviewable changes (2)
- packages/create-mako/templates/umi/_gitignore
- scripts/release-create-mako.ts
✅ Files skipped from review due to trivial changes (1)
- packages/create-mako/bin/create-mako.js
⏰ Context from checks skipped due to timeout of 90000ms (13)
- GitHub Check: stable - i686-pc-windows-msvc - node@20
- GitHub Check: stable - x86_64-pc-windows-msvc - node@20
- GitHub Check: stable - aarch64-unknown-linux-musl - node@20
- GitHub Check: stable - aarch64-unknown-linux-gnu - node@20
- GitHub Check: Clippy
- GitHub Check: stable - x86_64-unknown-linux-musl - node@20
- GitHub Check: Mako Build (macos-latest)
- GitHub Check: stable - x86_64-unknown-linux-gnu - node@20
- GitHub Check: Mako Build (ubuntu-latest)
- GitHub Check: stable - aarch64-apple-darwin - node@20
- GitHub Check: Code Coverage
- GitHub Check: Cargo Test
- GitHub Check: stable - x86_64-apple-darwin - node@20
🔇 Additional comments (2)
package.json (2)
9-9
: 新增构建脚本符合项目规范!新增的
build:create-mako
脚本与项目中其他构建脚本保持一致的模式,使用 pnpm 工作空间过滤功能来构建特定包。
21-21
: 优化发布流程的改动很棒!将
release:create-mako
从自定义发布脚本改为使用 pnpm 工作空间命令是个很好的改进:
- 简化了发布流程
- 与其他包的发布命令(如
release:mako
)保持一致- 充分利用了 pnpm 工作空间的特性
const argv = yargsParser(process.argv.slice(2), { | ||
alias: { | ||
version: ['v'], | ||
help: ['h'], | ||
template: ['t'], | ||
}, | ||
boolean: ['version', 'help'], | ||
}); |
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.
缺少对 --npm-client
参数的解析
当前的 yargsParser
配置中,没有解析 --npm-client
或 -n
参数,导致 argv.packageManager
始终为 undefined
,无法正确传递给 create
函数。
建议在 alias
中添加对 packageManager
参数的映射,修复如下:
const argv = yargsParser(process.argv.slice(2), {
alias: {
version: ['v'],
help: ['h'],
template: ['t'],
+ packageManager: ['npm-client', 'n'],
},
boolean: ['version', 'help'],
});
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const argv = yargsParser(process.argv.slice(2), { | |
alias: { | |
version: ['v'], | |
help: ['h'], | |
template: ['t'], | |
}, | |
boolean: ['version', 'help'], | |
}); | |
const argv = yargsParser(process.argv.slice(2), { | |
alias: { | |
version: ['v'], | |
help: ['h'], | |
template: ['t'], | |
packageManager: ['npm-client', 'n'], | |
}, | |
boolean: ['version', 'help'], | |
}); |
.catch((err) => { | ||
p.cancel(`Create failed, ${err.message}`); |
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.
🛠️ Refactor suggestion
使用 p.cancel
处理错误可能不合适
p.cancel
通常用于用户取消操作。这里在捕获错误时使用 p.cancel
,可能不符合预期。建议使用 p.outro
或 p.error
来显示错误信息。
根据 @umijs/clack-prompt
的实际 API,修改如下:
.catch((err) => {
- p.cancel(`Create failed, ${err.message}`);
+ p.error(`Create failed, ${err.message}`);
process.exit(1);
});
或:
.catch((err) => {
- p.cancel(`Create failed, ${err.message}`);
+ p.outro(`Create failed, ${err.message}`);
process.exit(1);
});
请根据 @umijs/clack-prompt
的实际方法选择合适的替代方案。
Committable suggestion skipped: line range outside the PR's diff.
child.stdout?.on('data', (data) => { | ||
options.onData(data); | ||
}); | ||
child.stderr?.on('data', (data) => { | ||
options.onData(data); | ||
}); |
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.
确保子进程输出的数据被正确处理为字符串
在处理子进程输出时,data
可能是 Buffer 对象,需要在调用 options.onData
之前转换为字符串,否则可能导致输出显示异常或错误。
修复如下:
child.stdout?.on('data', (data) => {
- options.onData(data);
+ options.onData(data.toString());
});
child.stderr?.on('data', (data) => {
- options.onData(data);
+ options.onData(data.toString());
});
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
child.stdout?.on('data', (data) => { | |
options.onData(data); | |
}); | |
child.stderr?.on('data', (data) => { | |
options.onData(data); | |
}); | |
child.stdout?.on('data', (data) => { | |
options.onData(data.toString()); | |
}); | |
child.stderr?.on('data', (data) => { | |
options.onData(data.toString()); | |
}); |
"build": "utools bundle --patch-dirname", | ||
"release": "utools release" |
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.
缺少 utools
作为开发依赖
在 scripts
中使用了 utools
,但未在 devDependencies
中声明,可能导致构建或发布过程中的错误。
建议在 devDependencies
中添加 utools
:
"devDependencies": {
"tsx": "^4.19.2",
"typescript": "^5.6.3",
+ "utools": "^适当的版本号"
},
请根据项目要求填写 utools
的正确版本号。
Committable suggestion skipped: line range outside the PR's diff.
"@umijs/clack-prompt": "^0.0.3", | ||
"@umijs/tools": "^0.1.3", | ||
"gradient-string": "^3.0.0", | ||
"picocolors": "^1.1.1", | ||
"tsx": "^4.19.2", | ||
"typescript": "^5.6.3", | ||
"yargs-parser": "^21.1.1" |
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.
将运行时依赖从 devDependencies
移动到 dependencies
在代码中使用的包(如 @umijs/clack-prompt
、gradient-string
、picocolors
、yargs-parser
)是运行时依赖,应放在 dependencies
中。如果它们仅存在于 devDependencies
,当用户安装该包时,这些依赖不会被安装,导致运行时错误。
修复如下:
"devDependencies": {
- "@umijs/clack-prompt": "^0.0.3",
- "@umijs/tools": "^0.1.3",
- "gradient-string": "^3.0.0",
- "picocolors": "^1.1.1",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
- "yargs-parser": "^21.1.1"
},
+ "dependencies": {
+ "@umijs/clack-prompt": "^0.0.3",
+ "gradient-string": "^3.0.0",
+ "picocolors": "^1.1.1",
+ "yargs-parser": "^21.1.1"
+ },
Committable suggestion skipped: line range outside the PR's diff.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1751 +/- ##
=======================================
Coverage 54.81% 54.81%
=======================================
Files 180 180
Lines 18081 18081
=======================================
Hits 9911 9911
Misses 8170 8170 ☔ View full report in Codecov by Sentry. |
see picture.
Summary by CodeRabbit
依赖变更
create-mako
包中的glob
、inquirer
和yargs-parser
依赖@umijs/clack-prompt
、gradient-string
和picocolors
脚本更新
release:create-mako
脚本的执行方式create-mako
包的构建和发布脚本CLI 改进
模板调整
.gitignore
文件中的.swc
忽略项