MCPcopy Index your code
hub / github.com/web-infra-dev/garfish / asyncLoadProcess

Function asyncLoadProcess

packages/remote-module/src/apis/loadModule.ts:45–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43 const urlWithVersion = `${version || 'latest'}@${url}`; // `latest@https://xx.js`
44
45 const asyncLoadProcess = async () => {
46 let result: Record<string, any> | null = null;
47 let module = cacheModules[urlWithVersion];
48
49 if (cache && module) {
50 if (isPromise(module)) {
51 module = await module;
52 }
53 result = getValueInObject(module, segments);
54 } else {
55 try {
56 const data = await loader.loadModule(url);
57 if (data.resourceManager) {
58 const actuator = new Actuator(data.resourceManager, externals);
59 cacheModules[urlWithVersion] = actuator.env.exports;
60 let exports = actuator.execScript().exports;
61
62 if (typeof adapter === 'function') {
63 exports = adapter(exports);
64 }
65 const hookResult = await hooks.lifecycle.asyncAfterLoadModule.emit({
66 url,
67 exports,
68 code: data.resourceManager.moduleCode,
69 });
70 if (hookResult === false) {
71 return null;
72 }
73 exports = hookResult.exports;
74
75 cacheModules[urlWithVersion] = exports;
76 if (isPromise(exports)) {
77 exports = await exports;
78 }
79 result = getValueInObject(exports, segments);
80 }
81 } catch (e) {
82 delete cacheModules[urlWithVersion];
83 const alias = segments ? segments[0] : '';
84 if (typeof error === 'function') {
85 result = error(e, info, alias);
86 } else {
87 throw prettifyError(e, alias, url);
88 }
89 }
90 }
91 return result;
92 };
93
94 if (fetchLoading[urlWithVersion]) {
95 return fetchLoading[urlWithVersion].then(() => {

Callers 2

loadModuleFunction · 0.85
loadAppMethod · 0.85

Calls 7

execScriptMethod · 0.95
isPromiseFunction · 0.90
getValueInObjectFunction · 0.90
prettifyErrorFunction · 0.90
loadModuleMethod · 0.80
errorFunction · 0.50
emitMethod · 0.45

Tested by

no test coverage detected