From 6ec57372dce14114d394b2fd13b676235e4b4602 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 23 Feb 2018 12:31:10 +0100 Subject: [PATCH] Fixes #364: Adopt the usage of ASAR in VSCode --- src/tree/AttachedAccountsTreeItem.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/tree/AttachedAccountsTreeItem.ts b/src/tree/AttachedAccountsTreeItem.ts index 0b4574d97..4a3daee16 100644 --- a/src/tree/AttachedAccountsTreeItem.ts +++ b/src/tree/AttachedAccountsTreeItem.ts @@ -35,11 +35,7 @@ export class AttachedAccountsTreeItem implements IAzureParentTreeItem { private _keytar: typeof keytarType; constructor(private readonly _globalState: vscode.Memento) { - try { - this._keytar = require(`${vscode.env.appRoot}/node_modules/keytar`); - } catch (e) { - // unable to find keytar - } + this._keytar = getCoreNodeModule(`keytar`); this.loadPersistedServers(); } @@ -299,3 +295,18 @@ export class AttachedAccountsTreeItem implements IAzureParentTreeItem { return [endpoint, masterKey, id]; } } + +/** + * Returns a node module installed with VSCode, or null if it fails. + */ +function getCoreNodeModule(moduleName: string) { + try { + return require(`${vscode.env.appRoot}/node_modules.asar/${moduleName}`); + } catch (err) { } + + try { + return require(`${vscode.env.appRoot}/node_modules/${moduleName}`); + } catch (err) { } + + return null; +}