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

Code before:
    if (isEmptyOrSpaces(vendorDirectory) || !fs.existsSync(vendorDirectory)) {
      log.warn({ vendorDirectory }, "unable to access custom Squirrel.Windows vendor directory, falling back to default vendor ")
      vendorDirectory = path.resolve(__dirname, "..", "vendor")
    }

    const tmpVendorDirectory = await this.packager.info.tempDirManager.createTempDir({ prefix: "squirrel-windows-vendor" })
    // Copy entire vendor directory to temp directory
    await fs.promises.cp(vendorDirectory, 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) {
      if (file.isFile() && file.name.toLocaleLowerCase().endsWith(".exe") && file.name.toLocaleLowerCase() !== "squirrel.exe") {
        const filePath = path.join(appOutDir, file.name)
        log.debug({ file: filePath }, "generating stub executable for exe")
        const fileNameWithoutExt = file.name.slice(0, -4)
        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)}`)
    const artifactPath = path.join(installerOutDir, setupFile)
    const msiArtifactPath = path.join(installerOutDir, packager.expandArtifactNamePattern(this.options, "msi", arch, "${productName} Setup ${version}.${ext}"))

    await packager.info.emitArtifactBuildStarted({
      targetPresentableName: "Squirrel.Windows",
      file: artifactPath,
      arch,

Review comment (suggestion):
Maybe we can use `path` package for comparisons?
```
path.extname(file.name) === ".exe" && path.basename(file.name, "exe") !== "Squirrel"
```

Code after:

  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`)
    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)
  }