mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce injectable for __static directory to eliminate side effect on import
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
cf052b9070
commit
5faaa7fa30
24
src/common/vars/lens-resources-dir.injectable.ts
Normal file
24
src/common/vars/lens-resources-dir.injectable.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* 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 contextDirInjectable from "./context-dir.injectable";
|
||||||
|
import isDevelopmentInjectable from "./is-development.injectable";
|
||||||
|
|
||||||
|
const lensResourcesDirInjectable = getInjectable({
|
||||||
|
id: "lens-resources-dir",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||||
|
const contextDir = di.inject(contextDirInjectable);
|
||||||
|
|
||||||
|
return isDevelopment
|
||||||
|
? contextDir
|
||||||
|
: (process.resourcesPath ?? contextDir);
|
||||||
|
},
|
||||||
|
|
||||||
|
causesSideEffects: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default lensResourcesDirInjectable;
|
||||||
20
src/common/vars/static-dir.injectable.ts
Normal file
20
src/common/vars/static-dir.injectable.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* 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 getAbsolutePathInjectable from "../path/get-absolute-path.injectable";
|
||||||
|
import lensResourcesDirInjectable from "./lens-resources-dir.injectable";
|
||||||
|
|
||||||
|
const staticDirInjectable = getInjectable({
|
||||||
|
id: "static-dir",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const getAbsolutePath = di.inject(getAbsolutePathInjectable);
|
||||||
|
const lensResourcesDir = di.inject(lensResourcesDirInjectable);
|
||||||
|
|
||||||
|
return getAbsolutePath(lensResourcesDir, "static");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default staticDirInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user