(state: InterceptorState)
| 52 | * @param state State object holding all interceptor data |
| 53 | */ |
| 54 | export 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 | |
| 77 | interface IExtensionApiFactory { |
| 78 | (id: string, ext: IExtensionManifest, addExtLog: (entry: ILogEntry) => void, version: string, state: BackState, extPath?: string): typeof flashpoint; |
no test coverage detected