mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce abstraction for joining paths
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
4 files changed
+32
No files matched your search
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
export type JoinPaths = (...args: string[]) => string;
|
||||||
|
|
||||||
|
const joinPathsInjectable = getInjectable({
|
||||||
|
id: "join-paths",
|
||||||
|
instantiate: (): JoinPaths => path.join,
|
||||||
|
|
||||||
|
// This causes side effect e.g. Windows uses different separator than e.g. linux
|
||||||
|
causesSideEffects: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default joinPathsInjectable;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { join } from "lodash/fp";
|
||||||
|
import type { JoinPaths } from "../path/join-paths.injectable";
|
||||||
|
|
||||||
|
export const joinPathsFake: JoinPaths = join("/");
|
||||||
@@ -32,6 +32,8 @@ import isWindowsInjectable from "../common/vars/is-windows.injectable";
|
|||||||
import isLinuxInjectable from "../common/vars/is-linux.injectable";
|
import isLinuxInjectable from "../common/vars/is-linux.injectable";
|
||||||
import getAbsolutePathInjectable from "../common/path/get-absolute-path.injectable";
|
import getAbsolutePathInjectable from "../common/path/get-absolute-path.injectable";
|
||||||
import { getAbsolutePathFake } from "../common/test-utils/get-absolute-path-fake";
|
import { getAbsolutePathFake } from "../common/test-utils/get-absolute-path-fake";
|
||||||
|
import joinPathsInjectable from "../common/path/join-paths.injectable";
|
||||||
|
import { joinPathsFake } from "../common/test-utils/join-paths-fake";
|
||||||
|
|
||||||
export const getDiForUnitTesting = (
|
export const getDiForUnitTesting = (
|
||||||
{ doGeneralOverrides } = { doGeneralOverrides: false },
|
{ doGeneralOverrides } = { doGeneralOverrides: false },
|
||||||
@@ -58,6 +60,7 @@ export const getDiForUnitTesting = (
|
|||||||
di.override(isLinuxInjectable, () => false);
|
di.override(isLinuxInjectable, () => false);
|
||||||
|
|
||||||
di.override(getAbsolutePathInjectable, () => getAbsolutePathFake);
|
di.override(getAbsolutePathInjectable, () => getAbsolutePathFake);
|
||||||
|
di.override(joinPathsInjectable, () => joinPathsFake);
|
||||||
|
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||||
di.override(extensionsStoreInjectable, () => ({ isEnabled: ({ id, isBundled }) => false }) as ExtensionsStore);
|
di.override(extensionsStoreInjectable, () => ({ isEnabled: ({ id, isBundled }) => false }) as ExtensionsStore);
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import isWindowsInjectable from "../common/vars/is-windows.injectable";
|
|||||||
import isLinuxInjectable from "../common/vars/is-linux.injectable";
|
import isLinuxInjectable from "../common/vars/is-linux.injectable";
|
||||||
import getAbsolutePathInjectable from "../common/path/get-absolute-path.injectable";
|
import getAbsolutePathInjectable from "../common/path/get-absolute-path.injectable";
|
||||||
import { getAbsolutePathFake } from "../common/test-utils/get-absolute-path-fake";
|
import { getAbsolutePathFake } from "../common/test-utils/get-absolute-path-fake";
|
||||||
|
import joinPathsInjectable from "../common/path/join-paths.injectable";
|
||||||
|
import { joinPathsFake } from "../common/test-utils/join-paths-fake";
|
||||||
|
|
||||||
export const getDiForUnitTesting = (
|
export const getDiForUnitTesting = (
|
||||||
{ doGeneralOverrides } = { doGeneralOverrides: false },
|
{ doGeneralOverrides } = { doGeneralOverrides: false },
|
||||||
@@ -55,6 +57,7 @@ export const getDiForUnitTesting = (
|
|||||||
di.override(isLinuxInjectable, () => false);
|
di.override(isLinuxInjectable, () => false);
|
||||||
|
|
||||||
di.override(getAbsolutePathInjectable, () => getAbsolutePathFake);
|
di.override(getAbsolutePathInjectable, () => getAbsolutePathFake);
|
||||||
|
di.override(joinPathsInjectable, () => joinPathsFake);
|
||||||
|
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||||
di.override(extensionsStoreInjectable, () => ({ isEnabled: ({ id, isBundled }) => false }) as ExtensionsStore);
|
di.override(extensionsStoreInjectable, () => ({ isEnabled: ({ id, isBundled }) => false }) as ExtensionsStore);
|
||||||
|
|||||||
Reference in new issue
Block a user