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

Class FPLNodeModuleFactory

src/back/extensions/NodeInterceptor.ts:82–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81/** Module interceptor for the Flashpoint API 'flashpoint-launcher' module */
82export class FPLNodeModuleFactory implements INodeModuleFactory {
83 public readonly nodeModuleName = 'flashpoint-launcher';
84
85 private readonly _extApiImpl = new Map<string, typeof flashpoint>();
86 private _defaultApiImpl?: typeof flashpoint;
87 private readonly _apiFactory: IExtensionApiFactory;
88
89 constructor(
90 protected readonly _extensionPaths: TernarySearchTree<string, IExtension>,
91 private readonly _addExtLogFactory: (extId: string) => (entry: ILogEntry) => void,
92 private readonly _version: string,
93 private readonly _state: BackState
94 ) {
95 this._apiFactory = createApiFactory;
96 }
97
98 /**
99 * Return an API implementation given an import request
100 *
101 * @param _request Unused
102 * @param parent Module that made this request, substring of an extension path
103 */
104 public load(_request: string, parent: string): any {
105 const ext = this._extensionPaths.findSubstr(parent);
106 if (ext) {
107 // Call was from an extension, use its own implementation
108 let apiImpl = this._extApiImpl.get(ext.id);
109 if (!apiImpl) {
110 // No API for extension yet, make one
111 apiImpl = this._apiFactory(
112 ext.id,
113 ext.manifest,
114 this._addExtLogFactory(ext.id),
115 this._version,
116 this._state,
117 ext.extensionPath);
118 this._extApiImpl.set(ext.id, apiImpl);
119 }
120 return apiImpl;
121 }
122
123 // Import not from an extension, give default implementation
124 if (!this._defaultApiImpl) {
125 this._defaultApiImpl = this._apiFactory(
126 '',
127 nullExtensionDescription,
128 this._addExtLogFactory('null'),
129 this._version,
130 this._state);
131 }
132 return this._defaultApiImpl;
133 }
134}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected