From d8a80fd8f9e47dc8ab9a24f93c574e1a4c8b16e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Burkard?= <22095555+JeromeBu@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:36:33 +0100 Subject: [PATCH] get root package.json api version (instead of the one from api/package.json) --- api/src/rpc/router.ts | 38 +++++++++---------- ...tRoot.ts => getMonorepoRootPackageJson.ts} | 13 +++---- 2 files changed, 24 insertions(+), 27 deletions(-) rename api/src/tools/{getProjectRoot.ts => getMonorepoRootPackageJson.ts} (50%) diff --git a/api/src/rpc/router.ts b/api/src/rpc/router.ts index d83e4b35..594517ba 100644 --- a/api/src/rpc/router.ts +++ b/api/src/rpc/router.ts @@ -1,29 +1,27 @@ -import type { ReturnType } from "tsafe"; -import { TRPCError } from "@trpc/server"; -import { assert } from "tsafe/assert"; -import { z } from "zod"; +import { initTRPC, TRPCError } from "@trpc/server"; import * as fs from "fs"; -import { join as pathJoin } from "path"; -import { getProjectRoot } from "../tools/getProjectRoot"; -import fetch from "node-fetch"; -import type { Core, Context as CoreContext } from "../core"; -import type { Context } from "./context"; -import type { User } from "./user"; -import type { KeycloakParams } from "../tools/createValidateKeycloakSignature"; +import { createResolveLocalizedString } from "i18nifty/LocalizedString/reactless"; import memoize from "memoizee"; +import fetch from "node-fetch"; +import { join as pathJoin } from "path"; +import superjson from "superjson"; +import type { Equals, ReturnType } from "tsafe"; +import { assert } from "tsafe/assert"; +import { z } from "zod"; +import type { Context as CoreContext, Core } from "../core"; +import { ExternalDataOrigin, Language, languages, type LocalizedString } from "../core/ports/GetSoftwareExternalData"; import type { - SoftwareType, + DeclarationFormData, + InstanceFormData, Os, SoftwareFormData, - DeclarationFormData, - InstanceFormData + SoftwareType } from "../core/usecases/readWriteSillData"; -import type { Equals } from "tsafe"; +import type { KeycloakParams } from "../tools/createValidateKeycloakSignature"; +import { getMonorepoRootPackageJson } from "../tools/getMonorepoRootPackageJson"; import type { OptionalIfCanBeUndefined } from "../tools/OptionalIfCanBeUndefined"; -import { initTRPC } from "@trpc/server"; -import superjson from "superjson"; -import { type LocalizedString, Language, languages, ExternalDataOrigin } from "../core/ports/GetSoftwareExternalData"; -import { createResolveLocalizedString } from "i18nifty/LocalizedString/reactless"; +import type { Context } from "./context"; +import type { User } from "./user"; export function createRouter(params: { core: Core; @@ -75,7 +73,7 @@ export function createRouter(params: { "getApiVersion": loggedProcedure.query( (() => { const out: string = JSON.parse( - fs.readFileSync(pathJoin(getProjectRoot(), "package.json")).toString("utf8") + fs.readFileSync(pathJoin(getMonorepoRootPackageJson(), "package.json")).toString("utf8") )["version"]; return () => out; diff --git a/api/src/tools/getProjectRoot.ts b/api/src/tools/getMonorepoRootPackageJson.ts similarity index 50% rename from api/src/tools/getProjectRoot.ts rename to api/src/tools/getMonorepoRootPackageJson.ts index 4d4ea107..4cd4a8ee 100644 --- a/api/src/tools/getProjectRoot.ts +++ b/api/src/tools/getMonorepoRootPackageJson.ts @@ -8,12 +8,11 @@ function getProjectRootRec(dirPath: string): string { return getProjectRootRec(path.join(dirPath, "..")); } -let result: string | undefined = undefined; - -export function getProjectRoot(): string { - if (result !== undefined) { - return result; +let monorepoRoot: string | undefined = undefined; +export function getMonorepoRootPackageJson(): string { + if (monorepoRoot !== undefined) { + return monorepoRoot; } - - return (result = getProjectRootRec(__dirname)); + monorepoRoot = getProjectRootRec(path.join(__dirname, "../../..")); + return monorepoRoot; }