Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions packages/runtime/src/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,45 @@ class Module {
`${getFMId(this.remoteInfo)} remote don't export ${expose}.`,
);

const wrapModuleFactory = this.wraperFactory(moduleFactory, id);

if (!loadFactory) {
return moduleFactory;
return wrapModuleFactory;
}
const exposeContent = await moduleFactory();

// This parameter is used for bridge debugging
Object.defineProperty(exposeContent, Symbol.for('mf_module_id'), {
value: id,
enumerable: false,
});
const exposeContent = await wrapModuleFactory();

return exposeContent;
}

private wraperFactory(
moduleFactory: () => any | (() => Promise<any>),
id: string,
) {
function defineModuleId(res: any, id: string) {
if (res && typeof res === 'object') {
Object.defineProperty(res, Symbol.for('mf_module_id'), {
value: id,
enumerable: false,
});
}
}

if (moduleFactory instanceof Promise) {
return async () => {
const res = await moduleFactory();
// This parameter is used for bridge debugging
defineModuleId(res, id);
return res;
};
} else {
return () => {
const res = moduleFactory();
// This parameter is used for bridge debugging
defineModuleId(res, id);
return res;
};
}
}
}

export { Module };