From fbbd18b316d7c4152f77c6f06de544c272cfbb79 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Wed, 28 Oct 2020 09:01:58 +0200 Subject: [PATCH] fix in-tree npm install if app is sandboxed Signed-off-by: Jari Kolehmainen --- src/extensions/extension-manager.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/extensions/extension-manager.ts b/src/extensions/extension-manager.ts index 1e0ebf9387..0f96ab339a 100644 --- a/src/extensions/extension-manager.ts +++ b/src/extensions/extension-manager.ts @@ -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) {