Skip to content

Commit

Permalink
build(plugin-satp-hermes): dist/lib/knex/knexfile.ts not under rootDir
Browse files Browse the repository at this point in the history
1. Moved the typescript knex sources into the appropriate directory to match
the established patterns we use for building the code (./src/main/typescript/)
This fixed the problem of the bundler not finding the knexfile sources.
2. Also refactored the runtime require calls of the knex files to be build-time
import statements instead. This came with the benefit that we no longer require
the linter to be turned off and also that compile time checks are in effect.
In the future if we want to go back to importing the knex files dynamically
we could do so by adding a parameter to the log repository constructor parameter
object which could be holding the path to a knex file to be included at runtime.
(though I would only do this if we have no other choice - by default we should
always thrive to use the compiler and do as much at build time as possible).

Fixes #3708

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz authored and RafaelAPB committed Jan 17, 2025
1 parent 1737df4 commit a8da82b
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { LocalLog } from "../core/types";
import { ILocalLogRepository } from "./interfaces/repository";
import knex, { Knex } from "knex";

import knexFile from "../knex/knexfile";

export class KnexLocalLogRepository implements ILocalLogRepository {
readonly database: Knex;

public constructor(config: Knex.Config | undefined) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const configFile = require("../../../knex/knexfile.ts")[
process.env.ENVIRONMENT || "development"
];

const envName = process.env.ENVIRONMENT || "development";
const configFile = knexFile[envName];
this.database = knex(config || configFile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { IRemoteLogRepository } from "./interfaces/repository";
import { RemoteLog } from "../core/types";
import knex, { Knex } from "knex";

import knexFileRemote from "../knex/knexfile-remote";

export class KnexRemoteLogRepository implements IRemoteLogRepository {
readonly database: Knex;

// for now we will ignore the config because it needs to be static
// so that both gateways can have access to the same database
// simulating a remote log storage
public constructor(config: Knex.Config | undefined) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const configFile = require("../../../knex/knexfile-remote.ts")[
process.env.ENVIRONMENT || "development"
];

const envName = process.env.ENVIRONMENT || "development";
const configFile = knexFileRemote[envName];
this.database = knex(config || configFile);
}

Expand Down

0 comments on commit a8da82b

Please sign in to comment.