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

Code before:
    if (packages.length === 0) {
      return null
    }
    return { packagePath, packages }
  }

  private async customizeDistributionConfiguration(distInfoFile: string, appPath: string, extraPackages: ExtraPackages | null, arch: Arch) {
    const options = this.options

    // Build requirements plist for productbuild to generate correct hostArchitectures and allowed-os-versions
    // This is the Apple-recommended way to specify architecture and OS requirements
    // See: man productbuild, section "PRE-INSTALL REQUIREMENTS PROPERTY LIST"
    const requirements: Record<string, any> = {}

    // Set architecture based on build target - productbuild will generate correct hostArchitectures in distribution XML
    // On macOS Big Sur+, productbuild defaults to both arm64 and x86_64 unless we specify otherwise
    requirements.arch = archToAppleArchitectures(arch)

    // Set minimum OS version - productbuild will generate allowed-os-versions in distribution XML
    const minimumSystemVersion = this.packager.platformSpecificBuildOptions.minimumSystemVersion
    if (minimumSystemVersion != null) {
      requirements.os = [minimumSystemVersion]
    }

    // Write requirements plist to temp file
    const requirementsPlistFile = path.join(this.outDir, "productbuild-requirements.plist")
    await savePlistFile(requirementsPlistFile, requirements)

    const args = ["--synthesize", "--product", requirementsPlistFile, "--component", appPath]
    if (extraPackages) {
      extraPackages.packages.forEach(pkg => {
        args.push("--package", path.join(extraPackages.packagePath, pkg))
      })
    }
    args.push(distInfoFile)
    await exec("productbuild", args, {
      cwd: this.outDir,
    })

    // Clean up temp plist file
    await unlink(requirementsPlistFile)

    let distInfo = await readFile(distInfoFile, "utf-8")

    if (options.mustClose != null && options.mustClose.length !== 0) {
      const startContent = `    <pkg-ref id="${this.packager.appInfo.id}">\n        <must-close>\n`
      const endContent = "        </must-close>\n    </pkg-ref>\n</installer-gui-script>"
      let mustCloseContent = ""
      options.mustClose.forEach(appId => {
        mustCloseContent += `            <app id="${appId}"/>\n`
      })

Review comment (suggestion):
If possible, I'd like to use the temp file management electron-builder already leverages. It auto-cleans up after build completes
```
const requirementsPlistFile = await this.packager.info.tempDirManager.getTempFile({ suffix: ".plist", prefix: "requirements" })
```

Code after:
    if (packages.length === 0) {
      return null
    }
    return { packagePath, packages }
  }

  private async customizeDistributionConfiguration(distInfoFile: string, appPath: string, extraPackages: ExtraPackages | null, arch: Arch) {
    const options = this.options

    // Build requirements plist for productbuild to generate correct hostArchitectures and allowed-os-versions
    // This is the Apple-recommended way to specify architecture and OS requirements
    // See: man productbuild, section "PRE-INSTALL REQUIREMENTS PROPERTY LIST"
    const requirements: Record<string, any> = {}

    // Set architecture based on build target - productbuild will generate correct hostArchitectures in distribution XML
    // On macOS Big Sur+, productbuild defaults to both arm64 and x86_64 unless we specify otherwise
    requirements.arch = archToAppleArchitectures(arch)

    // Set minimum OS version - productbuild will generate allowed-os-versions in distribution XML
    const minimumSystemVersion = this.packager.platformSpecificBuildOptions.minimumSystemVersion
    if (minimumSystemVersion != null) {
      requirements.os = [minimumSystemVersion]
    }

    const requirementsPlistFile = await this.packager.info.tempDirManager.getTempFile({ suffix: ".plist", prefix: "productbuild-requirements" })
    await savePlistFile(requirementsPlistFile, requirements)

    const args = ["--synthesize", "--product", requirementsPlistFile, "--component", appPath]
    if (extraPackages) {
      extraPackages.packages.forEach(pkg => {
        args.push("--package", path.join(extraPackages.packagePath, pkg))
      })
    }
    args.push(distInfoFile)
    await exec("productbuild", args, {
      cwd: this.outDir,
    })

    let distInfo = await readFile(distInfoFile, "utf-8")

    if (options.mustClose != null && options.mustClose.length !== 0) {
      const startContent = `    <pkg-ref id="${this.packager.appInfo.id}">\n        <must-close>\n`
      const endContent = "        </must-close>\n    </pkg-ref>\n</installer-gui-script>"
      let mustCloseContent = ""
      options.mustClose.forEach(appId => {
        mustCloseContent += `            <app id="${appId}"/>\n`
      })
      distInfo = distInfo.replace("</installer-gui-script>", `${startContent}${mustCloseContent}${endContent}`)
    }

    const insertIndex = distInfo.lastIndexOf("</installer-gui-script>")