Only measure once when in group for Node.js

[GitHub #78]
This commit is contained in:
Aoran Zeng 2024-09-13 22:51:11 +08:00
parent 4b70835daf
commit 2e33ef697e
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
6 changed files with 81 additions and 83 deletions

View File

@ -7,9 +7,9 @@
* Contributors : Peng Gao <gn3po4g@outlook.com>
* |
* Created On : <2023-08-29>
* Last Modified : <2024-09-10>
* Last Modified : <2024-09-13>
*
* chsrc
* chsrc
* ------------------------------------------------------------*/
#include "xy.h"
@ -23,6 +23,9 @@ static int chsrc_get_cpucore ();
bool ProgMode_CMD_Measure = false;
bool ProgMode_CMD_Reset = false;
bool ProgMode_Target_Group = false;
int ProgMode_Leader_Selected_Index = -1;
/* 命令行选项 */
bool CliOpt_IPv6 = false;
@ -748,19 +751,31 @@ source_has_empty_url (SourceInfo *source)
return source->url == NULL;
}
/**
* ** SourceInfo
*
* 1. MirrorCode
* 2. ()
* 3. URL
* **5 SourceInfo
* option:
* 1. MirrorCode
* 2. NULL: ()
* 3. URL
* 4. ChsrcTypeReset
* Leader target
* 5. ProgMode_Leader_Selected_Index
*
* @dependency option
* @dependency source
*/
#define chsrc_yield_source(for_what) \
SourceInfo source; \
if (is_url (option)) \
#define chsrc_yield_the_source(for_what) \
if (ProgMode_Target_Group==true && ProgMode_Leader_Selected_Index==-1) \
{ \
ProgMode_Leader_Selected_Index = use_specific_mirror_or_auto_select (option, for_what); \
source = for_what##_sources[ProgMode_Leader_Selected_Index]; \
} \
else if (ProgMode_Target_Group==true && ProgMode_Leader_Selected_Index!=-1) \
{ \
source = for_what##_sources[ProgMode_Leader_Selected_Index]; \
} \
else if (is_url (option)) \
{ \
SourceInfo __tmp = { &UserDefine, option }; \
source = __tmp; \
@ -771,6 +786,11 @@ source_has_empty_url (SourceInfo *source)
source = for_what##_sources[__index]; \
}
#define chsrc_yield_source(for_what) \
SourceInfo source; \
chsrc_yield_the_source(for_what)
#define split_between_source_changing_process puts ("--------------------------------")
@ -793,7 +813,7 @@ confirm_source (SourceInfo *source)
// 之所以禁用,是因为有的 reset 我们并没有实现,我们在这里阻止这些邪恶的用户
if (source_is_upstream (source) && source_has_empty_url (source))
{
char *msg = CliOpt_InEnglish ? "Not implement RESET for the target yet" : "暂未对该目标实现重置";
char *msg = CliOpt_InEnglish ? "Not implement `reset` for the target yet" : "暂未对该目标实现重置";
chsrc_error (msg);
exit (Exit_Unsupported);
}

View File

