黄中银 3 недель назад
Родитель
Сommit
09a994fa6a
1 измененных файлов с 29 добавлено и 17 удалено
  1. 29 17
      ApqInstaller/electron/modules/installer.ts

+ 29 - 17
ApqInstaller/electron/modules/installer.ts

@@ -16,7 +16,7 @@ import {
 } from './constants'
 import { commandExistsWithRefresh, getCommandVersionWithRefresh, downloadFile, getTempDir, cancelCurrentDownload } from './utils'
 import { needsAptUpdate, markAptUpdated } from './source-updater'
-import { getGitDownloadUrl, getNodejsDownloadUrl, getVSCodeDownloadUrl } from './version-fetcher'
+import { getGitDownloadUrl, getNodejsDownloadUrl, getVSCodeDownloadUrl, getNodejsMirrorConfig } from './version-fetcher'
 import logger from './logger'
 
 // 当前安装进程
@@ -551,12 +551,16 @@ export async function installNodejs(
     // 使用完整路径,避免 PATH 未生效的问题
     const npmCmd = getNpmPath()
 
-    // 配置 npm 国内镜像
-    onStatus('nodejs', `${STATUS_MESSAGES.CONFIGURING} npm 镜像...`, 70)
-    try {
-      await executeCommand(npmCmd, ['config', 'set', 'registry', NPM_REGISTRY], false)
-    } catch (error) {
-      logger.installWarn('配置 npm 镜像失败(npm 可能还未加入 PATH)', error)
+    // 仅当使用国内镜像下载时,才配置 npm 国内镜像
+    const { mirror: nodejsMirror } = getNodejsMirrorConfig()
+    if (nodejsMirror === 'npmmirror') {
+      const npmConfigCmd = `${npmCmd} config set registry ${NPM_REGISTRY}`
+      onStatus('nodejs', `${STATUS_MESSAGES.CONFIGURING} npm 镜像: ${npmConfigCmd}`, 70)
+      try {
+        await executeCommand(npmCmd, ['config', 'set', 'registry', NPM_REGISTRY], false)
+      } catch (error) {
+        logger.installWarn('配置 npm 镜像失败(npm 可能还未加入 PATH)', error)
+      }
     }
 
     checkCancelled()
@@ -607,12 +611,16 @@ export async function installNodejs(
   // 使用完整路径,避免 PATH 未生效的问题
   const npmCmd = getNpmPath()
 
-  // 配置 npm 国内镜像
-  onStatus('nodejs', `${STATUS_MESSAGES.CONFIGURING} npm 镜像...`, 50)
-  try {
-    await executeCommand(npmCmd, ['config', 'set', 'registry', NPM_REGISTRY], false)
-  } catch (error) {
-    logger.installWarn('配置 npm 镜像失败(npm 可能还未加入 PATH)', error)
+  // 仅当使用国内镜像下载时,才配置 npm 国内镜像
+  const { mirror: nodejsMirrorMac } = getNodejsMirrorConfig()
+  if (nodejsMirrorMac === 'npmmirror') {
+    const npmConfigCmd = `${npmCmd} config set registry ${NPM_REGISTRY}`
+    onStatus('nodejs', `${STATUS_MESSAGES.CONFIGURING} npm 镜像: ${npmConfigCmd}`, 50)
+    try {
+      await executeCommand(npmCmd, ['config', 'set', 'registry', NPM_REGISTRY], false)
+    } catch (error) {
+      logger.installWarn('配置 npm 镜像失败(npm 可能还未加入 PATH)', error)
+    }
   }
 
   checkCancelled()
@@ -1049,10 +1057,14 @@ export async function installAll(options: InstallOptions, onStatus: StatusCallba
     // 使用完整路径,避免 PATH 未生效的问题
     const npmCmd = getNpmPath()
 
-    try {
-      await executeCommand(npmCmd, ['config', 'set', 'registry', NPM_REGISTRY], false)
-    } catch (error) {
-      logger.installWarn('配置 npm 镜像失败', error)
+    // 仅当使用国内镜像下载时,才配置 npm 国内镜像
+    const { mirror: nodejsMirrorAll } = getNodejsMirrorConfig()
+    if (nodejsMirrorAll === 'npmmirror') {
+      try {
+        await executeCommand(npmCmd, ['config', 'set', 'registry', NPM_REGISTRY], false)
+      } catch (error) {
+        logger.installWarn('配置 npm 镜像失败', error)
+      }
     }
     currentStep++