Skip to content

Commit

Permalink
fix: 修复安装全插件不支持传入 registry 的问题 (#15537)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam authored Apr 18, 2024
1 parent b3e4a35 commit 8da290e
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 8da290e

Please sign in to comment.