Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

5.4 KB
Raw Blame
import { createRequire } from "node:module";
import type { Configuration } from "electron-builder";
import { asarUnpackGlobs, packagedFileGlobs } from "./runtime-dependencies";
import beforePack from "./scripts/before-pack";

const require = createRequire(import.meta.url);

const skipNotarize =
  process.env.SKIP_NOTARIZE === "1" || !process.env.APPLE_TEAM_ID;

// Fork PRs and local builds have no Azure credentials, so they package
// unsigned instead of failing inside Invoke-TrustedSigning.
const signWindowsWithAzure =
  !!process.env.AZURE_TENANT_ID &&
  !!process.env.AZURE_CLIENT_ID &&
  !!process.env.AZURE_CLIENT_SECRET;

// A test build installs beside a release build, so it must not claim the
// release deep-link scheme: the OS would route one of the two builds'
// callbacks to the wrong app.
const isTestChannelBuild = process.env.VITE_POSTHOG_BUILD_CHANNEL === "test";
const deeplinkSchemes = isTestChannelBuild
  ? ["posthog-code-test"]
  : ["posthog-code"];

const config: Configuration = {
  // Original release bundle id; changing it breaks existing installs' data dir and Keychain entries.
  appId: "com.posthog.array",
  productName: "PostHog",
  executableName: "PostHog",

  directories: {
    output: "out",
    buildResources: "build",
  },

  electronVersion: require("electron/package.json").version,
  npmRebuild: false,
  nodeGypRebuild: false,
  generateUpdatesFilesForAllChannels: true,

  // English-only product: drop the ~50 other Electron locales (~50 MB).
  electronLanguages: ["en", "en-US"],

  beforePack,

  files: [
    ".vite/build/**/*",
    ".vite/renderer/**/*",
    "package.json",
    "!node_modules/**/*",
    ...packagedFileGlobs,
    // Sourcemaps are uploaded to PostHog at build time, not consumed in the app.
    "!**/*.map",
    // better-sqlite3 ships its C amalgamation sources; only the built .node runs.
    "!node_modules/better-sqlite3/deps/**",
    "!node_modules/better-sqlite3/src/**",
  ],

  asarUnpack: [
    "**/*.node",
    "**/spawn-helper",
    ".vite/build/claude-cli/**",
    ".vite/build/plugins/posthog/**",
    ".vite/build/codex-acp/**",
    ".vite/build/grammars/**",
    ".vite/build/product-engineer/**",
    ".vite/build/rpc-host.js",
    ".vite/build/rpc-host.js.map",
    ".vite/build/adapters/codex-app-server/local-tools-mcp-server.js",
    ...asarUnpackGlobs,
  ],

  extraResources: [
    { from: "build/app-icon.png", to: "app-icon.png" },
    { from: "build/Assets.car", to: "Assets.car" },
  ],

  protocols: [
    {
      name: "PostHog",
      schemes: deeplinkSchemes,
    },
  ],

  mac: {
    target: ["dmg", "zip"],
    // biome-ignore lint/suspicious/noTemplateCurlyInString: electron-builder interpolation tokens, not JS template literals
    artifactName: "PostHog-Desktop-${version}-${arch}-mac.${ext}",
    icon: "build/app-icon.icns",
    category: "public.app-category.productivity",
    hardenedRuntime: true,
    gatekeeperAssess: false,
    entitlements: "build/entitlements.mac.plist",
    entitlementsInherit: "build/entitlements.mac.inherit.plist",
    extendInfo: {
      CFBundleIconName: "Icon",
      // Shown in the macOS microphone-permission prompt when a user records a
      // custom notification sound.
      NSMicrophoneUsageDescription:
        "PostHog uses the microphone to record custom notification sounds.",
    },
    notarize: !skipNotarize,
  },

  dmg: {
    format: "ULFO",
    size: "4g",
    background: "build/dmg-background.png",
    icon: "build/app-icon.icns",
    iconSize: 80,
    window: { width: 560, height: 380 },
    contents: [
      { x: 104, y: 55, type: "file" },
      { x: 104, y: 243, type: "link", path: "/Applications" },
    ],
  },

  win: {
    target: ["nsis"],
    // biome-ignore lint/suspicious/noTemplateCurlyInString: electron-builder interpolation tokens, not JS template literals
    artifactName: "PostHog-Desktop-${version}-${arch}-win.${ext}",
    // electron-builder generates the multi-size .ico from this 1024px PNG; a real
    // .ico must be >=256px and the committed app-icon.ico is only 32px.
    icon: "build/app-icon.png",
    ...(signWindowsWithAzure
      ? {
          azureSignOptions: {
            // electron-updater compares this against the certificate subject
            // before installing an update, so it must match the Azure
            // certificate profile exactly.
            publisherName:
              "CN=PostHog Inc., O=PostHog Inc., L=San Francisco, S=California, C=US",
            endpoint: "https://wus2.codesigning.azure.net",
            codeSigningAccountName: "posthog-desktop",
            certificateProfileName: "posthog-desktop-public",
          },
        }
      : {}),
  },

  nsis: {
    oneClick: false,
    deleteAppDataOnUninstall: false,
  },

  linux: {
    target: ["AppImage", "deb", "rpm"],
    // biome-ignore lint/suspicious/noTemplateCurlyInString: electron-builder interpolation tokens, not JS template literals
    artifactName: "PostHog-Desktop-${version}-${arch}-linux.${ext}",
    icon: "build/app-icon.png",
    category: "Development",
    mimeTypes: ["x-scheme-handler/posthog-code"],
  },

  deb: {
    packageName: "posthog-code",
    maintainer: "PostHog <[email protected]>",
    packageCategory: "devel",
  },

  rpm: {
    packageName: "posthog-code",
  },

  // Installs built from this config poll the CloudFront-fronted update feed
  // (the S3 bucket is private; reads go through the CDN).
  publish: {
    provider: "generic",
    url: "https://desktop-releases.posthog.com/stable",
  },
};

export default config;