Skip to content

Commit

Permalink
get root package.json api version (instead of the one from api/packag…
Browse files Browse the repository at this point in the history
…e.json)
  • Loading branch information
JeromeBu committed Mar 27, 2024
1 parent 1e98ee7 commit d8a80fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
38 changes: 18 additions & 20 deletions api/src/rpc/router.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d8a80fd

Please sign in to comment.