diff --git a/packages/core/src/api/index.ts b/packages/core/src/api/index.ts index df7abca..6258ac9 100644 --- a/packages/core/src/api/index.ts +++ b/packages/core/src/api/index.ts @@ -71,8 +71,6 @@ export const getLocalConfig = (): ILocalConfig => { }; }; -// export const localConfig: ILocalConfig = getLocalConfig(); - /** * get local config data (saved in localStorage) */ @@ -80,7 +78,9 @@ export const updateLocalConfig = (config: ILocalConfig) => { const savedConfig = getLocalConfig(); savedConfig.ip = config.ip || savedConfig.ip; savedConfig.port = config.port || savedConfig.port; - savedConfig.npmRegistry = config.npmRegistry || savedConfig.npmRegistry; + savedConfig.npmRegistry = ( + config.npmRegistry || savedConfig.npmRegistry + ).replace(/\/$/, ''); localStorage.setItem(LOCAL_CONFIG_KEY, JSON.stringify(savedConfig)); }; diff --git a/packages/core/src/utils/analyzeDeps.ts b/packages/core/src/utils/analyzeDeps.ts index 019dd86..5309688 100644 --- a/packages/core/src/utils/analyzeDeps.ts +++ b/packages/core/src/utils/analyzeDeps.ts @@ -1,5 +1,6 @@ import axios from 'axios'; import { safeGet } from './index'; +import { getLocalConfig } from '../api'; const regex = /import\s([\s\S]*?)\sfrom\s(?:('[@\.\/\-\w]+')|("[@\.\/\-\w]+"))/gm; @@ -22,9 +23,10 @@ const extractPkgs = (code: string, excludePkgs?: string[]): string[] => { }; const getPkgLatestVersion = (pkg: string): Promise => { + const localConfig = getLocalConfig(); return axios - .get(`https://registry.npm.taobao.org/${pkg}`) - .then((res) => { + .get(`${localConfig.npmRegistry}/${pkg}`) + .then((res: any) => { return [pkg, safeGet(res, 'data.dist-tags.latest', '*')]; }) .catch((err) => {