From 75eed35f3abbcad3106b7c9a58bc973536e10225 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 24 Aug 2022 15:39:48 -0400 Subject: [PATCH] Replace all uses of getAbsolutePath with joinPaths as it is more correct and less confusing Signed-off-by: Sebastian Malton --- .../directory-for-binaries.injectable.ts | 6 +-- .../directory-for-kube-configs.injectable.ts | 9 ++-- ...rectory-for-kubectl-binaries.injectable.ts | 7 ++- ...custom-kube-config-directory.injectable.ts | 7 ++- ...ctory-for-lens-local-storage.injectable.ts | 6 +-- .../base-bundled-binaries-dir.injectable.ts | 6 +-- .../vars/bundled-resources-dir.injectable.ts | 6 +-- .../vars/static-files-directory.injectable.ts | 6 +-- ...directory-for-extension-data.injectable.ts | 6 +-- src/main/helm/helm-binary-path.injectable.ts | 6 +-- .../routes/static-file-route.injectable.ts | 10 ++-- .../splash-window/splash-window.injectable.ts | 6 +-- .../get-tray-icon-path.injectable.ts | 15 +++--- .../lens-templates.injectable.ts | 49 +++++++------------ .../create-storage.injectable.ts | 4 +- .../utils/create-storage/create-storage.ts | 14 ++---- 16 files changed, 69 insertions(+), 94 deletions(-) diff --git a/src/common/app-paths/directory-for-binaries/directory-for-binaries.injectable.ts b/src/common/app-paths/directory-for-binaries/directory-for-binaries.injectable.ts index 5f6b14f5ba..f8a55b041c 100644 --- a/src/common/app-paths/directory-for-binaries/directory-for-binaries.injectable.ts +++ b/src/common/app-paths/directory-for-binaries/directory-for-binaries.injectable.ts @@ -4,16 +4,16 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import directoryForUserDataInjectable from "../directory-for-user-data/directory-for-user-data.injectable"; -import getAbsolutePathInjectable from "../../path/get-absolute-path.injectable"; +import joinPathsInjectable from "../../path/join-paths.injectable"; const directoryForBinariesInjectable = getInjectable({ id: "directory-for-binaries", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const directoryForUserData = di.inject(directoryForUserDataInjectable); - return getAbsolutePath(directoryForUserData, "binaries"); + return joinPaths(directoryForUserData, "binaries"); }, }); diff --git a/src/common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable.ts b/src/common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable.ts index f371860f18..d49029572e 100644 --- a/src/common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable.ts +++ b/src/common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable.ts @@ -4,19 +4,16 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import directoryForUserDataInjectable from "../directory-for-user-data/directory-for-user-data.injectable"; -import getAbsolutePathInjectable from "../../path/get-absolute-path.injectable"; +import joinPathsInjectable from "../../path/join-paths.injectable"; const directoryForKubeConfigsInjectable = getInjectable({ id: "directory-for-kube-configs", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const directoryForUserData = di.inject(directoryForUserDataInjectable); - return getAbsolutePath( - directoryForUserData, - "kubeconfigs", - ); + return joinPaths(directoryForUserData, "kubeconfigs"); }, }); diff --git a/src/common/app-paths/directory-for-kubectl-binaries/directory-for-kubectl-binaries.injectable.ts b/src/common/app-paths/directory-for-kubectl-binaries/directory-for-kubectl-binaries.injectable.ts index 4b6ce56601..c1ef1b23f5 100644 --- a/src/common/app-paths/directory-for-kubectl-binaries/directory-for-kubectl-binaries.injectable.ts +++ b/src/common/app-paths/directory-for-kubectl-binaries/directory-for-kubectl-binaries.injectable.ts @@ -4,17 +4,16 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import directoryForBinariesInjectable from "../directory-for-binaries/directory-for-binaries.injectable"; -import getAbsolutePathInjectable from "../../path/get-absolute-path.injectable"; +import joinPathsInjectable from "../../path/join-paths.injectable"; const directoryForKubectlBinariesInjectable = getInjectable({ id: "directory-for-kubectl-binaries", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const directoryForBinaries = di.inject(directoryForBinariesInjectable); - - return getAbsolutePath(directoryForBinaries, "kubectl"); + return joinPaths(directoryForBinaries, "kubectl"); }, }); diff --git a/src/common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable.ts b/src/common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable.ts index 6f22aa32f2..5d53e506bd 100644 --- a/src/common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable.ts +++ b/src/common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable.ts @@ -4,17 +4,16 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import directoryForKubeConfigsInjectable from "../directory-for-kube-configs/directory-for-kube-configs.injectable"; -import getAbsolutePathInjectable from "../../path/get-absolute-path.injectable"; +import joinPathsInjectable from "../../path/join-paths.injectable"; const getCustomKubeConfigDirectoryInjectable = getInjectable({ id: "get-custom-kube-config-directory", instantiate: (di) => { const directoryForKubeConfigs = di.inject(directoryForKubeConfigsInjectable); - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); - return (directoryName: string) => - getAbsolutePath(directoryForKubeConfigs, directoryName); + return (directoryName: string) => joinPaths(directoryForKubeConfigs, directoryName); }, }); diff --git a/src/common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable.ts b/src/common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable.ts index 4bb5cb2495..11a8f3f7de 100644 --- a/src/common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable.ts +++ b/src/common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable.ts @@ -4,16 +4,16 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import getAbsolutePathInjectable from "../path/get-absolute-path.injectable"; +import joinPathsInjectable from "../path/join-paths.injectable"; const directoryForLensLocalStorageInjectable = getInjectable({ id: "directory-for-lens-local-storage", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const directoryForUserData = di.inject(directoryForUserDataInjectable); - return getAbsolutePath( + return joinPaths( directoryForUserData, "lens-local-storage", ); diff --git a/src/common/vars/base-bundled-binaries-dir.injectable.ts b/src/common/vars/base-bundled-binaries-dir.injectable.ts index f0d78482c8..968ccc5c5b 100644 --- a/src/common/vars/base-bundled-binaries-dir.injectable.ts +++ b/src/common/vars/base-bundled-binaries-dir.injectable.ts @@ -4,17 +4,17 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import bundledResourcesDirectoryInjectable from "./bundled-resources-dir.injectable"; -import getAbsolutePathInjectable from "../path/get-absolute-path.injectable"; import normalizedPlatformArchitectureInjectable from "./normalized-platform-architecture.injectable"; +import joinPathsInjectable from "../path/join-paths.injectable"; const baseBundledBinariesDirectoryInjectable = getInjectable({ id: "base-bundled-binaries-directory", instantiate: (di) => { const bundledResourcesDirectory = di.inject(bundledResourcesDirectoryInjectable); const normalizedPlatformArchitecture = di.inject(normalizedPlatformArchitectureInjectable); - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); - return getAbsolutePath( + return joinPaths( bundledResourcesDirectory, normalizedPlatformArchitecture, ); diff --git a/src/common/vars/bundled-resources-dir.injectable.ts b/src/common/vars/bundled-resources-dir.injectable.ts index e20a638384..2058b1d5d3 100644 --- a/src/common/vars/bundled-resources-dir.injectable.ts +++ b/src/common/vars/bundled-resources-dir.injectable.ts @@ -5,20 +5,20 @@ import { getInjectable } from "@ogre-tools/injectable"; import isProductionInjectable from "./is-production.injectable"; import normalizedPlatformInjectable from "./normalized-platform.injectable"; -import getAbsolutePathInjectable from "../path/get-absolute-path.injectable"; import lensResourcesDirInjectable from "./lens-resources-dir.injectable"; +import joinPathsInjectable from "../path/join-paths.injectable"; const bundledResourcesDirectoryInjectable = getInjectable({ id: "bundled-resources-directory", instantiate: (di) => { const isProduction = di.inject(isProductionInjectable); const normalizedPlatform = di.inject(normalizedPlatformInjectable); - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const lensResourcesDir = di.inject(lensResourcesDirInjectable); return isProduction ? lensResourcesDir - : getAbsolutePath(lensResourcesDir, "binaries", "client", normalizedPlatform); + : joinPaths(lensResourcesDir, "binaries", "client", normalizedPlatform); }, }); diff --git a/src/common/vars/static-files-directory.injectable.ts b/src/common/vars/static-files-directory.injectable.ts index c881f12b97..e65e854e9c 100644 --- a/src/common/vars/static-files-directory.injectable.ts +++ b/src/common/vars/static-files-directory.injectable.ts @@ -3,17 +3,17 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import getAbsolutePathInjectable from "../path/get-absolute-path.injectable"; +import joinPathsInjectable from "../path/join-paths.injectable"; import lensResourcesDirInjectable from "./lens-resources-dir.injectable"; const staticFilesDirectoryInjectable = getInjectable({ id: "static-files-directory", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const lensResourcesDir = di.inject(lensResourcesDirInjectable); - return getAbsolutePath(lensResourcesDir, "static"); + return joinPaths(lensResourcesDir, "static"); }, }); diff --git a/src/extensions/extension-loader/file-system-provisioner-store/directory-for-extension-data.injectable.ts b/src/extensions/extension-loader/file-system-provisioner-store/directory-for-extension-data.injectable.ts index 896c74da6d..469ed85949 100644 --- a/src/extensions/extension-loader/file-system-provisioner-store/directory-for-extension-data.injectable.ts +++ b/src/extensions/extension-loader/file-system-provisioner-store/directory-for-extension-data.injectable.ts @@ -4,16 +4,16 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import getAbsolutePathInjectable from "../../../common/path/get-absolute-path.injectable"; +import joinPathsInjectable from "../../../common/path/join-paths.injectable"; const directoryForExtensionDataInjectable = getInjectable({ id: "directory-for-extension-data", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const directoryForUserData = di.inject(directoryForUserDataInjectable); - return getAbsolutePath(directoryForUserData, "extension_data"); + return joinPaths(directoryForUserData, "extension_data"); }, }); diff --git a/src/main/helm/helm-binary-path.injectable.ts b/src/main/helm/helm-binary-path.injectable.ts index d5983572c7..6d8c661547 100644 --- a/src/main/helm/helm-binary-path.injectable.ts +++ b/src/main/helm/helm-binary-path.injectable.ts @@ -4,21 +4,21 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { getBinaryName } from "../../common/vars"; -import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable"; import normalizedPlatformInjectable from "../../common/vars/normalized-platform.injectable"; import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable"; +import joinPathsInjectable from "../../common/path/join-paths.injectable"; const helmBinaryPathInjectable = getInjectable({ id: "helm-binary-path", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const normalizedPlatform = di.inject(normalizedPlatformInjectable); const baseBundledBinariesDirectory = di.inject(baseBundledBinariesDirectoryInjectable); const helmBinaryName = getBinaryName("helm", { forPlatform: normalizedPlatform }); - return getAbsolutePath(baseBundledBinariesDirectory, helmBinaryName); + return joinPaths(baseBundledBinariesDirectory, helmBinaryName); }, }); diff --git a/src/main/routes/static-file-route.injectable.ts b/src/main/routes/static-file-route.injectable.ts index 2650410d0b..90c3d02442 100644 --- a/src/main/routes/static-file-route.injectable.ts +++ b/src/main/routes/static-file-route.injectable.ts @@ -11,8 +11,6 @@ import path from "path"; import isDevelopmentInjectable from "../../common/vars/is-development.injectable"; import httpProxy from "http-proxy"; import readFileBufferInjectable from "../../common/fs/read-file-buffer.injectable"; -import type { GetAbsolutePath } from "../../common/path/get-absolute-path.injectable"; -import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable"; import type { JoinPaths } from "../../common/path/join-paths.injectable"; import joinPathsInjectable from "../../common/path/join-paths.injectable"; import { webpackDevServerPort } from "../../../webpack/vars"; @@ -20,11 +18,13 @@ import type { LensApiRequest, RouteResponse } from "../router/route"; import { route } from "../router/route"; import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable"; import appNameInjectable from "../../common/vars/app-name.injectable"; +import type { GetAbsolutePath } from "../../common/path/get-absolute-path.injectable"; +import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable"; interface ProductionDependencies { readFileBuffer: (path: string) => Promise; - getAbsolutePath: GetAbsolutePath; joinPaths: JoinPaths; + getAbsolutePath: GetAbsolutePath; staticFilesDirectory: string; appName: string; } @@ -98,8 +98,8 @@ const staticFileRouteInjectable = getRouteInjectable({ instantiate: (di) => { const isDevelopment = di.inject(isDevelopmentInjectable); const readFileBuffer = di.inject(readFileBufferInjectable); - const getAbsolutePath = di.inject(getAbsolutePathInjectable); const joinPaths = di.inject(joinPathsInjectable); + const getAbsolutePath = di.inject(getAbsolutePathInjectable); const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable); const appName = di.inject(appNameInjectable); @@ -114,10 +114,10 @@ const staticFileRouteInjectable = getRouteInjectable({ }) : handleStaticFileInProduction({ readFileBuffer, - getAbsolutePath, joinPaths, staticFilesDirectory, appName, + getAbsolutePath, }), ); }, diff --git a/src/main/start-main-application/lens-window/splash-window/splash-window.injectable.ts b/src/main/start-main-application/lens-window/splash-window/splash-window.injectable.ts index 72c65d6c8d..978309c4d0 100644 --- a/src/main/start-main-application/lens-window/splash-window/splash-window.injectable.ts +++ b/src/main/start-main-application/lens-window/splash-window/splash-window.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import createLensWindowInjectable from "../application-window/create-lens-window.injectable"; import staticFilesDirectoryInjectable from "../../../../common/vars/static-files-directory.injectable"; -import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable"; +import joinPathsInjectable from "../../../../common/path/join-paths.injectable"; const splashWindowInjectable = getInjectable({ id: "splash-window", @@ -13,8 +13,8 @@ const splashWindowInjectable = getInjectable({ instantiate: (di) => { const createLensWindow = di.inject(createLensWindowInjectable); const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable); - const getAbsolutePath = di.inject(getAbsolutePathInjectable); - const splashWindowFile = getAbsolutePath(staticFilesDirectory, "splash.html"); + const joinPaths = di.inject(joinPathsInjectable); + const splashWindowFile = joinPaths(staticFilesDirectory, "splash.html"); return createLensWindow({ id: "splash", diff --git a/src/main/tray/menu-icon/get-tray-icon-path.injectable.ts b/src/main/tray/menu-icon/get-tray-icon-path.injectable.ts index fe2746a2ab..30d2e58858 100644 --- a/src/main/tray/menu-icon/get-tray-icon-path.injectable.ts +++ b/src/main/tray/menu-icon/get-tray-icon-path.injectable.ts @@ -3,34 +3,33 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import getAbsolutePathInjectable from "../../../common/path/get-absolute-path.injectable"; import staticFilesDirectoryInjectable from "../../../common/vars/static-files-directory.injectable"; import isDevelopmentInjectable from "../../../common/vars/is-development.injectable"; import isMacInjectable from "../../../common/vars/is-mac.injectable"; import { camelCase, flow, upperFirst } from "lodash/fp"; +import joinPathsInjectable from "../../../common/path/join-paths.injectable"; const upperCamelCase = flow(camelCase, upperFirst); const getTrayIconPathInjectable = getInjectable({ id: "get-tray-icon-path", instantiate: (di) => { - const getAbsolutePath = di.inject(getAbsolutePathInjectable); + const joinPaths = di.inject(joinPathsInjectable); const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable); const isDevelopment = di.inject(isDevelopmentInjectable); const isMac = di.inject(isMacInjectable); - const baseIconDirectory = getAbsolutePath( + const baseIconDirectory = joinPaths( staticFilesDirectory, isDevelopment ? "../build/tray" : "icons", // copied within electron-builder extras ); const fileSuffix = isMac ? "Template.png" : ".png"; - return (name: string) => - getAbsolutePath( - baseIconDirectory, - `trayIcon${upperCamelCase(name)}${fileSuffix}`, - ); + return (name: string) => joinPaths( + baseIconDirectory, + `trayIcon${upperCamelCase(name)}${fileSuffix}`, + ); }, }); diff --git a/src/renderer/components/dock/create-resource/lens-templates.injectable.ts b/src/renderer/components/dock/create-resource/lens-templates.injectable.ts index ce78c2286e..e5d88d9256 100644 --- a/src/renderer/components/dock/create-resource/lens-templates.injectable.ts +++ b/src/renderer/components/dock/create-resource/lens-templates.injectable.ts @@ -8,44 +8,29 @@ import { hasCorrectExtension } from "./has-correct-extension"; import readFileInjectable from "../../../../common/fs/read-file.injectable"; import readDirInjectable from "../../../../common/fs/read-dir.injectable"; import type { RawTemplates } from "./create-resource-templates.injectable"; -import type { GetAbsolutePath } from "../../../../common/path/get-absolute-path.injectable"; -import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable"; import staticFilesDirectoryInjectable from "../../../../common/vars/static-files-directory.injectable"; - -interface Dependencies { - readDir: (dirPath: string) => Promise; - readFile: (filePath: string) => Promise; - getAbsolutePath: GetAbsolutePath; - staticFilesDirectory: string; -} - -async function getTemplates({ readDir, readFile, getAbsolutePath, staticFilesDirectory }: Dependencies) { - const templatesFolder = getAbsolutePath(staticFilesDirectory, "../templates/create-resource"); - - /** - * Mapping between file names and their contents - */ - const templates: [file: string, contents: string][] = []; - - for (const dirEntry of await readDir(templatesFolder)) { - if (hasCorrectExtension(dirEntry)) { - templates.push([path.parse(dirEntry).name, await readFile(path.join(templatesFolder, dirEntry))]); - } - } - - return templates; -} +import joinPathsInjectable from "../../../../common/path/join-paths.injectable"; const lensCreateResourceTemplatesInjectable = getInjectable({ id: "lens-create-resource-templates", instantiate: async (di): Promise => { - const templates = await getTemplates({ - readFile: di.inject(readFileInjectable), - readDir: di.inject(readDirInjectable), - getAbsolutePath: di.inject(getAbsolutePathInjectable), - staticFilesDirectory: di.inject(staticFilesDirectoryInjectable), - }); + const readFile = di.inject(readFileInjectable); + const readDir = di.inject(readDirInjectable); + const joinPaths = di.inject(joinPathsInjectable); + const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable); + + /** + * Mapping between file names and their contents + */ + const templates: [file: string, contents: string][] = []; + const templatesFolder = joinPaths(staticFilesDirectory, "../templates/create-resource"); + + for (const dirEntry of await readDir(templatesFolder)) { + if (hasCorrectExtension(dirEntry)) { + templates.push([path.parse(dirEntry).name, await readFile(path.join(templatesFolder, dirEntry))]); + } + } return ["lens", templates]; }, diff --git a/src/renderer/utils/create-storage/create-storage.injectable.ts b/src/renderer/utils/create-storage/create-storage.injectable.ts index b40eef738c..2d295b802b 100644 --- a/src/renderer/utils/create-storage/create-storage.injectable.ts +++ b/src/renderer/utils/create-storage/create-storage.injectable.ts @@ -9,9 +9,9 @@ import readJsonFileInjectable from "../../../common/fs/read-json-file.injectable import writeJsonFileInjectable from "../../../common/fs/write-json-file.injectable"; import { observable } from "mobx"; import loggerInjectable from "../../../common/logger.injectable"; -import getAbsolutePathInjectable from "../../../common/path/get-absolute-path.injectable"; import hostedClusterIdInjectable from "../../cluster-frame-context/hosted-cluster-id.injectable"; import storageSaveDelayInjectable from "./storage-save-delay.injectable"; +import joinPathsInjectable from "../../../common/path/join-paths.injectable"; const createStorageInjectable = getInjectable({ id: "create-storage", @@ -26,7 +26,7 @@ const createStorageInjectable = getInjectable({ writeJsonFile: di.inject(writeJsonFileInjectable), logger: di.inject(loggerInjectable), directoryForLensLocalStorage: di.inject(directoryForLensLocalStorageInjectable), - getAbsolutePath: di.inject(getAbsolutePathInjectable), + joinPaths: di.inject(joinPathsInjectable), hostedClusterId: di.inject(hostedClusterIdInjectable), saveDelay: di.inject(storageSaveDelayInjectable), }), diff --git a/src/renderer/utils/create-storage/create-storage.ts b/src/renderer/utils/create-storage/create-storage.ts index 501e425161..1149d479cc 100755 --- a/src/renderer/utils/create-storage/create-storage.ts +++ b/src/renderer/utils/create-storage/create-storage.ts @@ -8,10 +8,9 @@ import { comparer, reaction, toJS, when } from "mobx"; import type { StorageLayer } from "../storageHelper"; import { StorageHelper } from "../storageHelper"; -import { isTestEnv } from "../../../common/vars"; import type { JsonObject, JsonValue } from "type-fest"; import type { Logger } from "../../../common/logger"; -import type { GetAbsolutePath } from "../../../common/path/get-absolute-path.injectable"; +import type { JoinPaths } from "../../../common/path/join-paths.injectable"; interface Dependencies { storage: { initialized: boolean; loaded: boolean; data: Record }; @@ -19,7 +18,7 @@ interface Dependencies { directoryForLensLocalStorage: string; readJsonFile: (filePath: string) => Promise; writeJsonFile: (filePath: string, contentObject: JsonObject) => Promise; - getAbsolutePath: GetAbsolutePath; + joinPaths: JoinPaths; hostedClusterId: string | undefined; saveDelay: number; } @@ -31,7 +30,7 @@ export type CreateStorage = (key: string, defaultValue: T) => StorageLayer */ export const createStorage = ({ storage, - getAbsolutePath, + joinPaths, logger, directoryForLensLocalStorage, readJsonFile, @@ -45,17 +44,14 @@ export const createStorage = ({ storage.initialized = true; (async () => { - const filePath = getAbsolutePath(directoryForLensLocalStorage, `${hostedClusterId || "app"}.json`); + const filePath = joinPaths(directoryForLensLocalStorage, `${hostedClusterId || "app"}.json`); try { storage.data = (await readJsonFile(filePath)) as JsonObject; } catch { // do nothing } finally { - if (!isTestEnv) { - logger.info(`${logPrefix} loading finished for ${filePath}`); - } - + logger.info(`${logPrefix} loading finished for ${filePath}`); storage.loaded = true; }