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

Code before:

  await Promise.all([
    doRename(path.join(contentsPath, "MacOS"), electronBranding.productName, appPlist.CFBundleExecutable),
    unlinkIfExists(path.join(appOutDir, "LICENSE")),
    unlinkIfExists(path.join(appOutDir, "LICENSES.chromium.html")),
  ])

  await moveHelpers(
    getAvailableHelperSuffixes(helperEHPlist, helperNPPlist, helperRendererPlist, helperPluginPlist, helperGPUPlist),
    frameworksPath,
    appFilename,
    electronBranding.productName
  )

  if (helperLoginPlist != null) {
    const prefix = electronBranding.productName
    const suffix = " Login Helper"
    const executableBasePath = path.join(loginItemPath, `${prefix}${suffix}.app`, "Contents", "MacOS")
    await doRename(executableBasePath, `${prefix}${suffix}`, appFilename + suffix).then(() => doRename(loginItemPath, `${prefix}${suffix}.app`, `${appFilename}${suffix}.app`))
  }

  const appPath = path.join(appOutDir, `${appInfo.productFilename}.app`)
  await rename(path.dirname(contentsPath), appPath)
  // https://github.com/electron-userland/electron-builder/issues/840
  const now = Date.now() / 1000
  await utimes(appPath, now, now)
}

function configureLocalhostAts(appPlist: any) {
  // https://bencoding.com/2015/07/20/app-transport-security-and-localhost/
  let ats = appPlist.NSAppTransportSecurity
  if (ats == null) {
    ats = {}
    appPlist.NSAppTransportSecurity = ats
  }

  ats.NSAllowsLocalNetworking = true
  // https://github.com/electron-userland/electron-builder/issues/3377#issuecomment-446035814
  ats.NSAllowsArbitraryLoads = true

  let exceptionDomains = ats.NSExceptionDomains
  if (exceptionDomains == null) {
    exceptionDomains = {}
    ats.NSExceptionDomains = exceptionDomains
  }

  if (exceptionDomains.localhost == null) {
    const allowHttp = {
      NSTemporaryExceptionAllowsInsecureHTTPSLoads: false,
      NSIncludesSubdomains: false,
      NSTemporaryExceptionAllowsInsecureHTTPLoads: true,

Review comment (suggestion):
Maybe can just keep the previous logic and then do this?
```
await Promise.all(Object.entries(plistDataToWrite).map(([filename, content] => savePlistFile(filename, content)))
```

Code after:

  if (helperNPPlist != null) {
    await savePlistFile(helperNPPlistFilename, helperNPPlist)
  }

  if (helperRendererPlist != null) {
    await savePlistFile(helperRendererPlistFilename, helperRendererPlist)
  }

  if (helperPluginPlist != null) {
    await savePlistFile(helperPluginPlistFilename, helperPluginPlist)
  }

  if (helperGPUPlist != null) {
    await savePlistFile(helperGPUPlistFilename, helperGPUPlist)
  }

  if (helperLoginPlist != null) {
    await savePlistFile(helperLoginPlistFilename, helperLoginPlist)
  }

  await savePlistFile(appPlistFilename, appPlist)
  if (helperPlist != null) {
    await savePlistFile(helperPlistFilename, helperPlist)
  }

  await Promise.all([
    doRename(path.join(contentsPath, "MacOS"), electronBranding.productName, appPlist.CFBundleExecutable as string),
    unlinkIfExists(path.join(appOutDir, "LICENSE")),
    unlinkIfExists(path.join(appOutDir, "LICENSES.chromium.html")),
  ])

  await moveHelpers(
    getAvailableHelperSuffixes(helperEHPlist, helperNPPlist, helperRendererPlist, helperPluginPlist, helperGPUPlist),
    frameworksPath,
    appFilename,
    electronBranding.productName
  )

  if (helperLoginPlist != null) {
    const prefix = electronBranding.productName
    const suffix = " Login Helper"
    const executableBasePath = path.join(loginItemPath, `${prefix}${suffix}.app`, "Contents", "MacOS")
    await doRename(executableBasePath, `${prefix}${suffix}`, appFilename + suffix).then(() => doRename(loginItemPath, `${prefix}${suffix}.app`, `${appFilename}${suffix}.app`))
  }

  const appPath = path.join(appOutDir, `${appInfo.productFilename}.app`)
  await rename(path.dirname(contentsPath), appPath)
  // https://github.com/electron-userland/electron-builder/issues/840
  const now = Date.now() / 1000
  await utimes(appPath, now, now)