Skip to content

Commit

Permalink
fix: 优化nrm获取异常问题和补充单测
Browse files Browse the repository at this point in the history
  • Loading branch information
beezen committed Jan 22, 2024
1 parent 89dbed2 commit 7ce629a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions __tests__/actions/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("action_base", () => {
let registryName = getRegistryConfig(config).registryName;
let accountObject = nucmrcConfig[registryName];
let currentAccountName = ""; // 当前账号名
Object.keys(accountObject).forEach(name => {
Object.keys(accountObject).forEach((name) => {
if (accountObject[name]["is-current"]) {
currentAccountName = name;
}
Expand Down Expand Up @@ -41,7 +41,6 @@ describe("action_base", () => {
expect(getUserList({}).indexOf(name2) > -1).toBeTruthy();
expect(getUserList({ all: true }).indexOf(name2) > -1).toBeTruthy();
});

// 还原单测前状态
it("backup", () => {
removeUser(name2);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe("utils", () => {
initLanguage(); // 初始化 i18next
const langCn = require("../../src/lang/default/zh/base.json");
const langEn = require("../../src/lang/default/en/base.json");
expect(printLog("command.version", { isPrint: false, lng: "cn" })).toBe(langCn.command.version);
expect(printLog("command.version", { isPrint: false, lng: "en" })).toBe(langEn.command.version);
expect(printLog("command.version", { isPrint: false, lng: "cn" })).toBe(langCn.command.version);
});

it("getPackageManager", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/actions/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export function getUserList(options) {
custom: ["black", "bgBrightYellow"]
});
if (options.all) {
delete nucmrcConfig.baseConfig;
userList = Object.keys(nucmrcConfig)
const { baseConfig, ...accountConfig } = nucmrcConfig;
userList = Object.keys(accountConfig)
.map((registryName) => {
let registryNameStr =
registryName === registryConfig.registryName
? colors.custom(`【${registryName}】`)
: `【${registryName}】`;
return `${registryNameStr}\n${getListInfo(nucmrcConfig[registryName])}`;
return `${registryNameStr}\n${getListInfo(accountConfig[registryName])}`;
})
.join("\n\n");
printLog(userList);
Expand Down
8 changes: 4 additions & 4 deletions src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function checkConfigInit() {
if (!fs.existsSync(nucmrc_path)) {
const defaultBaseConfig = {
baseConfig: {
lang: "en",
lang: "cn",
checkUpdateDate: Date.now()
}
};
Expand Down Expand Up @@ -148,17 +148,17 @@ export function prepareEnv(callback) {
Object.assign(baseInitConfig, {
fileConfig, // 配置文件
registryConfig, // 源配置
lang: fileConfig?.nucm?.baseConfig?.lang || "en" // 语言
lang: fileConfig?.nucm?.baseConfig?.lang || "cn" // 语言
});
changeLanguage(baseInitConfig.lang);
callback && callback(baseInitConfig);
}

/**
* 初始化本地语言
* @param {string} lng 语言类型 en|zh
* @param {string} lng 语言类型 en|cn
*/
export function initLanguage(lng = "en") {
export function initLanguage(lng = "cn") {
init({
resources: resourcesAll,
lng,
Expand Down
7 changes: 4 additions & 3 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ export function printLog(message, options = {}) {

/** 获取 nrm 模块 */
export function getNrmModule() {
const npmBinPath = shell.exec("npm bin", { silent: true }).stdout.trim();
const nrmCli = path.join(npmBinPath, "nrm");
if (fs.existsSync(nrmCli)) return nrmCli;
try {
const nrmCli = require.resolve("nrm/cli.js");
if (fs.existsSync(nrmCli)) return nrmCli;
} catch (_err) {}
return "";
}

Expand Down

0 comments on commit 7ce629a

Please sign in to comment.