Handle no azdata API in sql db proj extension gracefully (#15873)

* Update db proj ext to handle not having azdata API available

* Fixes

* Fix compile
This commit is contained in:
Charles Gagnon
2021-06-22 23:34:01 -07:00
committed by GitHub
parent c636e24d03
commit 4707c1601c
12 changed files with 192 additions and 175 deletions

View File

@@ -3,6 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type * as azdataType from 'azdata';
import * as vscode from 'vscode';
import * as os from 'os';
import * as constants from './constants';
@@ -324,3 +325,20 @@ export function timeConversion(duration: number): string {
return portions.join(', ');
}
// Try to load the azdata API - but gracefully handle the failure in case we're running
// in a context where the API doesn't exist (such as VS Code)
let azdataApi: typeof azdataType | undefined = undefined;
try {
azdataApi = require('azdata');
} catch {
// no-op
}
/**
* Gets the azdata API if it's available in the context this extension is running in.
* @returns The azdata API if it's available
*/
export function getAzdataApi(): typeof azdataType | undefined {
return azdataApi;
}