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

fix: bug 27332508: disable auto install dependencies for manifest-only office add-in #11234

Merged
merged 13 commits into from
May 23, 2024
Merged
6 changes: 6 additions & 0 deletions packages/fx-core/src/common/projectSettingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export function isValidOfficeAddInProject(workspacePath?: string): boolean {
}
}

export function isManifestOnlyOfficeAddinProject(workspacePath?: string): boolean {
if (!workspacePath) return false;
const srcPath = path.join(workspacePath, "src");
return !fs.existsSync(srcPath);
}

export function fetchManifestList(
workspacePath?: string,
officeManifestType?: OfficeManifestType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,11 @@ describe("fetchManifestList", () => {
)
.to.deep.equal(["manifest.json"]);
});

it("should return true when no src folder exists", () => {
mockFs({
"/test/manifest.xml": "",
});
chai.expect(projectSettingsHelper.isManifestOnlyOfficeAddinProject("/test")).to.be.true;
});
});
7 changes: 6 additions & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@
{
"command": "fx-extension.localdebug",
"title": "%teamstoolkit.commands.localDebug.title%",
"enablement": "!fx-extension.commandLocked",
"enablement": "!fx-extension.commandLocked && !fx-extension.isManifestOnlyOfficeAddIn",
"category": "Teams"
},
{
Expand Down Expand Up @@ -888,6 +888,11 @@
"title": "%teamstoolkit.commands.feedbackLink.title%",
"icon": "$(info)"
},
{
"command": "fx-extension.stopDebugging",
"title": "%teamstoolkit.commandsTreeViewProvider.officeAddIn.stopDebugTitle%",
"enablement": "fx-extension.isOfficeAddIn && !fx-extension.isManifestOnlyOfficeAddIn"
},
{
"command": "fx-extension.invokeChat",
"title": "%teamstoolkit.commandsTreeViewProvider.getCopilotHelpTitle%",
Expand Down
7 changes: 7 additions & 0 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
isOfficeAddInProject,
isSPFxProject,
isTeamsFxProject,
isOfficeManifestOnlyProject,
setUriEventHandler,
unsetIsTeamsFxProject,
workspaceUri,
Expand Down Expand Up @@ -147,6 +148,12 @@ export async function activate(context: vscode.ExtensionContext) {
isOfficeAddInProject
);

await vscode.commands.executeCommand(
"setContext",
"fx-extension.isManifestOnlyOfficeAddIn",
isOfficeManifestOnlyProject
);

void VsCodeLogInstance.info("Teams Toolkit extension is now active!");

// Don't wait this async method to let it run in background.
Expand Down
10 changes: 9 additions & 1 deletion packages/vscode-extension/src/globalVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import * as path from "path";
import * as vscode from "vscode";
import { UserState } from "./constants";
import { UriHandler } from "./uriHandler";
import { isValidProject, isValidOfficeAddInProject } from "@microsoft/teamsfx-core";
import {
isValidProject,
isValidOfficeAddInProject,
isManifestOnlyOfficeAddinProject,
} from "@microsoft/teamsfx-core";

/**
* Common variables used throughout the extension. They must be initialized in the activate() method of extension.ts
Expand All @@ -15,6 +19,7 @@ export let context: vscode.ExtensionContext;
export let workspaceUri: vscode.Uri | undefined;
export let isTeamsFxProject = false;
export let isOfficeAddInProject = false;
export let isOfficeManifestOnlyProject = false;
export let isSPFxProject = false;
export let isExistingUser = "no";
export let uriEventHandler: UriHandler;
Expand All @@ -32,6 +37,9 @@ export function initializeGlobalVariables(ctx: vscode.ExtensionContext): void {
isExistingUser = context.globalState.get<string>(UserState.IsExisting) || "no";
isTeamsFxProject = isValidProject(workspaceUri?.fsPath);
isOfficeAddInProject = isValidOfficeAddInProject(workspaceUri?.fsPath);
if (isOfficeAddInProject) {
isOfficeManifestOnlyProject = isManifestOnlyOfficeAddinProject(workspaceUri?.fsPath);
}
// Default Extension log path
// e.g. C:/Users/xx/AppData/Roaming/Code/logs/20230221T095340/window7/exthost/TeamsDevApp.ms-teams-vscode-extension
defaultExtensionLogPath = ctx.logUri.fsPath;
Expand Down
12 changes: 9 additions & 3 deletions packages/vscode-extension/src/officeDevHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"use strict";

import { FxError, Result, Warning, ok } from "@microsoft/teamsfx-api";
import { globalStateGet, globalStateUpdate } from "@microsoft/teamsfx-core";
import {
globalStateGet,
globalStateUpdate,
isManifestOnlyOfficeAddinProject,
} from "@microsoft/teamsfx-core";
import * as fs from "fs-extra";
import * as path from "path";
import * as vscode from "vscode";
Expand Down Expand Up @@ -248,12 +252,14 @@ export async function autoOpenOfficeDevProjectHandler(): Promise<void> {
await globalStateUpdate(GlobalKey.OpenSampleReadMe, false);
}
if (autoInstallDependency) {
void popupOfficeAddInDependenciesMessage();
if (!isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? ""))
void popupOfficeAddInDependenciesMessage();
await globalStateUpdate(GlobalKey.AutoInstallDependency, false);
}
if (
globalVariables.isOfficeAddInProject &&
!checkOfficeAddInInstalled(globalVariables.workspaceUri?.fsPath ?? "")
!checkOfficeAddInInstalled(globalVariables.workspaceUri?.fsPath ?? "") &&
!isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? "")
) {
void popupOfficeAddInDependenciesMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { generateManifestGUID, stopOfficeAddInDebug } from "../../src/officeDevH
import { VsCodeUI } from "../../src/qm/vsc_ui";
import { ExtTelemetry } from "../../src/telemetry/extTelemetry";
import * as localizeUtils from "../../src/utils/localizeUtils";
import * as teamsfxCore from "@microsoft/teamsfx-core";
import * as projectSettingsHelper from "@microsoft/teamsfx-core/build/common/projectSettingsHelper";

describe("officeDevHandler", () => {
const sandbox = sinon.createSandbox();
Expand Down Expand Up @@ -227,6 +229,9 @@ describe("autoOpenOfficeDevProjectHandler", () => {
return Promise.resolve("No" as any);
});
const globalStateUpdateStub = sandbox.stub(globalState, "globalStateUpdate");
const isManifestOnlyOfficeAddinProjectStub = sandbox
.stub(projectSettingsHelper, "isManifestOnlyOfficeAddinProject")
.returns(false);

await officeDevHandlers.autoOpenOfficeDevProjectHandler();

Expand All @@ -248,6 +253,10 @@ describe("autoOpenOfficeDevProjectHandler", () => {
return Promise.resolve(option);
});

const isManifestOnlyOfficeAddinProjectStub = sandbox
.stub(projectSettingsHelper, "isManifestOnlyOfficeAddinProject")
.returns(false);

await officeDevHandlers.autoOpenOfficeDevProjectHandler();

chai.assert(autoInstallDependencyHandlerStub.calledOnce);
Expand Down