Skip to content

Commit

Permalink
feat(appx): Update identityName for windows 10 (#8206)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifurther authored Jun 8, 2024
1 parent 140e2f0 commit 51111a8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-bags-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

feat(appx): Update identityName for windows 10
2 changes: 1 addition & 1 deletion docs/configuration/appx.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All options are optional. All required for AppX configuration is inferred and co

<!-- do not edit. start of generated block -->
<ul>
<li><code id="AppXOptions-applicationId">applicationId</code> String - The application id. Defaults to <code>identityName</code>. Can’t start with numbers.</li>
<li><code id="AppXOptions-applicationId">applicationId</code> String - The application id. Defaults to <code>identityName</code>. This string contains alpha-numeric fields separated by periods. Each field must begin with an ASCII alphabetic character.</li>
<li><code id="AppXOptions-backgroundColor">backgroundColor</code> = <code>#464646</code> String | “undefined” - The background color of the app tile. See <a href="https://msdn.microsoft.com/en-us/library/windows/apps/br211471.aspx">Visual Elements</a>.</li>
<li><code id="AppXOptions-displayName">displayName</code> String | “undefined” - A friendly name that can be displayed to users. Corresponds to <a href="https://msdn.microsoft.com/en-us/library/windows/apps/br211432.aspx">Properties.DisplayName</a>. Defaults to the application product name.</li>
<li><code id="AppXOptions-identityName">identityName</code> String | “undefined” - The name. Corresponds to <a href="https://msdn.microsoft.com/en-us/library/windows/apps/br211441.aspx">Identity.Name</a>. Defaults to the <a href="/configuration/configuration#Metadata-name">application name</a>.</li>
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"type": "boolean"
},
"applicationId": {
"description": "The application id. Defaults to `identityName`. Can’t start with numbers.",
"description": "The application id. Defaults to `identityName`. This string contains alpha-numeric fields separated by periods. Each field must begin with an ASCII alphabetic character.",
"type": "string"
},
"artifactName": {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/options/AppXOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TargetSpecificOptions } from "../core"

export interface AppXOptions extends TargetSpecificOptions {
/**
* The application id. Defaults to `identityName`. Can’t start with numbers.
* The application id. Defaults to `identityName`. This string contains alpha-numeric fields separated by periods. Each field must begin with an ASCII alphabetic character.
*/
readonly applicationId?: string

Expand Down
77 changes: 70 additions & 7 deletions packages/app-builder-lib/src/targets/AppxTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ const vendorAssetsForDefaultAssets: { [key: string]: string } = {
"Wide310x150Logo.png": "SampleAppx.310x150.png",
}

const restrictedApplicationIdValues = [
"CON",
"PRN",
"AUX",
"NUL",
"COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
"LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9",
]

const DEFAULT_RESOURCE_LANG = "en-US"

export default class AppXTarget extends Target {
Expand Down Expand Up @@ -199,19 +224,57 @@ export default class AppXTarget extends Target {
return appInfo.getVersionInWeirdWindowsForm(options.setBuildNumber === true)

case "applicationId": {
const result = options.applicationId || options.identityName || appInfo.name
if (!isNaN(parseInt(result[0], 10))) {
let message = `AppX Application.Id can’t start with numbers: "${result}"`
if (options.applicationId == null) {
message += `\nPlease set appx.applicationId (or correct appx.identityName or name)`
const validCharactersRegex = /^([A-Za-z][A-Za-z0-9]*)(\.[A-Za-z][A-Za-z0-9]*)*$/
const identitynumber = parseInt(options.identityName as string, 10) || NaN
let result: string
if (!isNaN(identitynumber) && options.identityName !== null && options.identityName !== undefined) {
if (options.identityName[0] === "0") {
log.warn(`Remove the 0${identitynumber}`)
result = options.identityName.replace("0" + identitynumber.toString(), "")
} else {
log.warn(`Remove the ${identitynumber}`)
result = options.identityName.replace(identitynumber.toString(), "")
}
} else {
result = options.applicationId || options.identityName || appInfo.name
}

if (result.length < 1 || result.length > 64) {
const message = `Appx Application.Id with a value between 1 and 64 characters in length`
throw new InvalidConfigurationError(message)
} else if (!validCharactersRegex.test(result)) {
const message = `AppX Application.Id can not be consists of alpha-numeric and period"`
throw new InvalidConfigurationError(message)
} else if (restrictedApplicationIdValues.includes(result.toUpperCase())) {
const message = `AppX identityName.Id can not include restricted values: ${JSON.stringify(restrictedApplicationIdValues)}`
throw new InvalidConfigurationError(message)
} else if (result == null && options.applicationId == null) {
const message = `Please set appx.applicationId (or correct appx.identityName or name)`
throw new InvalidConfigurationError(message)
}

return result
}

case "identityName":
return options.identityName || appInfo.name
case "identityName": {
const result = options.identityName || appInfo.name
const validCharactersRegex = /^[a-zA-Z0-9.-]+$/
if (result.length < 3 || result.length > 50) {
const message = `Appx identityName.Id with a value between 3 and 50 characters in length`
throw new InvalidConfigurationError(message)
} else if (!validCharactersRegex.test(result)) {
const message = `AppX identityName.Id cat be consists of alpha-numeric, period, and dash characters"`
throw new InvalidConfigurationError(message)
} else if (restrictedApplicationIdValues.includes(result.toUpperCase())) {
const message = `AppX identityName.Id can not be some values`
throw new InvalidConfigurationError(message)
} else if (result == null && options.identityName == null) {
const message = `Please set appx.identityName or name`
throw new InvalidConfigurationError(message)
}

return result
}

case "executable":
return executable
Expand Down
18 changes: 18 additions & 0 deletions test/src/windows/appxTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ it.ifDevOrWinCi(
)
)

// use identityName and same setting for applicationId
it.ifDevOrWinCi(
"application id",
app(
{
targets: Platform.WINDOWS.createTarget(["appx"], Arch.x64),
config: {
cscLink: protectedCscLink,
cscKeyPassword: "test",
appx: {
identityName: "01234Test.ApplicationDataSample",
},
},
},
{}
)
)

const it2 = isEnvTrue(process.env.DO_APPX_CERT_STORE_AWARE_TEST) ? test : test.skip
it2.ifNotCi(
"certificateSubjectName",
Expand Down

0 comments on commit 51111a8

Please sign in to comment.