Remove fs-extra-promise and fs-extra (#17226)

* Remove fs-extra-promise

* const

* Remove one more

* Update comment
This commit is contained in:
Charles Gagnon 2022-01-31 13:21:09 -08:00 коммит произвёл GitHub
Родитель b4f9c74403
Коммит c3017781cc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 86 добавлений и 131 удалений

Просмотреть файл

@ -124,7 +124,6 @@
"error-ex": "^1.3.0",
"figures": "^1.4.0",
"find-remove": "1.2.1",
"fs-extra-promise": "^0.3.1",
"getmac": "1.2.1",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.1",

Просмотреть файл

@ -7,7 +7,7 @@ import * as path from 'path';
import { Runtime } from '../models/platform';
import ServiceDownloadProvider from './serviceDownloadProvider';
import { IConfig, IStatusView } from './interfaces';
import * as fs from 'fs-extra-promise';
import * as fs from 'fs/promises';
/*
@ -23,29 +23,29 @@ export default class ServerProvider {
/**
* Given a file path, returns the path to the SQL Tools service file.
*/
public findServerPath(filePath: string): Promise<string> {
return fs.lstatAsync(filePath).then(stats => {
public async findServerPath(filePath: string): Promise<string | undefined> {
const stats = await fs.lstat(filePath);
// If a file path was passed, assume its the launch file.
if (stats.isFile()) {
return filePath;
}
// Otherwise, search the specified folder.
let candidate: string;
if (this._config !== undefined) {
let executableFiles: string[] = this._config.getSqlToolsExecutableFiles();
executableFiles.forEach(element => {
let executableFile = path.join(filePath, element);
if (candidate === undefined && fs.existsSync(executableFile)) {
candidate = executableFile;
return candidate;
for (const executableFile of executableFiles) {
const executablePath = path.join(filePath, executableFile);
try {
if (await fs.stat(executablePath)) {
return executablePath;
}
});
} catch (err) {
// no-op, the exe files list has all possible options and so depending on the platform we expect some
// to always fail
}
return candidate;
});
}
}
return undefined;
}
/**
@ -75,25 +75,22 @@ export default class ServerProvider {
/**
* Returns the path of the installed service
*/
public getServerPath(runtime: Runtime): Promise<string> {
const installDirectory = this._downloadProvider.getInstallDirectory(runtime);
public async getServerPath(runtime: Runtime): Promise<string> {
const installDirectory = await this._downloadProvider.getOrMakeInstallDirectory(runtime);
return this.findServerPath(installDirectory);
}
/**
* Downloads the service and returns the path of the installed service
*/
public downloadServerFiles(runtime: Runtime): Promise<string> {
return new Promise<string>((resolve, reject) => {
const installDirectory = this._downloadProvider.getInstallDirectory(runtime);
return this._downloadProvider.installSQLToolsService(runtime).then(_ => {
return this.findServerPath(installDirectory).then(result => {
return resolve(result);
});
}).catch(err => {
public async downloadServerFiles(runtime: Runtime): Promise<string> {
const installDirectory = await this._downloadProvider.getOrMakeInstallDirectory(runtime);
try {
await this._downloadProvider.installSQLToolsService(runtime);
return this.findServerPath(installDirectory);
} catch (err) {
this._statusView.serviceInstallationFailed();
reject(err);
});
});
throw err;
}
}
}

Просмотреть файл

@ -9,7 +9,7 @@ import { Runtime, getRuntimeDisplayName } from '../models/platform';
import { IConfig, IStatusView, IPackage, PackageError, IHttpClient, IDecompressProvider } from './interfaces';
import { ILogger } from '../models/interfaces';
import * as Constants from '../constants/constants';
import * as fse from 'fs-extra';
import * as fs from 'fs/promises';
/*
* Service Download Provider class which handles downloading the SQL Tools service.
@ -45,16 +45,19 @@ export default class ServiceDownloadProvider {
/**
* Returns SQL tools service installed folder.
* Returns SQL tools service installed folder, creating it if it doesn't exist.
*/
public getInstallDirectory(platform: Runtime): string {
public async getOrMakeInstallDirectory(platform: Runtime): Promise<string> {
let basePath = this.getInstallDirectoryRoot();
let versionFromConfig = this._config.getSqlToolsPackageVersion();
basePath = basePath.replace('{#version#}', versionFromConfig);
basePath = basePath.replace('{#platform#}', getRuntimeDisplayName(platform));
if (!fse.existsSync(basePath)) {
fse.mkdirsSync(basePath);
try {
await fs.mkdir(basePath, { recursive: true });
} catch {
// Best effort to make the folder, if it already exists (expected scenario) or something else happens
// then just carry on
}
return basePath;
}
@ -85,14 +88,13 @@ export default class ServiceDownloadProvider {
/**
* Downloads the SQL tools service and decompress it in the install folder.
*/
public installSQLToolsService(platform: Runtime): Promise<boolean> {
public async installSQLToolsService(platform: Runtime): Promise<boolean> {
const proxy = <string>this._config.getWorkspaceConfig('http.proxy');
const strictSSL = this._config.getWorkspaceConfig('http.proxyStrictSSL', true);
const authorization = this._config.getWorkspaceConfig('http.proxyAuthorization');
return new Promise<boolean>((resolve, reject) => {
const fileName = this.getDownloadFileName(platform);
const installDirectory = this.getInstallDirectory(platform);
const installDirectory = await this.getOrMakeInstallDirectory(platform);
this._logger.appendLine(`${Constants.serviceInstallingTo} ${installDirectory}.`);
const urlString = this.getGetDownloadUrl(fileName);
@ -106,24 +108,19 @@ export default class ServiceDownloadProvider {
tmpFile: undefined,
isZipFile: isZipFile
};
this.createTempFile(pkg).then(tmpResult => {
const tmpResult = await this.createTempFile(pkg);
pkg.tmpFile = tmpResult;
this._httpClient.downloadFile(pkg.url, pkg, this._logger, this._statusView, proxy, strictSSL, authorization).then(_ => {
try {
await this._httpClient.downloadFile(pkg.url, pkg, this._logger, this._statusView, proxy, strictSSL, authorization);
this._logger.logDebug(`Downloaded to ${pkg.tmpFile.name}...`);
this._logger.appendLine(' Done!');
this.install(pkg).then(result => {
resolve(true);
}).catch(installError => {
reject(installError);
});
}).catch(downloadError => {
this._logger.appendLine(`[ERROR] ${downloadError}`);
reject(downloadError);
});
});
});
await this.install(pkg);
} catch (err) {
this._logger.appendLine(`[ERROR] ${err}`);
throw err;
}
return true;
}
private createTempFile(pkg: IPackage): Promise<tmp.SynchrounousResult> {

Просмотреть файл

@ -83,7 +83,7 @@ export function getServiceInstallDirectory(runtime: Runtime): Promise<string> {
if (runtime === undefined) {
PlatformInformation.getCurrent().then(platformInfo => {
if (platformInfo.isValidRuntime) {
resolve(downloadProvider.getInstallDirectory(platformInfo.runtimeId));
resolve(downloadProvider.getOrMakeInstallDirectory(platformInfo.runtimeId));
} else {
reject('unsupported runtime');
}
@ -91,7 +91,7 @@ export function getServiceInstallDirectory(runtime: Runtime): Promise<string> {
reject(error);
});
} else {
resolve(downloadProvider.getInstallDirectory(runtime));
resolve(downloadProvider.getOrMakeInstallDirectory(runtime));
}
});

Просмотреть файл

@ -14,7 +14,7 @@ import { Runtime } from '../src/models/platform';
import * as path from 'path';
import { ILogger } from '../src/models/interfaces';
import { Logger } from '../src/models/logger';
import * as fse from 'fs-extra';
import * as fs from 'fs/promises';
interface IFixture {
downloadUrl: string;
@ -47,7 +47,7 @@ suite('ServiceDownloadProvider Tests', () => {
config.setup(x => x.getSqlToolsPackageVersion()).returns(() => expectedVersionFromConfig);
let downloadProvider = new ServiceDownloadProvider(config.object, undefined, testStatusView.object,
testHttpClient.object, testDecompressProvider.object);
let actual = downloadProvider.getInstallDirectory(Runtime.OSX_10_11_64);
let actual = downloadProvider.getOrMakeInstallDirectory(Runtime.OSX_10_11_64);
assert.equal(expected, actual);
done();
});
@ -62,7 +62,7 @@ suite('ServiceDownloadProvider Tests', () => {
config.setup(x => x.getSqlToolsPackageVersion()).returns(() => expectedVersionFromConfig);
let downloadProvider = new ServiceDownloadProvider(config.object, undefined, testStatusView.object,
testHttpClient.object, testDecompressProvider.object);
let actual = downloadProvider.getInstallDirectory(Runtime.OSX_10_11_64);
let actual = downloadProvider.getOrMakeInstallDirectory(Runtime.OSX_10_11_64);
assert.equal(expected, actual);
done();
});
@ -77,7 +77,7 @@ suite('ServiceDownloadProvider Tests', () => {
config.setup(x => x.getSqlToolsPackageVersion()).returns(() => expectedVersionFromConfig);
let downloadProvider = new ServiceDownloadProvider(config.object, undefined, testStatusView.object,
testHttpClient.object, testDecompressProvider.object);
let actual = downloadProvider.getInstallDirectory(Runtime.OSX_10_11_64);
let actual = downloadProvider.getOrMakeInstallDirectory(Runtime.OSX_10_11_64);
assert.equal(expected, actual);
done();
});
@ -92,7 +92,7 @@ suite('ServiceDownloadProvider Tests', () => {
config.setup(x => x.getSqlToolsPackageVersion()).returns(() => expectedVersionFromConfig);
let downloadProvider = new ServiceDownloadProvider(config.object, undefined, testStatusView.object,
testHttpClient.object, testDecompressProvider.object);
let actual = downloadProvider.getInstallDirectory(Runtime.OSX_10_11_64);
let actual = downloadProvider.getOrMakeInstallDirectory(Runtime.OSX_10_11_64);
assert.equal(expected, actual);
done();
});
@ -114,18 +114,18 @@ suite('ServiceDownloadProvider Tests', () => {
});
});
function createDownloadProvider(fixture: IFixture): IFixture {
async function createDownloadProvider(fixture: IFixture): Promise<IFixture> {
let fileName = 'fileName';
let baseDownloadUrl = 'baseDownloadUrl/{#version#}/{#fileName#}';
let version = '1.0.0';
let installFolder = path.join(__dirname, 'testService');
let fileNamesJson = { Windows_7_64: `${fileName}` };
let downloadUrl = 'baseDownloadUrl/1.0.0/fileName';
fse.remove(installFolder, function (err): void {
if (err) {
return console.error(err);
try {
await fs.rmdir(installFolder);
} catch (err) {
console.error(err);
}
});
config.setup(x => x.getSqlToolsInstallDirectory()).returns(() => installFolder);
config.setup(x => x.getSqlToolsConfigValue('downloadFileNames')).returns(() => fileNamesJson);
@ -151,7 +151,7 @@ suite('ServiceDownloadProvider Tests', () => {
return fixture;
}
test('installSQLToolsService should download and decompress the service and update the status', () => {
test('installSQLToolsService should download and decompress the service and update the status', async () => {
let fixture: IFixture = {
downloadUrl: undefined,
downloadProvider: undefined,
@ -159,7 +159,7 @@ suite('ServiceDownloadProvider Tests', () => {
decompressResult: Promise.resolve()
};
fixture = createDownloadProvider(fixture);
fixture = await createDownloadProvider(fixture);
return fixture.downloadProvider.installSQLToolsService(Runtime.Windows_7_64).then(_ => {
testHttpClient.verify(x => x.downloadFile(fixture.downloadUrl, TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(),
TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()),
@ -172,7 +172,7 @@ suite('ServiceDownloadProvider Tests', () => {
});
// @cssuh 10/22 - commented this test because it was throwing some random undefined errors
test.skip('installSQLToolsService should not call decompress if download fails', () => {
test.skip('installSQLToolsService should not call decompress if download fails', async () => {
let fixture: IFixture = {
downloadUrl: undefined,
downloadProvider: undefined,
@ -180,7 +180,7 @@ suite('ServiceDownloadProvider Tests', () => {
decompressResult: Promise.resolve()
};
fixture = createDownloadProvider(fixture);
fixture = await createDownloadProvider(fixture);
return fixture.downloadProvider.installSQLToolsService(Runtime.Windows_7_64).catch(_ => {
testHttpClient.verify(x => x.downloadFile(fixture.downloadUrl, TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(),
TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()),
@ -192,7 +192,7 @@ suite('ServiceDownloadProvider Tests', () => {
});
});
test.skip('installSQLToolsService should not update status to installed decompress fails', () => {
test.skip('installSQLToolsService should not update status to installed decompress fails', async () => {
let fixture: IFixture = {
downloadUrl: undefined,
downloadProvider: undefined,
@ -200,7 +200,7 @@ suite('ServiceDownloadProvider Tests', () => {
decompressResult: Promise.reject('download failed')
};
fixture = createDownloadProvider(fixture);
fixture = await createDownloadProvider(fixture);
return fixture.downloadProvider.installSQLToolsService(Runtime.Windows_7_64).catch(_ => {
testHttpClient.verify(x => x.downloadFile(fixture.downloadUrl, TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(),
TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()),

Просмотреть файл

@ -33,7 +33,7 @@ suite('Server tests', () => {
function setupMocks(fixture: IFixture): void {
testConfig.setup(x => x.getSqlToolsExecutableFiles()).returns(() => fixture.executablesFromConfig);
testDownloadProvider.setup(x => x.getInstallDirectory(fixture.runtime)).returns(() => fixture.installDir);
testDownloadProvider.setup(x => x.getOrMakeInstallDirectory(fixture.runtime)).returns(() => Promise.resolve(fixture.installDir));
testDownloadProvider.setup(x => x.installSQLToolsService(fixture.runtime)).callback(() => {
fixture.executablesFromConfig = [fixture.executableFileName.replace(fixture.installDir, '')];
}).returns(() => { return Promise.resolve(true); });

Просмотреть файл

@ -780,11 +780,6 @@ bl@^4.0.3:
inherits "^2.0.4"
readable-stream "^3.4.0"
bluebird@^2.10.1:
version "2.11.0"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"
integrity sha1-U0uQM8AiyVecVro7Plpcqvu2UOE=
bluebird@^3.3.4:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
@ -2163,25 +2158,6 @@ fs-constants@^1.0.0:
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
fs-extra-promise@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/fs-extra-promise/-/fs-extra-promise-0.3.1.tgz#dd49b1e2135524f519ed8e9f5f4e03913c8e414b"
integrity sha1-3Umx4hNVJPUZ7Y6fX04DkTyOQUs=
dependencies:
bluebird "^2.10.1"
fs-extra "^0.26.2"
fs-extra@^0.26.2:
version "0.26.7"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.26.7.tgz#9ae1fdd94897798edab76d0918cf42d0c3184fa9"
integrity sha1-muH92UiXeY7at20JGM9C0MMYT6k=
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"
klaw "^1.0.0"
path-is-absolute "^1.0.0"
rimraf "^2.2.8"
fs-minipass@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-2.1.0.tgz#7f5036fdbf12c63c169190cbe4199c852271f9fb"
@ -2414,7 +2390,7 @@ glogg@^1.0.0:
dependencies:
sparkles "^1.0.0"
graceful-fs@4.X, graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.2:
graceful-fs@4.X, graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.2.2:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==
@ -3270,13 +3246,6 @@ json5@^0.5.1:
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=
jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
integrity sha1-NzaitCi4e72gzIO1P6PWM6NcKug=
optionalDependencies:
graceful-fs "^4.1.6"
jsprim@^1.2.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
@ -3324,13 +3293,6 @@ kind-of@^6.0.0, kind-of@^6.0.2:
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==
klaw@^1.0.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439"
integrity sha1-QIhDO0azsbolnXh4XY6W9zugJDk=
optionalDependencies:
graceful-fs "^4.1.9"
last-run@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/last-run/-/last-run-1.1.1.tgz#45b96942c17b1c79c772198259ba943bebf8ca5b"