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

Code before:
export default class SquirrelWindowsTarget extends Target {
  //tslint:disable-next-line:no-object-literal-type-assertion
  readonly options: SquirrelWindowsOptions = { ...this.packager.platformSpecificBuildOptions, ...this.packager.config.squirrelWindows } as SquirrelWindowsOptions

  isAsyncSupported = false

  constructor(
    private readonly packager: WinPackager,
    readonly outDir: string
  ) {
    super("squirrel")
  }

  private async prepareSignedVendorDirectory(): Promise<string> {
    const customSquirrelVendorDirectory = this.options.customSquirrelVendorDir
    const tmpVendorDirectory = await this.packager.info.tempDirManager.createTempDir({ prefix: "squirrel-windows-vendor" })

    if (isEmptyOrSpaces(customSquirrelVendorDirectory) || !fs.existsSync(customSquirrelVendorDirectory)) {
      log.warn({ customSquirrelVendorDirectory: customSquirrelVendorDirectory }, "unable to access custom Squirrel.Windows vendor directory, falling back to default vendor ")
      const windowInstallerPackage = require.resolve("electron-winstaller/package.json")
      const vendorDirectory = path.join(path.dirname(windowInstallerPackage), "vendor")

      const squirrelBin = 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=="
      )

      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.appName}.exe`)

Review comment (suggestion):
From some recent code changes, I think this should now be able to be simplified to
```
getBinFromUrl("squirrel.windows@1.0.0", "squirrel.windows-2.0.1-patched.7z", hash)
```

Code after:
export default class SquirrelWindowsTarget extends Target {
  //tslint:disable-next-line:no-object-literal-type-assertion
  readonly options: SquirrelWindowsOptions = { ...this.packager.platformSpecificBuildOptions, ...this.packager.config.squirrelWindows } as SquirrelWindowsOptions

  isAsyncSupported = false

  constructor(
    private readonly packager: WinPackager,
    readonly outDir: string
  ) {
    super("squirrel")
  }

  private async prepareSignedVendorDirectory(): Promise<string> {
    const customSquirrelVendorDirectory = this.options.customSquirrelVendorDir
    const tmpVendorDirectory = await this.packager.info.tempDirManager.createTempDir({ prefix: "squirrel-windows-vendor" })

    if (isEmptyOrSpaces(customSquirrelVendorDirectory) || !fs.existsSync(customSquirrelVendorDirectory)) {
      log.warn({ customSquirrelVendorDirectory: customSquirrelVendorDirectory }, "unable to access custom Squirrel.Windows vendor directory, falling back to default vendor ")
      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`)