Repository: electron-userland/electron-builder
File: packages/app-builder-lib/src/targets/AppxTarget.ts (TypeScript)

Code before:

        default:
          throw new Error(`Macro ${p1} is not defined`)
      }
    })
    await writeFile(outFile, manifest)
  }

  private getCapabilities(): string {
    const caps = asArray(this.options.capabilities)
    if(caps.indexOf("runFullTrust") < 0)
      caps.push("runFullTrust");

    let capabilities = "<Capabilities>"
    for(const cap of CAPABILITIES)
    {
      if(caps.indexOf(cap.name)>=0)
        capabilities += "\n  " + cap.toXMLString();
    }
    capabilities += "\n</Capabilities>";
    return capabilities
  }

  private async getExtensions(executable: string, displayName: string): Promise<string> {
    const uriSchemes = asArray(this.packager.config.protocols).concat(asArray(this.packager.platformSpecificBuildOptions.protocols))

    const fileAssociations = asArray(this.packager.config.fileAssociations).concat(asArray(this.packager.platformSpecificBuildOptions.fileAssociations))

    let isAddAutoLaunchExtension = this.options.addAutoLaunchExtension
    if (isAddAutoLaunchExtension === undefined) {
      const deps = this.packager.info.metadata.dependencies
      isAddAutoLaunchExtension = deps != null && deps["electron-winstore-auto-launch"] != null
    }

    if (!isAddAutoLaunchExtension && uriSchemes.length === 0 && fileAssociations.length === 0 && this.options.customExtensionsPath === undefined) {
      return ""
    }

    let extensions = "<Extensions>"

    if (isAddAutoLaunchExtension) {
      extensions += `
        <desktop:Extension Category="windows.startupTask" Executable="${executable}" EntryPoint="Windows.FullTrustApplication">
          <desktop:StartupTask TaskId="SlackStartup" Enabled="true" DisplayName="${displayName}" />
        </desktop:Extension>`
    }

    for (const protocol of uriSchemes) {
      for (const scheme of asArray(protocol.schemes)) {
        extensions += `
          <uap:Extension Category="windows.protocol">

Review comment (performance):
This isn't an optimized flow and can be simplified / made more performant.
```
export function getCapabilitiesXML(): string {
  const caps = asArray(this.options.capabilities) 
  
  // Ensure runFullTrust is always included
  const capSet = new Set(caps);
  capSet.add("runFullTrust");
  
  // Filter and map in one pass
  const capabilityStrings = CAPABILITIES
    .filter(cap => capSet.has(cap.name))
    .map(cap => `  ${cap.toXMLString()}`);
  
  return `<Capabilities>\n${capabilityStrings.join('\n')}\n</Capabilities>`;
}
```

Key optimizations:

- Set instead of array - `capSet.has(cap.name)` is O(1) vs `caps.indexOf(cap.name)` which is O(n)
- Single pass - Combined filter and map with chaining instead of building `string` in loop
- Template literal - Cleaner string construction with `join()`
- Flexible input - Handles both string array and single string (matching asArray pattern)
- Immutable - Doesn't modify input array, creates new `Set`

Code after:

        default:
          throw new Error(`Macro ${p1} is not defined`)
      }
    })
    await writeFile(outFile, manifest)
  }

  private getCapabilities(): string {
    const caps = asArray(this.options.capabilities)

    const capSet = new Set(caps)

    const invalid = Array.from(capSet).filter(cap => !isValidCapabilityName(cap))
    if (invalid.length > 0) {
      throw new Error(`invalid windows capabilit${invalid.length === 1 ? "y" : "ies"} specified: ${invalid.join(", ")}`)
    }

    // Ensure runFullTrust is always included
    capSet.add("runFullTrust")

    // Filter and map in one pass
    const capabilityStrings = CAPABILITIES.filter(cap => capSet.has(cap.name)).map(cap => `  ${cap.toXMLString()}`)

    return `<Capabilities>\n${capabilityStrings.join("\n")}\n</Capabilities>`
  }

  private async getExtensions(executable: string, displayName: string): Promise<string> {
    const uriSchemes = asArray(this.packager.config.protocols).concat(asArray(this.packager.platformSpecificBuildOptions.protocols))

    const fileAssociations = asArray(this.packager.config.fileAssociations).concat(asArray(this.packager.platformSpecificBuildOptions.fileAssociations))

    let isAddAutoLaunchExtension = this.options.addAutoLaunchExtension
    if (isAddAutoLaunchExtension === undefined) {
      const deps = this.packager.info.metadata.dependencies
      isAddAutoLaunchExtension = deps != null && deps["electron-winstore-auto-launch"] != null
    }

    if (!isAddAutoLaunchExtension && uriSchemes.length === 0 && fileAssociations.length === 0 && this.options.customExtensionsPath === undefined) {
      return ""
    }

    let extensions = "<Extensions>"

    if (isAddAutoLaunchExtension) {
      extensions += `
        <desktop:Extension Category="windows.startupTask" Executable="${executable}" EntryPoint="Windows.FullTrustApplication">
          <desktop:StartupTask TaskId="SlackStartup" Enabled="true" DisplayName="${displayName}" />
        </desktop:Extension>`
    }