Remove sql project build dependency on STS (#20447)

* download Microsoft.Build.Sql sdk and extract

* cleanup extracted folder and nuget

* add constants

* cleanup

* remove package-lock.json

* making outputChannel required and some cleanup

* only download if the files aren't already there

* Add todo

* add try catches

* addressing comments
This commit is contained in:
Kim Santiago
2022-08-31 14:04:06 -07:00
committed by GitHub
parent eedf6e01c3
commit 8926c4f605
7 changed files with 793 additions and 309 deletions

View File

@@ -615,3 +615,14 @@ export enum PublishTargetType {
}
export const CollapseProjectNodesKey = 'collapseProjectNodes';
// httpClient
export const downloadError = localize('downloadError', "Download error");
export const downloadProgress = localize('downloadProgress', "Download progress");
export const downloading = localize('downloading', "Downloading");
// buildHelper
export const downloadingDacFxDlls = localize('downloadingDacFxDlls', "Downloading Microsoft.Build.Sql nuget to get build DLLs");
export const extractingDacFxDlls = localize('extractingDacFxDlls', "Extracting DacFx build DLLs");
export function errorDownloading(url: string, error: string) { return localize('errorDownloading', "Error downloading {0}. Error: {1}", url, error); }
export function errorExtracting(path: string, error: string) { return localize('errorExtracting', "Error extracting files from {0}. Error: {1}", path, error); }

View File

@@ -4,7 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import * as os from 'os';
import * as fs from 'fs';
import * as request from 'request';
import * as vscode from 'vscode';
import axios, { AxiosRequestConfig } from 'axios';
import * as constants from '../common/constants';
const DownloadTimeoutMs = 20000;
/**
* Class includes method for making http request
@@ -48,4 +54,53 @@ export class HttpClient {
}
return response.data;
}
/**
* Gets a file/fileContents at the given URL. Function is copied from Machine Learning extension extensions/machine-learning/src/common/httpClient.ts
* @param downloadUrl The URL to download the file from
* @param targetPath The path to download the file to
* @param outputChannel The output channel to output status messages to
* @returns Full path to the downloaded file or the contents of the file at the given downloadUrl
*/
public download(downloadUrl: string, targetPath: string, outputChannel?: vscode.OutputChannel): Promise<void> {
return new Promise((resolve, reject) => {
let totalMegaBytes: number | undefined = undefined;
let receivedBytes = 0;
let printThreshold = 0.1;
let downloadRequest = request.get(downloadUrl, { timeout: DownloadTimeoutMs })
.on('error', downloadError => {
outputChannel?.appendLine(constants.downloadError);
reject(downloadError);
})
.on('response', (response) => {
if (response.statusCode !== 200) {
outputChannel?.appendLine(constants.downloadError);
return reject(response.statusMessage);
}
let contentLength = response.headers['content-length'];
let totalBytes = parseInt(contentLength || '0');
totalMegaBytes = totalBytes / (1024 * 1024);
outputChannel?.appendLine(`${constants.downloading} ${downloadUrl} (0 / ${totalMegaBytes.toFixed(2)} MB)`);
})
.on('data', (data) => {
receivedBytes += data.length;
if (totalMegaBytes) {
let receivedMegaBytes = receivedBytes / (1024 * 1024);
let percentage = receivedMegaBytes / totalMegaBytes;
if (percentage >= printThreshold) {
outputChannel?.appendLine(`${constants.downloadProgress} (${receivedMegaBytes.toFixed(2)} / ${totalMegaBytes.toFixed(2)} MB)`);
printThreshold += 0.1;
}
}
});
downloadRequest.pipe(fs.createWriteStream(targetPath))
.on('close', async () => {
resolve();
})
.on('error', (downloadError) => {
reject(downloadError);
downloadRequest.abort();
});
});
}
}