1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix in-tree npm install if app is sandboxed

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-10-28 09:01:58 +02:00
parent 1f41cc800b
commit fbbd18b316

View File

@ -25,10 +25,18 @@ export class ExtensionManager {
return extensionPackagesRoot()
}
get inTreeTargetPath() {
return path.join(this.extensionPackagesRoot, "extensions")
}
get inTreeFolderPath(): string {
return path.resolve(__static, "../extensions");
}
get nodeModulesPath(): string {
return path.join(this.extensionPackagesRoot, "node_modules")
}
get localFolderPath(): string {
return path.join(os.homedir(), ".k8slens", "extensions");
}
@ -39,7 +47,12 @@ export class ExtensionManager {
async load() {
logger.info("[EXTENSION-MANAGER] loading extensions from " + this.extensionPackagesRoot)
await fs.ensureDir(path.join(this.extensionPackagesRoot, "node_modules"))
if (this.inTreeFolderPath !== this.inTreeTargetPath) {
await fs.remove(this.inTreeTargetPath)
await fs.ensureDir(this.inTreeTargetPath)
await fs.copy(this.inTreeFolderPath, this.inTreeTargetPath)
}
await fs.ensureDir(this.nodeModulesPath)
await fs.ensureDir(this.localFolderPath)
return await this.loadExtensions();
}
@ -55,7 +68,7 @@ export class ExtensionManager {
id: manifestJson.name,
version: manifestJson.version,
name: manifestJson.name,
manifestPath: path.join(this.extensionPackagesRoot, "node_modules", manifestJson.name, "package.json"),
manifestPath: path.join(this.nodeModulesPath, manifestJson.name, "package.json"),
manifest: manifestJson
}
} catch (err) {
@ -87,7 +100,7 @@ export class ExtensionManager {
async loadBundledExtensions() {
const extensions: InstalledExtension[] = []
const folderPath = this.inTreeFolderPath
const folderPath = this.inTreeTargetPath
const bundledExtensions = getBundledExtensions()
const paths = await fs.readdir(folderPath);
for (const fileName of paths) {