// ConnectorRunner.ts
private async loadConnector(connectorFile: string) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const connectorClass = require(connectorFile).default;
this._connector = await connectorClass.create();
}
A connector is a subtype of BaseConnector and should be passed to the connector runner as an instance.
Invoking require seems like a bad idea in an npm package for two reasons.
- The import is relative to the file that called
require. This means users of our API must specify their connector relative to node_modules, or use an absolute path.
- Our API does not support connectors written as ES modules. Users are required to compile to CommonJS.
If we want the connector constructor to be asynchronous, we can pass the class object to the connector runner, or make create an instance method.
A connector is a subtype of
BaseConnectorand should be passed to the connector runner as an instance.Invoking
requireseems like a bad idea in annpmpackage for two reasons.require. This means users of our API must specify their connector relative tonode_modules, or use an absolute path.If we want the connector constructor to be asynchronous, we can pass the class object to the connector runner, or make
createan instance method.