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

feat(appx): Update identityName for windows 10 #8206

Merged
merged 16 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>.</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 @@
"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 @@
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

Check warning on line 229 in packages/app-builder-lib/src/targets/AppxTarget.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Replace `↹↹··let·result:` with `··········let·result:·`

Check warning on line 229 in packages/app-builder-lib/src/targets/AppxTarget.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Replace `↹↹··let·result:` with `··········let·result:·`
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(), "")

Check warning on line 233 in packages/app-builder-lib/src/targets/AppxTarget.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Replace `+` with `·+·`

Check warning on line 233 in packages/app-builder-lib/src/targets/AppxTarget.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Replace `+` with `·+·`
} 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 Application.Id can not be some values`
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
Loading