From 8da290e905bcc00dfe159fe952dc5acf490a8566 Mon Sep 17 00:00:00 2001 From: "Li,Weitao" Date: Thu, 18 Apr 2024 21:17:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=85=A8=E6=8F=92=E4=BB=B6=E4=B8=8D=E6=94=AF=E6=8C=81=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=20registry=20=E7=9A=84=E9=97=AE=E9=A2=98=20(#15537)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taro-cli/src/presets/commands/global-config.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/taro-cli/src/presets/commands/global-config.ts b/packages/taro-cli/src/presets/commands/global-config.ts index 6b2068e685cd..5d1de85eade0 100644 --- a/packages/taro-cli/src/presets/commands/global-config.ts +++ b/packages/taro-cli/src/presets/commands/global-config.ts @@ -36,9 +36,10 @@ 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() @@ -46,6 +47,7 @@ export default (ctx: IPluginContext) => { 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() @@ -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}配置`)