@ -5,26 +5,9 @@
* Contributors : Mr. Will <mr.will.com@outlook.com>
* Created On : <2023-08-30>
* Major Revision : 2
* Last Modified : <2024-09-10>
* Last Modified : <2024-09-13>
* ------------------------------------------------------------*/
/**
* @time 2024-04-18
* @note {
* Sjtug, Tuna, Lzuoss, Jlu, Bfsu,
* npm源一直未证实是否可用
* }
*/
static SourceInfo
pl_nodejs_sources[] = {
{&Upstream, "https://registry.npmjs.org/"},
{&NpmMirror, "https://registry.npmmirror.com"},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"},
{&Zju, "https://mirrors.zju.edu.cn/npm"}
};
def_sources_n(pl_nodejs);
void
pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist)
{
@ -79,11 +62,19 @@ pl_nodejs_getsrc (char *option)
void
pl_nodejs_setsrc (char *option)
{
{
char *msg = CliOpt_InEnglish ? "** Three package managers will be replaced for you at the same time: " \
"npm, pnpm, yarn. If you need to change the source independently, " \
"please run independently `chsrc set <pkg-manager>` **\n"
: "** 将同时为您更换3个包管理器 npm, pnpm, Yarn 的源,若需要独立换源,请独立运行 chsrc set <pkg-manager> **\n";
chsrc_log (bdyellow(msg));
}
bool npm_exist, yarn_exist, pnpm_exist;
pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist);
// chsrc_yield_source_and_confirm (pl_nodejs);
split_between_source_changing_process;
ProgMode_Target_Group = true;
chsrc_yield_source_and_confirm (pl_nodejs);
if (npm_exist)
{
@ -100,10 +91,7 @@ pl_nodejs_setsrc (char *option)
if (pnpm_exist)
{
pl_nodejs_pnpm_setsrc (option);
say ("");
}
// chsrc_conclude (&source, ChsrcTypeAuto);
}

View File

@ -8,19 +8,6 @@
* Last Modified : <2024-09-13>
* ------------------------------------------------------------*/
/**
* @update 2024-04-08
*/
static SourceInfo
pl_nodejs_yarn_sources[] = {
{&Upstream, "https://registry.npmjs.org/"}, // @note 根据 pnpm 官网,有最后的斜线
{&NpmMirror, "https://registry.npmmirror.com"},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"},
{&Zju, "https://mirrors.zju.edu.cn/npm"}
};
def_sources_n(pl_nodejs_yarn);
static double
pl_nodejs_yarn_get_yarn_version ()
{
@ -53,7 +40,10 @@ pl_nodejs_yarn_getsrc (char *option)
void
pl_nodejs_yarn_setsrc (char *option)
{
chsrc_yield_source_and_confirm (pl_nodejs_yarn);
SourceInfo source;
chsrc_yield_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
char *cmd = NULL;
@ -115,4 +105,5 @@ pl_nodejs_yarn_feat (char *option)
return fi;
}
def_target_gsrf(pl_nodejs_yarn);
// def_target_gsrf(pl_nodejs_yarn);
TargetInfo pl_nodejs_yarn_target = {def_target_inner_gsrf(pl_nodejs_yarn),def_target_sourcesn(pl_nodejs)};

View File

@ -5,10 +5,27 @@
* Contributors : Nul None <nul@none.org>
* Created On : <2023-09-09>
* Major Revision : 1
* Last Modified : <2024-09-10>
* Last Modified : <2024-09-13>
* ------------------------------------------------------------*/
static MirrorSite
NpmMirror = {"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "https://npmmirror.com/",
// 注意,这个是跳转后的地址,不确定未来会不会改变
"https://cdn.npmmirror.com/packages/%40tensorflow/tfjs/4.10.0/tfjs-4.10.0.tgz"}; // 29MB
/**
* @time 2024-04-18
* @note {
* Sjtug, Tuna, Lzuoss, Jlu, Bfsu,
* npm源一直未证实是否可用
* }
*/
static SourceInfo
pl_nodejs_sources[] = {
{&Upstream, "https://registry.npmjs.org/"}, // @note 根据 pnpm 官网,有最后的斜线
{&NpmMirror, "https://registry.npmmirror.com"},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"},
{&Zju, "https://mirrors.zju.edu.cn/npm"}
};
def_sources_n(pl_nodejs);

View File

@ -5,22 +5,9 @@
* Contributors : Mr. Will <mr.will.com@outlook.com>
* Created On : <2023-08-30>
* Major Revision : 2
* Last Modified : <2024-09-10>
* Last Modified : <2024-09-13>
* ------------------------------------------------------------*/
/**
* @update 2024-04-08
*/
static SourceInfo
pl_nodejs_npm_sources[] = {
{&Upstream, "https://registry.npmjs.org/"}, // @note 根据 pnpm 官网,有最后的斜线
{&NpmMirror, "https://registry.npmmirror.com"},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"},
{&Zju, "https://mirrors.zju.edu.cn/npm"}
};
def_sources_n(pl_nodejs_npm);
/**
* chsrc get npm
*/
@ -39,7 +26,10 @@ pl_nodejs_npm_getsrc (char *option)
void
pl_nodejs_npm_setsrc (char *option)
{
chsrc_yield_source_and_confirm (pl_nodejs_npm);
SourceInfo source;
chsrc_yield_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
char *cmd = NULL;
@ -84,4 +74,5 @@ pl_nodejs_npm_feat (char *option)
return fi;
}
def_target_gsrf(pl_nodejs_npm);
// def_target_gsrf(pl_nodejs_npm);
TargetInfo pl_nodejs_npm_target = {def_target_inner_gsrf(pl_nodejs_npm),def_target_sourcesn(pl_nodejs)};

View File

@ -5,22 +5,9 @@
* Contributors : Nul None <nul@none.org>
* Created On : <2024-04-18>
* Major Revision : 2
* Last Modified : <2024-09-10>
* Last Modified : <2024-09-13>
* ------------------------------------------------------------*/
/**
* @update 2024-04-08
*/
static SourceInfo
pl_nodejs_pnpm_sources[] = {
{&Upstream, "https://registry.npmjs.org/"}, // @note 根据 pnpm 官网,有最后的斜线
{&NpmMirror, "https://registry.npmmirror.com"},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"},
{&Zju, "https://mirrors.zju.edu.cn/npm"}
};
def_sources_n(pl_nodejs_pnpm);
/**
* chsrc get pnpm
*/
@ -40,7 +27,10 @@ pl_nodejs_pnpm_getsrc (char *option)
void
pl_nodejs_pnpm_setsrc (char *option)
{
chsrc_yield_source_and_confirm (pl_nodejs_pnpm);
SourceInfo source;
chsrc_yield_the_source (pl_nodejs);
if (ProgMode_Target_Group!=true)
chsrc_confirm_source;
char *cmd = NULL;
@ -86,4 +76,5 @@ pl_nodejs_pnpm_feat (char *option)
}
def_target_gsrf(pl_nodejs_pnpm);
// def_target_gsrf(pl_nodejs_pnpm);
TargetInfo pl_nodejs_pnpm_target = {def_target_inner_gsrf(pl_nodejs_pnpm),def_target_sourcesn(pl_nodejs)};