Skip to content

Commit 6f0ef7d

Browse files
authored
feat(runtime): add bridge debug info (#2573)
1 parent 4f22c3e commit 6f0ef7d

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

packages/runtime/src/module/index.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,45 @@ class Module {
122122
`${getFMId(this.remoteInfo)} remote don't export ${expose}.`,
123123
);
124124

125+
const wrapModuleFactory = this.wraperFactory(moduleFactory, id);
126+
125127
if (!loadFactory) {
126-
return moduleFactory;
128+
return wrapModuleFactory;
127129
}
128-
const exposeContent = await moduleFactory();
129-
130-
// This parameter is used for bridge debugging
131-
Object.defineProperty(exposeContent, Symbol.for('mf_module_id'), {
132-
value: id,
133-
enumerable: false,
134-
});
130+
const exposeContent = await wrapModuleFactory();
135131

136132
return exposeContent;
137133
}
134+
135+
private wraperFactory(
136+
moduleFactory: () => any | (() => Promise<any>),
137+
id: string,
138+
) {
139+
function defineModuleId(res: any, id: string) {
140+
if (res && typeof res === 'object') {
141+
Object.defineProperty(res, Symbol.for('mf_module_id'), {
142+
value: id,
143+
enumerable: false,
144+
});
145+
}
146+
}
147+
148+
if (moduleFactory instanceof Promise) {
149+
return async () => {
150+
const res = await moduleFactory();
151+
// This parameter is used for bridge debugging
152+
defineModuleId(res, id);
153+
return res;
154+
};
155+
} else {
156+
return () => {
157+
const res = moduleFactory();
158+
// This parameter is used for bridge debugging
159+
defineModuleId(res, id);
160+
return res;
161+
};
162+
}
163+
}
138164
}
139165

140166
export { Module };

0 commit comments

Comments
 (0)