mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
setup nodejs module paths so that extensions can import things from others
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
4771c7755c
commit
2f2ec7f28c
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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 * as path from "path";
|
||||
import { beforeApplicationIsLoadingInjectionToken } from "../../start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
const setupModulePathsInjectable = getInjectable({
|
||||
id: "setup-module-paths",
|
||||
|
||||
instantiate: (di) => {
|
||||
const userDataDir = di.inject(directoryForUserDataInjectable);
|
||||
|
||||
return {
|
||||
run: () => {
|
||||
const module = __non_webpack_require__("module");
|
||||
|
||||
if (module?._nodeModulePaths) {
|
||||
const nodeModulePaths = module._nodeModulePaths;
|
||||
|
||||
module._nodeModulePaths = (from: string[]) => {
|
||||
return nodeModulePaths(from).concat([path.join(userDataDir, "node_modules")]);
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
||||
});
|
||||
|
||||
export default setupModulePathsInjectable;
|
||||
Loading…
Reference in New Issue
Block a user