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

Code before:

    if (!this.isPortable) {
      logFields.oneClick = oneClick
      logFields.perMachine = isPerMachine
    }

    await packager.info.emitArtifactBuildStarted(
      {
        targetPresentableName: this.name,
        file: installerPath,
        arch: primaryArch,
      },
      logFields
    )

    const guid = options.guid || UUID.v5(appInfo.id, ELECTRON_BUILDER_NS_UUID)
    const uninstallAppKey = guid.replace(/\\/g, " - ")
    const defines: Defines = {
      APP_ID: appInfo.id,
      APP_GUID: guid,
      // Windows bug - entry in Software\Microsoft\Windows\CurrentVersion\Uninstall cannot have \ symbols (dir)
      UNINSTALL_APP_KEY: uninstallAppKey,
      UNINSTALL_URL_HELP: options.uninstallUrlHelp || this.packager.info.metadata.homepage || undefined,
      UNINSTALL_URL_INFO_ABOUT: options.uninstallUrlInfoAbout || this.packager.info.metadata.homepage || undefined,
      UNINSTALL_URL_UPDATE_INFO: options.uninstallUrlUpdateInfo || this.packager.info.metadata.homepage || undefined,
      UNINSTALL_URL_README: options.uninstallUrlReadme || this.packager.info.metadata.homepage || undefined,
      PRODUCT_NAME: appInfo.productName,
      PRODUCT_FILENAME: appInfo.productFilename,
      APP_FILENAME: getWindowsInstallationDirName(appInfo, !oneClick || isPerMachine),
      APP_DESCRIPTION: appInfo.description,
      VERSION: appInfo.version,

      PROJECT_DIR: packager.projectDir,
      BUILD_RESOURCES_DIR: packager.info.buildResourcesDir,

      APP_PACKAGE_NAME: getWindowsInstallationAppPackageName(appInfo.name),
    }
    if (options.customNsisBinary?.debugLogging) {
      defines.ENABLE_LOGGING_ELECTRON_BUILDER = null
    }
    if (uninstallAppKey !== guid) {
      defines.UNINSTALL_REGISTRY_KEY_2 = `Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${guid}`
    }

    const commands: Commands = {
      OutFile: `"${installerPath}"`,
      VIProductVersion: appInfo.getVersionInWeirdWindowsForm(),
      VIAddVersionKey: this.computeVersionKey(),
      Unicode: this.isUnicodeEnabled,
    }


Review comment (suggestion):
I think `undefined` may have unexpected side effects. Note: `defines.ENABLE_LOGGING_ELECTRON_BUILDER = null` where `null` is used as a flag (I guess implicitly represents a boolean in the nsis scripts?)

Easy way around this - only set the defines var when provided a value
```
const { homepage } = this.packager.info.metadata
// `use` from builder-util IIRC
use(options.uninstallUrlHelp || homepage, (it) => defines.UNINSTALL_URL_HELP = it)
use(options.uninstallUrlInfoAbout || homepage, (it) => defines.UNINSTALL_URL_INFO_ABOUT = it)
use(options.uninstallUrlUpdateInfo || homepage, (it) => defines.UNINSTALL_URL_UPDATE_INFO = it)
use(options.uninstallUrlReadme || homepage, (it) => defines.UNINSTALL_URL_README = it)
```

Code after:

    if (!this.isPortable) {
      logFields.oneClick = oneClick
      logFields.perMachine = isPerMachine
    }

    await packager.info.emitArtifactBuildStarted(
      {
        targetPresentableName: this.name,
        file: installerPath,
        arch: primaryArch,
      },
      logFields
    )

    const guid = options.guid || UUID.v5(appInfo.id, ELECTRON_BUILDER_NS_UUID)
    const uninstallAppKey = guid.replace(/\\/g, " - ")
    const defines: Defines = {
      APP_ID: appInfo.id,
      APP_GUID: guid,
      // Windows bug - entry in Software\Microsoft\Windows\CurrentVersion\Uninstall cannot have \ symbols (dir)
      UNINSTALL_APP_KEY: uninstallAppKey,
      PRODUCT_NAME: appInfo.productName,
      PRODUCT_FILENAME: appInfo.productFilename,
      APP_FILENAME: getWindowsInstallationDirName(appInfo, !oneClick || isPerMachine),
      APP_DESCRIPTION: appInfo.description,
      VERSION: appInfo.version,

      PROJECT_DIR: packager.projectDir,
      BUILD_RESOURCES_DIR: packager.info.buildResourcesDir,

      APP_PACKAGE_NAME: getWindowsInstallationAppPackageName(appInfo.name),
    }
    if (options.customNsisBinary?.debugLogging) {
      defines.ENABLE_LOGGING_ELECTRON_BUILDER = null
    }
    if (uninstallAppKey !== guid) {
      defines.UNINSTALL_REGISTRY_KEY_2 = `Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${guid}`
    }

    const { homepage } = this.packager.info.metadata
    use(options.uninstallUrlHelp || homepage, it => (defines.UNINSTALL_URL_HELP = it))
    use(options.uninstallUrlInfoAbout || homepage, it => (defines.UNINSTALL_URL_INFO_ABOUT = it))
    use(options.uninstallUrlUpdateInfo || homepage, it => (defines.UNINSTALL_URL_UPDATE_INFO = it))
    use(options.uninstallUrlReadme || homepage, it => (defines.UNINSTALL_URL_README = it))

    const commands: Commands = {
      OutFile: `"${installerPath}"`,
      VIProductVersion: appInfo.getVersionInWeirdWindowsForm(),
      VIAddVersionKey: this.computeVersionKey(),
      Unicode: this.isUnicodeEnabled,