Skip to content

Commit

Permalink
build(4.9.7): 优化isEmitVerMatchInputVer
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyzhong committed Jun 11, 2024
1 parent 2c48cbb commit e14cfb0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

[released] - 2024-06-11

发布 `hel-micro`,版本`4.9.7`,特性包含:

- `isEmitVerMatchInputVer` 支持透传 `branchId` 做更准确的判断,避免 `waitAppReady` 函数一直处于等待状态

[released] - 2024-06-06

发布 `hel-micro`,版本`4.9.6`,特性包含:
Expand Down
2 changes: 1 addition & 1 deletion packages/hel-micro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hel-micro",
"version": "4.9.6",
"version": "4.9.7",
"description": "A module federation SDK which is unrelated to tool chain for module consumer.",
"keywords": [
"hel",
Expand Down
2 changes: 1 addition & 1 deletion packages/hel-micro/src/consts/ver.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VER = '4.9.6';
export const VER = '4.9.7';
8 changes: 3 additions & 5 deletions packages/hel-micro/src/services/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,11 @@ export async function getAppFromRemoteOrLocal(appName: string, options: IInnerPr
const memApp = core.getAppMeta(appName, platform);
const memAppVersion = core.getVersion(appName, { platform, versionId });

// 优先从内存获取(非语义化api获取的 memAppVersion 才是有意义的,可进入此逻辑做判断)
// 优先从内存获取(非语义化api、未传递分支时获取的 memAppVersion 才是有意义的,可进入此逻辑做判断)
// TODO : semverApi 下沉到 isEmitVerMatchInputVer 里面
const compareMem = !semverApi && !branchId && memApp && memAppVersion;
if (
!semverApi
&& !branchId
&& memApp
&& memAppVersion
compareMem
&& isEmitVerMatchInputVer(appName, { platform, projectId, emitVer: memAppVersion.sub_app_version, inputVer: versionId, strictMatchVer })
) {
return { appInfo: memApp, appVersion: memAppVersion };
Expand Down
8 changes: 4 additions & 4 deletions packages/hel-micro/src/services/appStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ const inner = {
await new Promise((resolve) => {
handleStyleFetched = (styleInfo: IEmitStyleInfo) => {
const { appName: emitAppName, platform: emitPlatform, versionId: emitVer } = styleInfo;
const { versionId: inputVer, platform, strictMatchVer } = options;
const { branchId, versionId: inputVer, platform, strictMatchVer } = options;
if (
emitAppName !== appName
|| emitPlatform !== platform
|| !isEmitVerMatchInputVer(appName, { platform, emitVer, inputVer, strictMatchVer })
|| !isEmitVerMatchInputVer(appName, { branchId, platform, emitVer, inputVer, strictMatchVer })
) {
return;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ const inner = {

async fetchStyleData(appName: string, options: IFetchStyleOptions) {
const platAndVer = getPlatAndVer(appName, options);
const { extraStyleStr = '', cssListToStr, extraCssList = [] } = options;
const { extraStyleStr = '', cssListToStr, extraCssList = [], strictMatchVer, branchId } = options;
const { validCssList, onlyUseAppCssList, buildCssList, initExtraCssList, appCssList } = inner.computeStyleData(appName, options);

// renderStyleStr 为渲染用到的样式字符串
Expand All @@ -165,7 +165,7 @@ const inner = {

// 有其他上层调用已经触发样式获取逻辑,这里调用 waitStyleReady 等待样式获取动作完成即可
if (status === LOADING) {
await inner.waitStyleReady(appName, { ...platAndVer, strictMatchVer: options.strictMatchVer });
await inner.waitStyleReady(appName, { ...platAndVer, strictMatchVer, branchId });
appStyleStr = core.getAppStyleStr(appName, platAndVer) || '';
} else if (status === NOT_LOAD) {
core.setVerStyleStrStatus(appName, LOADING, platAndVer);
Expand Down
4 changes: 2 additions & 2 deletions packages/hel-micro/src/services/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function judgeAppReady(appInfo: IEmitAppInfo, options: IJudgeOptions, pre
const appPathDesc = `${platform}/${appName}/${inputVer}`;
const appMeta = getAppMeta(appName, platform);

const { custom, trust } = preFetchOptions;
const { branchId, custom, trust } = preFetchOptions;
const fixData = (fixOptions: IFixOptions) => {
try {
const shouldNext = isLib
Expand Down Expand Up @@ -181,7 +181,7 @@ export function judgeAppReady(appInfo: IEmitAppInfo, options: IJudgeOptions, pre

const logStillWait = () => log(`${fnMark} still wait ${appPathDesc} emitted (appInfo,toMatch):`, appInfo, toMatch);
// 啥也不做,等待平台值匹配、应用名匹配的那个事件发射上来
const toMatch = { platform, emitVer, inputVer, projectId, strictMatchVer };
const toMatch = { branchId, platform, emitVer, inputVer, projectId, strictMatchVer };
if (appName !== emitAppName || !isEmitVerMatchInputVer(appName, toMatch)) {
return logStillWait();
}
Expand Down
11 changes: 9 additions & 2 deletions packages/hel-micro/src/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ interface IVerMatchOptions {
strictMatchVer?: boolean;
platform?: Platform;
projectId?: string;
branchId?: string;
}
const fnMark = '[[ isEmitVerMatchInputVer ]]';

/**
* @returns true,匹配成功,false,匹配失败
*/
export function isEmitVerMatchInputVer(appName: string, options: IVerMatchOptions) {
const fnMark = '[[ isEmitVerMatchInputVer ]]';
const { platform, emitVer, inputVer, projectId } = options;
const { branchId, platform, emitVer, inputVer, projectId } = options;
const strictMatchVer = alt.getVal(platform, 'strictMatchVer', [options.strictMatchVer]);

const appMeta = getAppMeta(appName, platform);
Expand All @@ -32,6 +33,12 @@ export function isEmitVerMatchInputVer(appName: string, options: IVerMatchOption

// 用在线版本或灰度版本比较
if (!inputVer && appMeta) {
// 存在分支id的话,采取总是相信子模块的策略
if (branchId) {
log(`${fnMark} found branchId ${branchId}`);
return true;
}

const { online_version, build_version } = appMeta;
// 判断 projectId 是否传入,传入的话看 proj_ver.map[projectId].o 的值是否存在且是否和 emitVer 相等
if (projectId) {
Expand Down
2 changes: 2 additions & 0 deletions packages/hel-micro/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ILinkAttrs, IScriptAttrs, ISubApp, ISubAppVersion } from 'hel-type
export interface IGetOptionsLoose {
platform?: string;
versionId?: string;
branchId?: string;
}

export type AssetUrlType = 'build' | 'static' | 'relative';
Expand Down Expand Up @@ -42,6 +43,7 @@ export interface IPlatAndVer {
export interface IWaitStyleReadyOptions extends IPlatAndVer {
platform: string;
versionId: string;
branchId?: string;
strictMatchVer?: boolean;
}

Expand Down

0 comments on commit e14cfb0

Please sign in to comment.