From a8da82bc93a060dbc6c4c53b5b1c7bfd0fd9812c Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Fri, 20 Dec 2024 10:59:16 -0800 Subject: [PATCH] build(plugin-satp-hermes): dist/lib/knex/knexfile.ts not under rootDir 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 --- .../src/{ => main/typescript}/knex/knexfile-remote.ts | 0 .../src/{ => main/typescript}/knex/knexfile.ts | 0 .../knex/migrations/20220331132128_create_logs_table.ts | 0 .../20240130234303_create_remote_logs_table.ts | 0 .../knex/seeds/1724235145_create_dummy_entries.ts | 0 .../typescript/repository/knex-local-log-repository.ts | 9 ++++----- .../typescript/repository/knex-remote-log-repository.ts | 9 ++++----- 7 files changed, 8 insertions(+), 10 deletions(-) rename packages/cactus-plugin-satp-hermes/src/{ => main/typescript}/knex/knexfile-remote.ts (100%) rename packages/cactus-plugin-satp-hermes/src/{ => main/typescript}/knex/knexfile.ts (100%) rename packages/cactus-plugin-satp-hermes/src/{ => main/typescript}/knex/migrations/20220331132128_create_logs_table.ts (100%) rename packages/cactus-plugin-satp-hermes/src/{ => main/typescript}/knex/migrations/20240130234303_create_remote_logs_table.ts (100%) rename packages/cactus-plugin-satp-hermes/src/{ => main/typescript}/knex/seeds/1724235145_create_dummy_entries.ts (100%) diff --git a/packages/cactus-plugin-satp-hermes/src/knex/knexfile-remote.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/knex/knexfile-remote.ts similarity index 100% rename from packages/cactus-plugin-satp-hermes/src/knex/knexfile-remote.ts rename to packages/cactus-plugin-satp-hermes/src/main/typescript/knex/knexfile-remote.ts diff --git a/packages/cactus-plugin-satp-hermes/src/knex/knexfile.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/knex/knexfile.ts similarity index 100% rename from packages/cactus-plugin-satp-hermes/src/knex/knexfile.ts rename to packages/cactus-plugin-satp-hermes/src/main/typescript/knex/knexfile.ts diff --git a/packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/knex/migrations/20220331132128_create_logs_table.ts similarity index 100% rename from packages/cactus-plugin-satp-hermes/src/knex/migrations/20220331132128_create_logs_table.ts rename to packages/cactus-plugin-satp-hermes/src/main/typescript/knex/migrations/20220331132128_create_logs_table.ts diff --git a/packages/cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/knex/migrations/20240130234303_create_remote_logs_table.ts similarity index 100% rename from packages/cactus-plugin-satp-hermes/src/knex/migrations/20240130234303_create_remote_logs_table.ts rename to packages/cactus-plugin-satp-hermes/src/main/typescript/knex/migrations/20240130234303_create_remote_logs_table.ts diff --git a/packages/cactus-plugin-satp-hermes/src/knex/seeds/1724235145_create_dummy_entries.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/knex/seeds/1724235145_create_dummy_entries.ts similarity index 100% rename from packages/cactus-plugin-satp-hermes/src/knex/seeds/1724235145_create_dummy_entries.ts rename to packages/cactus-plugin-satp-hermes/src/main/typescript/knex/seeds/1724235145_create_dummy_entries.ts diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts index 43ba019cf9..62b6e27db3 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-local-log-repository.ts @@ -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); } diff --git a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts index 09a7b87488..99a5f42f89 100644 --- a/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts +++ b/packages/cactus-plugin-satp-hermes/src/main/typescript/repository/knex-remote-log-repository.ts @@ -2,6 +2,8 @@ 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; @@ -9,11 +11,8 @@ export class KnexRemoteLogRepository implements IRemoteLogRepository { // 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); }