Skip to content

Commit

Permalink
fix: truncate app name to avoid import spfx failure (#10210)
Browse files Browse the repository at this point in the history
* fix: truncate app name to avoid import spfx failure

* test: fix ut fail

* refactor: remove unused strings

* test: fix ut coverage fail
  • Loading branch information
HuihuiWu-Microsoft authored Oct 27, 2023
1 parent 84a3752 commit c9c564e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
2 changes: 0 additions & 2 deletions packages/fx-core/resource/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"core.deploy.botTroubleShoot.learnMore": "Learn more",
"core.option.deploy": "Deploy",
"core.option.confirm": "Confirm",
"core.option.cancel": "Cancel",
"core.option.learnMore": "Learn more",
"core.option.upgrade": "Upgrade",
"core.option.moreInfo": "More Info",
Expand All @@ -27,7 +26,6 @@
"core.progress.configureAzureStorage": "Configuring Azure Storage, enable static website setting.",
"core.progress.runCommand": "Run command %s at %s",
"core.progress.deployToAzure": "Deploying %s to %s.",
"core.Notification.ReadMore": "Read more",
"core.migrationV3.confirmOnly.Message": "Please confirm the upgrade",
"core.migrationV3.Message": "Upgrade your Teams Toolkit project to stay compatible with the latest version. A backup directory will be created along with an Upgrade Summary.",
"core.migrationV3.VS.Message": "Upgrade your solution to stay compatible with the latest Teams Toolkit version. A backup directory will be generated in which it contains an upgrade report.",
Expand Down
15 changes: 15 additions & 0 deletions packages/fx-core/src/component/generator/spfx/spfxGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,21 @@ export class SPFxGenerator {

remoteManifest = existingManifest;
}

// Truncate manifest app name if exceed limitation
if (localManifest.name.short.length > Constants.TEAMS_APP_NAME_MAX_LENGTH) {
localManifest.name.short = localManifest.name.short.substring(
0,
Constants.TEAMS_APP_NAME_MAX_LENGTH
);
}
if (remoteManifest.name.short.length > Constants.TEAMS_APP_NAME_MAX_LENGTH) {
remoteManifest.name.short = remoteManifest.name.short.substring(
0,
Constants.TEAMS_APP_NAME_MAX_LENGTH
);
}

importDetails.push(`(.) Processing: Writing to save changes to manifest.local.json...`);
await manifestUtils._writeAppManifest(
localManifest,
Expand Down
17 changes: 1 addition & 16 deletions packages/fx-core/src/component/generator/spfx/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,8 @@ import { getLocalizedString } from "../../../../common/localizeUtils";

// Licensed under the MIT license.
export class Constants {
public static readonly FRAMEWORK_NONE = "none";
public static readonly FRAMEWORK_REACT = "react";
public static readonly MAX_ALIAS_LENGTH = 40;
public static readonly MAX_BUNDLE_NAME_LENGTH = 64;
public static readonly CALLED_ID = "teamsdev";
public static readonly APP_CATALOG_REFRESH_TIME = 20000;
public static readonly APP_CATALOG_MAX_TIMES = 6;
public static readonly APP_CATALOG_ACTIVE_TIME = 180000;
public static readonly PLUGIN_NAME = "SPFx";
public static readonly PLUGIN_DEV_NAME = "fx-resource-spfx";
public static readonly BUILD_SHAREPOINT_PACKAGE = "Build SharePoint Package";
public static readonly READ_MORE = getLocalizedString("core.Notification.ReadMore");
public static readonly CANCEL = getLocalizedString("core.option.cancel");
public static readonly DEPLOY_GUIDE =
"https://docs.microsoft.com/en-us/microsoftteams/platform/get-started/first-app-spfx?tabs=vscode#deploy-your-app-to-sharepoint";
public static readonly CREATE_APP_CATALOG_GUIDE =
"https://docs.microsoft.com/en-us/sharepoint/use-app-catalog#create-the-app-catalog";
public static readonly SPFX_HELP_LINK = "https://aka.ms/teamsfx-spfx-help";
public static readonly SetUpDevEnvironmentHelpLink =
"https://aka.ms/teamsfx-spfx-dev-environment-setup";
public static readonly TEMPLATE_NAME = "spfx-tab";
Expand All @@ -36,6 +20,7 @@ export class Constants {
"https://developer.microsoft.com/en-us/microsoft-365/dev-program";
public static readonly YO_RC_SOLUTION_NAME = "solutionName";
public static readonly IMPORT_HELP_LINK = "https://aka.ms/teamsfx-spfx-help-v5";
public static readonly TEAMS_APP_NAME_MAX_LENGTH = 30;
}

export class TelemetryKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ describe("SPFxGenerator", function () {
"https://developer.microsoft.com/en-us/json-schemas/teams/v1.16/MicrosoftTeams.schema.json",
manifestVersion: "1.16",
id: "fakedId",
name: {
short: "thisisaverylongappnametotestifitwillbetruncated",
},
icons: {
color: "color.png",
outline: "outline.png",
Expand Down Expand Up @@ -530,7 +533,10 @@ describe("SPFxGenerator", function () {
const generateTemplateStub = sinon
.stub(Generator, "generateTemplate" as any)
.resolves(ok(undefined));
const fakedManifest = { staticTabs: [{ name: "default" }] };
const fakedManifest = {
name: { short: "thisisaverylongappnametotestifitwillbetruncated" },
staticTabs: [{ name: "default" }],
};
const readAppManifestStub = sinon
.stub(ManifestUtils.prototype, "_readAppManifest")
.resolves(ok(fakedManifest as any));
Expand Down

0 comments on commit c9c564e

Please sign in to comment.