Repository: electron-userland/electron-builder
File: packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts (TypeScript)

Code before:
      const windowInstallerPackage = require.resolve("electron-winstaller/package.json")
      vendorDirectory = path.join(path.dirname(windowInstallerPackage), "vendor")
      customSquirrelBin = await getBin(
        "squirrel.windows",
        "https://github.com/electron-userland/electron-builder-binaries/releases/download/squirrel.windows@1.0.0/squirrel.windows-2.0.1-patched.7z",
        "DWijIRRElidu/Rq0yegAKqo2g6aVJUPvcRyvkzUoBPbRasIk61P6xY2fBMdXw6wT17md7NzrTI9/zA1wT9vEqg=="
      )
    }

    const tmpVendorDirectory = await this.packager.info.tempDirManager.createTempDir({ prefix: "squirrel-windows-vendor" })
    await fs.promises.cp(vendorDirectory, tmpVendorDirectory, { recursive: true })
    if (customSquirrelBin && customSquirrelBin.length > 0) {
      await fs.promises.cp(path.join(customSquirrelBin, "electron-winstaller", "vendor"), tmpVendorDirectory, { recursive: true })
    }

    log.debug({ from: vendorDirectory, to: tmpVendorDirectory }, "copied vendor directory")

    const files = await fs.promises.readdir(tmpVendorDirectory)
    for (const file of files) {
      if (file === "Squirrel.exe") {
        const filePath = path.join(tmpVendorDirectory, file)
        log.debug({ file: filePath }, "signing vendor executable")
        await this.packager.sign(filePath)
        break
      }
    }
    return tmpVendorDirectory
  }

  private async generateStubExecutableExe(appOutDir: string, vendorDir: string) {
    const files = await fs.promises.readdir(appOutDir, { withFileTypes: true })
    for (const file of files) {
      const fileNameWithoutExt = path.basename(file.name, ".exe")
      if (path.extname(file.name) === ".exe" && fileNameWithoutExt !== "Squirrel") {
        const filePath = path.join(appOutDir, file.name)
        log.filePath(filePath)
        const stubExePath = path.join(appOutDir, `${fileNameWithoutExt}_ExecutionStub.exe`)
        await fs.promises.copyFile(path.join(vendorDir, "StubExecutable.exe"), stubExePath)
        await execWine(path.join(vendorDir, "WriteZipToSetup.exe"), null, ["--copy-stub-resources", filePath, stubExePath])
        await this.packager.sign(stubExePath)
      }
    }
  }

  async build(appOutDir: string, arch: Arch) {
    const packager = this.packager
    const version = packager.appInfo.version
    const sanitizedName = sanitizeFileName(this.appName)

    const setupFile = packager.expandArtifactNamePattern(this.options, "exe", arch, "${productName} Setup ${version}.${ext}")
    const installerOutDir = path.join(this.outDir, `squirrel-windows${getArchSuffix(arch)}`)

Review comment (bug):
Minor: Can avoid the `for-if-break` approach with a `find`
```
const file = files.find(f => f === "Squirrel.exe")
```
That being said, it looks like we're just trying to sign that one file, right?
```
const filePath = path.join(tmpVendorDirectory, "Squirrel.exe")
if (filePath) { // do we need this check or should Squirrel.exe always be present?
   log.debug({ file: filePath }, "signing vendor executable")
   await this.packager.sign(filePath)
}
```

Code after:
      const windowInstallerPackage = require.resolve("electron-winstaller/package.json")
      const vendorDirectory = path.join(path.dirname(windowInstallerPackage), "vendor")

      const squirrelBin = await getBinFromUrl(
        "squirrel.windows@1.0.0",
        "squirrel.windows-2.0.1-patched.7z",
        "DWijIRRElidu/Rq0yegAKqo2g6aVJUPvcRyvkzUoBPbRasIk61P6xY2fBMdXw6wT17md7NzrTI9/zA1wT9vEqg=="
      )

      await fs.promises.cp(vendorDirectory, tmpVendorDirectory, { recursive: true })
      // copy the patched squirrel to tmp vendor directory
      await fs.promises.cp(path.join(squirrelBin, "electron-winstaller", "vendor"), tmpVendorDirectory, { recursive: true })
    } else {
      // copy the custom squirrel vendor directory to tmp vendor directory
      await fs.promises.cp(customSquirrelVendorDirectory, tmpVendorDirectory, { recursive: true })
    }

    const files = await fs.promises.readdir(tmpVendorDirectory)
    const squirrelExe = files.find(f => f === "Squirrel.exe")
    if (squirrelExe) {
      const filePath = path.join(tmpVendorDirectory, squirrelExe)
      log.debug({ file: filePath }, "signing vendor executable")
      await this.packager.sign(filePath)
    } else {
      log.warn("Squirrel.exe not found in vendor directory, skipping signing")
    }
    return tmpVendorDirectory
  }

  private async generateStubExecutableExe(appOutDir: string, vendorDir: string) {
    const files = await fs.promises.readdir(appOutDir, { withFileTypes: true })
    const appExe = files.find(f => f.name === `${this.exeName}.exe`)
    if (!appExe) {
      throw new Error(`App executable not found in app directory: ${appOutDir}`)
    }

    const filePath = path.join(appOutDir, appExe.name)
    const stubExePath = path.join(appOutDir, `${this.exeName}_ExecutionStub.exe`)
    await fs.promises.copyFile(path.join(vendorDir, "StubExecutable.exe"), stubExePath)
    await execWine(path.join(vendorDir, "WriteZipToSetup.exe"), null, ["--copy-stub-resources", filePath, stubExePath])
    await this.packager.sign(stubExePath)
    log.debug({ file: filePath }, "signing app executable")
    await this.packager.sign(filePath)
  }

  async build(appOutDir: string, arch: Arch) {
    const packager = this.packager
    const version = packager.appInfo.version
    const sanitizedName = sanitizeFileName(this.appName)

    const setupFile = packager.expandArtifactNamePattern(this.options, "exe", arch, "${productName} Setup ${version}.${ext}")