Skip to content

ConnectorRunner should not invoke require in loadConnector #40

Description

@jackson-at-bentley
// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions