Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace fse with AzExtFsUtils where possible #3268

Merged
merged 13 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@
"@azure/storage-blob": "^12.5.0",
"@microsoft/vscode-azext-azureappservice": "^0.7.2",
"@microsoft/vscode-azext-azureutils": "^0.3.4",
"@microsoft/vscode-azext-utils": "^0.3.7",
"@microsoft/vscode-azext-utils": "^0.3.12",
"escape-string-regexp": "^4.0.0",
"extract-zip": "^2.0.1",
"fs-extra": "^4.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/addBinding/settingSteps/BindingNameStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import { ParsedFunctionJson } from '../../../funcConfig/function';
import { localize } from '../../../localize';
import { IBindingWizardContext } from '../IBindingWizardContext';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class BindingNameStep extends StringPromptStep {
private async bindingExists(context: IBindingWizardContext, val: string): Promise<boolean> {
try {
if (!this._functionJson) {
this._functionJson = new ParsedFunctionJson(await fse.readJSON(context.functionJsonPath));
this._functionJson = new ParsedFunctionJson(await AzExtFsExtra.readJSON(context.functionJsonPath));
}

return !!this._functionJson.bindings.find(b => b.name === val);
Expand Down
9 changes: 4 additions & 5 deletions src/commands/appSettings/downloadAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import { StringDictionary } from "@azure/arm-appservice";
import { AppSettingsTreeItem, confirmOverwriteSettings, IAppSettingsClient } from "@microsoft/vscode-azext-azureappservice";
import { IActionContext } from "@microsoft/vscode-azext-utils";
import * as fse from 'fs-extra';
import { AzExtFsExtra, IActionContext } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { functionFilter, localSettingsFileName, viewOutput } from "../../constants";
import { ext } from "../../extensionVariables";
Expand Down Expand Up @@ -41,7 +40,7 @@ export async function downloadAppSettingsInternal(context: IActionContext, clien
const isEncrypted: boolean | undefined = localSettings.IsEncrypted;
if (localSettings.IsEncrypted) {
await decryptLocalSettings(context, localSettingsUri);
localSettings = <ILocalSettingsJson>await fse.readJson(localSettingsPath);
localSettings = await AzExtFsExtra.readJSON<ILocalSettingsJson>(localSettingsPath);
}

try {
Expand All @@ -56,8 +55,8 @@ export async function downloadAppSettingsInternal(context: IActionContext, clien
await confirmOverwriteSettings(context, remoteSettings.properties, localSettings.Values, localSettingsFileName);
}

await fse.ensureFile(localSettingsPath);
await fse.writeJson(localSettingsPath, localSettings, { spaces: 2 });
await AzExtFsExtra.ensureFile(localSettingsPath);
await AzExtFsExtra.writeJSON(localSettingsPath, localSettings);

} finally {
if (isEncrypted) {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/appSettings/getLocalSettingsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IActionContext } from '@microsoft/vscode-azext-utils';
import * as fse from 'fs-extra';
import { AzExtFsExtra, IActionContext } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { workspace, WorkspaceFolder } from "vscode";
import { localSettingsFileName } from "../../constants";
Expand All @@ -21,7 +20,7 @@ export async function getLocalSettingsFile(context: IActionContext, message: str
const projectPath: string | undefined = await tryGetFunctionProjectRoot(context, workspaceFolder);
if (projectPath) {
const localSettingsFile: string = path.join(projectPath, localSettingsFileName);
if (await fse.pathExists(localSettingsFile)) {
if (await AzExtFsExtra.pathExists(localSettingsFile)) {
return localSettingsFile;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/commands/appSettings/uploadAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import { StringDictionary } from "@azure/arm-appservice";
import { AppSettingsTreeItem, confirmOverwriteSettings, IAppSettingsClient } from "@microsoft/vscode-azext-azureappservice";
import { IActionContext } from "@microsoft/vscode-azext-utils";
import * as fse from 'fs-extra';
import { AzExtFsExtra, IActionContext } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { functionFilter, localSettingsFileName, viewOutput } from "../../constants";
import { ext } from "../../extensionVariables";
Expand Down Expand Up @@ -37,11 +36,11 @@ export async function uploadAppSettingsInternal(context: IActionContext, client:
const localSettingsPath: string = await getLocalSettingsFile(context, message, workspaceFolder);
const localSettingsUri: vscode.Uri = vscode.Uri.file(localSettingsPath);

let localSettings: ILocalSettingsJson = <ILocalSettingsJson>await fse.readJson(localSettingsPath);
let localSettings: ILocalSettingsJson = <ILocalSettingsJson>await AzExtFsExtra.readJSON(localSettingsPath);
if (localSettings.IsEncrypted) {
await decryptLocalSettings(context, localSettingsUri);
try {
localSettings = <ILocalSettingsJson>await fse.readJson(localSettingsPath);
localSettings = await AzExtFsExtra.readJSON<ILocalSettingsJson>(localSettingsPath);
} finally {
await encryptLocalSettings(context, localSettingsUri);
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/createFunction/FunctionCreateStepBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardExecuteStep, callWithTelemetryAndErrorHandling, IActionContext } from '@microsoft/vscode-azext-utils';
import * as fse from 'fs-extra';
import { AzExtFsExtra, AzureWizardExecuteStep, callWithTelemetryAndErrorHandling, IActionContext } from '@microsoft/vscode-azext-utils';
import { Progress, Uri, window, workspace } from 'vscode';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
Expand Down Expand Up @@ -76,7 +75,7 @@ function runPostFunctionCreateSteps(func: ICachedFunction): void {
context.telemetry.suppressIfSuccessful = true;

if (getContainingWorkspace(func.projectPath)) {
if (await fse.pathExists(func.newFilePath)) {
if (await AzExtFsExtra.pathExists(func.newFilePath)) {
await window.showTextDocument(await workspace.openTextDocument(Uri.file(func.newFilePath)));
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/createFunction/FunctionNameStepBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardPromptStep } from '@microsoft/vscode-azext-utils';
import * as fse from 'fs-extra';
import { AzExtFsExtra, AzureWizardPromptStep } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { localize } from '../../localize';
import { IFunctionTemplate } from '../../templates/IFunctionTemplate';
Expand Down Expand Up @@ -39,7 +38,7 @@ export abstract class FunctionNameStepBase<T extends IFunctionWizardContext> ext

while (count < maxCount) {
const fileName: string = defaultValue + count.toString();
if (!(await fse.pathExists(path.join(folderPath, fileExtension ? fileName + fileExtension : fileName)))) {
if (!(await AzExtFsExtra.pathExists(path.join(folderPath, fileExtension ? fileName + fileExtension : fileName)))) {
return fileName;
}
count += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { localize } from "../../../localize";
import { IFunctionTemplate } from '../../../templates/IFunctionTemplate';
Expand All @@ -18,7 +18,7 @@ export class DotnetFunctionNameStep extends FunctionNameStepBase<IDotnetFunction
}

protected async validateFunctionNameCore(context: IDotnetFunctionWizardContext, name: string): Promise<string | undefined> {
if (await fse.pathExists(path.join(context.projectPath, name + getFileExtension(context)))) {
if (await AzExtFsExtra.pathExists(path.join(context.projectPath, name + getFileExtension(context)))) {
return localize('existingFile', 'A file with the name "{0}" already exists.', name);
} else {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import { nonNullProp } from '../../../utils/nonNull';
import { getJavaFunctionFilePath, IJavaProjectWizardContext } from '../../createNewProject/javaSteps/IJavaProjectWizardContext';
import { FunctionCreateStepBase } from '../FunctionCreateStepBase';
Expand Down Expand Up @@ -30,8 +30,8 @@ export class JavaFunctionCreateStep extends FunctionCreateStepBase<IFunctionWiza
args.set("className", functionName.replace('-', '_'));
const content: string = substituteParametersInTemplate(template, args);
const path: string = getJavaFunctionFilePath(context.projectPath, packageName, functionName);
await fse.ensureFile(path);
await fse.writeFile(path, content);
await AzExtFsExtra.ensureFile(path);
await AzExtFsExtra.writeFile(path, content);
return getJavaFunctionFilePath(context.projectPath, packageName, functionName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import { localize } from "../../../localize";
import { IFunctionTemplate } from '../../../templates/IFunctionTemplate';
import { nonNullProp } from '../../../utils/nonNull';
Expand All @@ -20,7 +20,7 @@ export class JavaFunctionNameStep extends FunctionNameStepBase<IFunctionWizardCo

protected async validateFunctionNameCore(context: IFunctionWizardContext & IJavaProjectWizardContext, name: string): Promise<string | undefined> {
const packageName: string = nonNullProp(context, 'javaPackageName');
if (await fse.pathExists(getJavaFunctionFilePath(context.projectPath, packageName, name))) {
if (await AzExtFsExtra.pathExists(getJavaFunctionFilePath(context.projectPath, packageName, name))) {
return localize('existingError', 'A function with name "{0}" already exists in package "{1}".', getJavaClassName(name), packageName);
} else {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { functionJsonFileName, ProjectLanguage } from '../../../constants';
import { IFunctionBinding, IFunctionJson } from '../../../funcConfig/function';
import { IScriptFunctionTemplate } from '../../../templates/script/parseScriptTemplates';
import * as fsUtil from '../../../utils/fs';
import { nonNullProp } from '../../../utils/nonNull';
import { FunctionCreateStepBase } from '../FunctionCreateStepBase';
import { getBindingSetting } from '../IFunctionWizardContext';
Expand Down Expand Up @@ -37,9 +36,9 @@ export class ScriptFunctionCreateStep extends FunctionCreateStepBase<IScriptFunc
public async executeCore(context: IScriptFunctionWizardContext): Promise<string> {
const functionPath: string = path.join(context.projectPath, nonNullProp(context, 'functionName'));
const template: IScriptFunctionTemplate = nonNullProp(context, 'functionTemplate');
await fse.ensureDir(functionPath);
await AzExtFsExtra.ensureDir(functionPath);
await Promise.all(Object.keys(template.templateFiles).map(async f => {
await fse.writeFile(path.join(functionPath, f), template.templateFiles[f]);
await AzExtFsExtra.writeFile(path.join(functionPath, f), template.templateFiles[f]);
}));

const triggerBinding: IFunctionBinding = nonNullProp(template.functionJson, 'triggerBinding');
Expand All @@ -53,7 +52,7 @@ export class ScriptFunctionCreateStep extends FunctionCreateStepBase<IScriptFunc
}

const functionJsonPath: string = path.join(functionPath, functionJsonFileName);
await fsUtil.writeFormattedJson(functionJsonPath, functionJson);
await AzExtFsExtra.writeJSON(functionJsonPath, functionJson);

const language: ProjectLanguage = nonNullProp(context, 'language');
const fileName: string | undefined = getScriptFileNameFromLanguage(language);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { localize } from "../../../localize";
import { IScriptFunctionTemplate } from '../../../templates/script/parseScriptTemplates';
Expand All @@ -18,7 +18,7 @@ export class ScriptFunctionNameStep extends FunctionNameStepBase<IScriptFunction
}

protected async validateFunctionNameCore(context: IScriptFunctionWizardContext, name: string): Promise<string | undefined> {
if (await fse.pathExists(path.join(context.projectPath, name))) {
if (await AzExtFsExtra.pathExists(path.join(context.projectPath, name))) {
return localize('existingFolderError', 'A folder with the name "{0}" already exists.', name);
} else {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { tsConfigFileName, tsDefaultOutDir } from '../../../constants';
import { IFunctionJson } from '../../../funcConfig/function';
Expand All @@ -16,8 +16,8 @@ export class TypeScriptFunctionCreateStep extends ScriptFunctionCreateStep {
let outDir: string = tsDefaultOutDir;
try {
const tsconfigPath: string = path.join(context.projectPath, tsConfigFileName);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
outDir = (await fse.readJSON(tsconfigPath)).compilerOptions.outDir;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
outDir = (await AzExtFsExtra.readJSON<any>(tsconfigPath)).compilerOptions.outDir;
} catch {
// ignore and use default outDir
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { DialogResponses, IActionContext } from '@microsoft/vscode-azext-utils';
import * as fse from 'fs-extra';
import { AzExtFsExtra, DialogResponses, IActionContext } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { gitignoreFileName, hostFileName, localSettingsFileName, ProjectLanguage } from '../../../constants';
import { azureWebJobsStorageKey, MismatchBehavior, setLocalAppSetting } from '../../../funcConfig/local.settings';
Expand Down Expand Up @@ -51,7 +50,7 @@ export class DotnetProjectCreateStep extends ProjectCreateStepBase {
const filesToCheck: string[] = [projName, gitignoreFileName, localSettingsFileName, hostFileName];
const existingFiles: string[] = [];
for (const fileName of filesToCheck) {
if (await fse.pathExists(path.join(context.projectPath, fileName))) {
if (await AzExtFsExtra.pathExists(path.join(context.projectPath, fileName))) {
existingFiles.push(fileName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fse from 'fs-extra';
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { Progress } from 'vscode';
import { buildGradleFileName, JavaBuildTool, settingsGradleFileName } from '../../../constants';
Expand All @@ -27,13 +27,13 @@ export class GradleProjectCreateStep extends ScriptProjectCreateStep {

const settingsGradlePath: string = path.join(context.projectPath, settingsGradleFileName);
if (await confirmOverwriteFile(context, settingsGradlePath)) {
await fse.writeFile(settingsGradlePath, this.getSettingsGradleContent(context));
await AzExtFsExtra.writeFile(settingsGradlePath, this.getSettingsGradleContent(context));
}

const buildGradlePath: string = path.join(context.projectPath, buildGradleFileName);
const buildGradleContent: string = await this.getBuildGradleContent(context);
if (await confirmOverwriteFile(context, buildGradlePath)) {
await fse.writeFile(buildGradlePath, buildGradleContent);
await AzExtFsExtra.writeFile(buildGradlePath, buildGradleContent);
}
}

Expand Down