MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / installNodeInterceptor

Function installNodeInterceptor

src/back/extensions/NodeInterceptor.ts:54–75  ·  view source on GitHub ↗
(state: InterceptorState)

Source from the content-addressed store, hash-verified

52 * @param state State object holding all interceptor data
53 */
54export async function installNodeInterceptor(state: InterceptorState): Promise<void> {
55 const { alternatives, factories } = state;
56 const node_module: any = await import('module');
57 const original = node_module._load;
58 node_module._load = function load(request: string, parent: { path: string, filename: string; }, isMain: any) {
59 for (const alternativeModuleName of alternatives) {
60 const alternative = alternativeModuleName(request);
61 if (alternative) {
62 request = alternative;
63 break;
64 }
65 }
66 if (!factories.has(request)) {
67 return original.apply(this, arguments);
68 }
69 return factories.get(request)!.load(
70 request,
71 parent.filename,
72 request => original.apply(this, [request, parent, isMain])
73 );
74 };
75}
76
77interface IExtensionApiFactory {
78 (id: string, ext: IExtensionManifest, addExtLog: (entry: ILogEntry) => void, version: string, state: BackState, extPath?: string): typeof flashpoint;

Callers 1

initializeFunction · 0.90

Calls 2

getMethod · 0.80
loadMethod · 0.65

Tested by

no test coverage detected