From bb88a807e3dde429dd9ceb52cdccd0b2a23d4623 Mon Sep 17 00:00:00 2001 From: ruiqiyang-MSFT <33129891+richard6094@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:14:48 +0800 Subject: [PATCH] fix: remove auto popup install dependency (#11905) * fix: remove auto popup install dependency * fix: modfiy UT for remove auto install dependency * fix: remove no needed import * fix: remove code no longer used * fix: remove auto install in officedev --------- Co-authored-by: Ruiqi Yang (from Dev Box) --- .../src/handlers/officeDevHandlers.ts | 46 +----------- .../test/handlers/officeDevHandler.test.ts | 75 ------------------- 2 files changed, 1 insertion(+), 120 deletions(-) diff --git a/packages/vscode-extension/src/handlers/officeDevHandlers.ts b/packages/vscode-extension/src/handlers/officeDevHandlers.ts index 7d9658c91e..e114f31f1a 100644 --- a/packages/vscode-extension/src/handlers/officeDevHandlers.ts +++ b/packages/vscode-extension/src/handlers/officeDevHandlers.ts @@ -7,13 +7,7 @@ "use strict"; import { FxError, Result, ok } from "@microsoft/teamsfx-api"; -import { - globalStateGet, - globalStateUpdate, - isManifestOnlyOfficeAddinProject, -} from "@microsoft/teamsfx-core"; -import * as fs from "fs-extra"; -import * as path from "path"; +import { globalStateGet, globalStateUpdate } from "@microsoft/teamsfx-core"; import * as vscode from "vscode"; import { GlobalKey } from "../constants"; import { OfficeDevTerminal, TriggerCmdType } from "../debug/taskTerminal/officeDevTerminal"; @@ -167,26 +161,6 @@ export function installOfficeAddInDependencies(args?: any[]): Promise> { ExtTelemetry.sendTelemetryEvent(TelemetryEvent.stopAddInDebug, getTriggerFromProperty(args)); const terminal = OfficeDevTerminal.getInstance(TriggerCmdType.triggerStopDebug); @@ -208,7 +182,6 @@ export async function autoOpenOfficeDevProjectHandler(): Promise { const isOpenReadMe = (await globalStateGet(GlobalKey.OpenReadMe, "")) as string; const isOpenSampleReadMe = (await globalStateGet(GlobalKey.OpenSampleReadMe, false)) as boolean; const createWarnings = (await globalStateGet(GlobalKey.CreateWarnings, "")) as string; - const autoInstallDependency = (await globalStateGet(GlobalKey.AutoInstallDependency)) as boolean; if (isOpenWalkThrough) { // current the welcome walkthrough is not supported for wxp add in await globalStateUpdate(GlobalKey.OpenWalkThrough, false); @@ -225,21 +198,4 @@ export async function autoOpenOfficeDevProjectHandler(): Promise { await openSampleReadmeHandler([TelemetryTriggerFrom.Auto]); await globalStateUpdate(GlobalKey.OpenSampleReadMe, false); } - if (autoInstallDependency) { - if (!isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? "")) - void popupOfficeAddInDependenciesMessage(); - await globalStateUpdate(GlobalKey.AutoInstallDependency, false); - } - if ( - globalVariables.isOfficeAddInProject && - !checkOfficeAddInInstalled(globalVariables.workspaceUri?.fsPath ?? "") && - !isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? "") - ) { - void popupOfficeAddInDependenciesMessage(); - } -} - -export function checkOfficeAddInInstalled(directory: string): boolean { - const nodeModulesExists = fs.existsSync(path.join(directory, "node_modules")); - return nodeModulesExists; } diff --git a/packages/vscode-extension/test/handlers/officeDevHandler.test.ts b/packages/vscode-extension/test/handlers/officeDevHandler.test.ts index 4b994779e6..8cbde9cbda 100644 --- a/packages/vscode-extension/test/handlers/officeDevHandler.test.ts +++ b/packages/vscode-extension/test/handlers/officeDevHandler.test.ts @@ -121,29 +121,6 @@ describe("officeDevHandler", () => { "https://aka.ms/OfficeAddinsPromptLibrary" ); }); - - it("popupOfficeAddInDependenciesMessage", async () => { - const autoInstallDependencyHandlerStub = sandbox.stub( - autoOpenHelper, - "autoInstallDependencyHandler" - ); - sandbox.stub(localizeUtils, "localize").returns("installPopUp"); - sandbox - .stub(vscode.window, "showInformationMessage") - .callsFake((_message: string, option: any, ...items: vscode.MessageItem[]) => { - return Promise.resolve(option); - }); - await officeDevHandlers.popupOfficeAddInDependenciesMessage(); - chai.assert(autoInstallDependencyHandlerStub.calledOnce); - }); - - it("checkOfficeAddInInstalled", async () => { - mockfs({ - "/test/node_modules/test": "", - }); - const node_modulesExists = officeDevHandlers.checkOfficeAddInInstalled("/test"); - chai.assert.isTrue(node_modulesExists); - }); }); describe("autoOpenOfficeDevProjectHandler", () => { @@ -216,58 +193,6 @@ describe("autoOpenOfficeDevProjectHandler", () => { chai.assert.isTrue(executeCommandStub.calledOnce); }); - it("autoInstallDependency", async () => { - sandbox.stub(globalVariables, "workspaceUri").value(vscode.Uri.file("test")); - sandbox.stub(globalState, "globalStateGet").callsFake(async (key: string) => { - if (key === "teamsToolkit:autoInstallDependency") { - return true; - } else { - return ""; - } - }); - sandbox.stub(localizeUtils, "localize").returns("installPopUp"); - const showInformationMessageStub = sandbox - .stub(vscode.window, "showInformationMessage") - .callsFake((_message: string, option: any, ...items: vscode.MessageItem[]) => { - return Promise.resolve("No" as any); - }); - const globalStateUpdateStub = sandbox.stub(globalState, "globalStateUpdate"); - const isManifestOnlyOfficeAddinProjectStub = sandbox - .stub(projectSettingsHelper, "isManifestOnlyOfficeAddinProject") - .returns(false); - - await officeDevHandlers.autoOpenOfficeDevProjectHandler(); - - chai.assert(showInformationMessageStub.callCount == 2); - chai.assert(globalStateUpdateStub.calledOnce); - }); - - it("autoInstallDependency when extension launch", async () => { - sandbox.stub(globalVariables, "workspaceUri").value({ fsPath: "/test" }); - sandbox.stub(globalState, "globalStateGet").resolves(""); - sandbox.stub(globalVariables, "isOfficeAddInProject").value(true); - - sandbox.stub(localizeUtils, "localize").returns("ask install window pop up"); - const autoInstallDependencyHandlerStub = sandbox.stub( - autoOpenHelper, - "autoInstallDependencyHandler" - ); - - const showInformationMessageStub = sandbox - .stub(vscode.window, "showInformationMessage") - .callsFake((_message: string, option: any, ...items: vscode.MessageItem[]) => { - return Promise.resolve(option); - }); - - const isManifestOnlyOfficeAddinProjectStub = sandbox - .stub(projectSettingsHelper, "isManifestOnlyOfficeAddinProject") - .returns(false); - - await officeDevHandlers.autoOpenOfficeDevProjectHandler(); - - chai.assert(autoInstallDependencyHandlerStub.calledOnce); - }); - it("openOfficeDevFolder", async () => { const folderPath = vscode.Uri.file("/test"); const executeCommandStub = sandbox.stub(vscode.commands, "executeCommand");