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: 修复安装全局插件不支持传入 registry 的问题 #15537

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/taro-cli/src/presets/commands/global-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ export default (ctx: IPluginContext) => {
'taro global-config reset',
],
optionsMap: {
'-r --registry [url]': '指定 npm registry',
'-h, --help': 'output usage information'
},
fn ({ _ }) {
fn ({ _, options }) {
const [, action, pluginName] = _
const { getUserHomeDir, TARO_GLOBAL_CONFIG_DIR, fs, TARO_GLOBAL_CONFIG_FILE } = ctx.helper
const homedir = getUserHomeDir()
const globalPluginConfigDir = path.join(homedir, TARO_GLOBAL_CONFIG_DIR)
if (!homedir) return console.log('找不到用户根目录')
const rootPath = getRootPath()
const templatePath = path.join(rootPath, 'templates', 'global-config')
const registry = options.registry || options.r
function makeSureConfigExists () {
if (!fs.existsSync(globalPluginConfigDir)) {
const spinner = ora(`目录不存在,全局配置初始化`).start()
Expand Down Expand Up @@ -73,8 +75,12 @@ export default (ctx: IPluginContext) => {
spinner.fail('安装的插件名不合规!')
process.exit(1)
}
let command = `cd ${globalPluginConfigDir} && npm ${actionType} ${pluginName}`
if (registry) {
command += ` --registry=${registry}`
}
execCommand({
command: `cd ${globalPluginConfigDir} && npm ${actionType} ${pluginName}`,
command,
successCallback (data) {
console.log(data.replace(/\n$/, ''))
spinner.start(`开始修改${presetOrPluginChineseName}配置`)
Expand Down
Loading