Browse Source

feat: analyze dependences from custom config npm registry

master
Hans Chan 4 years ago
parent
commit
d407608393
  1. 6
      packages/core/src/api/index.ts
  2. 6
      packages/core/src/utils/analyzeDeps.ts

6
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) * get local config data (saved in localStorage)
*/ */
@ -80,7 +78,9 @@ export const updateLocalConfig = (config: ILocalConfig) => {
const savedConfig = getLocalConfig(); const savedConfig = getLocalConfig();
savedConfig.ip = config.ip || savedConfig.ip; savedConfig.ip = config.ip || savedConfig.ip;
savedConfig.port = config.port || savedConfig.port; 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)); localStorage.setItem(LOCAL_CONFIG_KEY, JSON.stringify(savedConfig));
}; };

6
packages/core/src/utils/analyzeDeps.ts

@ -1,5 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import { safeGet } from './index'; import { safeGet } from './index';
import { getLocalConfig } from '../api';
const regex = /import\s([\s\S]*?)\sfrom\s(?:('[@\.\/\-\w]+')|("[@\.\/\-\w]+"))/gm; 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<string[]> => { const getPkgLatestVersion = (pkg: string): Promise<string[]> => {
const localConfig = getLocalConfig();
return axios return axios
.get(`https://registry.npm.taobao.org/${pkg}`) .get(`${localConfig.npmRegistry}/${pkg}`)
.then((res) => { .then((res: any) => {
return [pkg, safeGet(res, 'data.dist-tags.latest', '*')]; return [pkg, safeGet(res, 'data.dist-tags.latest', '*')];
}) })
.catch((err) => { .catch((err) => {

Loading…
Cancel
Save