33 * Licensed under the MIT License. See LICENSE file in the project root for license information.
44 *-----------------------------------------------------------------------------------------------*/
55
6- import { env , ExtensionContext } from 'vscode' ;
6+ /* eslint-disable import/no-dynamic-require */
7+ /* eslint-disable global-require */
8+
9+ import { env , ExtensionContext } from 'vscode' ;
10+
11+ export function getVscodeModule < T > ( moduleName : string ) : T | undefined {
12+ try {
13+ return require ( `${ env . appRoot } /node_modules.asar/${ moduleName } ` ) ;
14+ } catch ( err ) {
15+ // Not in ASAR.
16+ }
17+ try {
18+ return require ( `${ env . appRoot } /node_modules/${ moduleName } ` ) ;
19+ } catch ( err ) {
20+ // Not available.
21+ }
22+ return undefined ;
23+ }
724
825const keytar : any = getVscodeModule ( 'keytar' ) ;
926
1027export class TokenStore {
1128 public static extensionContext : ExtensionContext ;
1229
13- static async setItem ( key : string , login : string , value : string ) : Promise < void > {
14- return keytar ? keytar . setPassword ( key , login , value ) : undefined ;
30+ static setItem ( key : string , login : string , value : string ) : Promise < void > {
31+ return keytar ? keytar . setPassword ( key , login , value ) : Promise . resolve ( ) ;
1532 }
1633
17- static async getItem ( key : string , login : string ) : Promise < string > {
34+ static getItem ( key : string , login : string ) : Promise < string > {
1835 return keytar ? keytar . getPassword ( key , login ) : '' ;
1936 }
2037
@@ -26,17 +43,3 @@ export class TokenStore {
2643 return TokenStore . extensionContext . globalState . get ( 'username' ) ;
2744 }
2845}
29-
30- export function getVscodeModule < T > ( moduleName : string ) : T | undefined {
31- try {
32- return require ( `${ env . appRoot } /node_modules.asar/${ moduleName } ` ) ;
33- } catch ( err ) {
34- // Not in ASAR.
35- }
36- try {
37- return require ( `${ env . appRoot } /node_modules/${ moduleName } ` ) ;
38- } catch ( err ) {
39- // Not available.
40- }
41- return undefined ;
42- }
0 commit comments