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)
*/
@ -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));
};

6
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<string[]> => {
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) => {

Loading…
Cancel
Save