mirror of
https://github.com/stablyai/orca.git
synced 2026-09-21 16:02:20 +00:00
fix(release): restore the minified telemetry constant fallback
The macOS, Windows, and both Linux release builds all failed on "Verify
telemetry constants present in app.asar", blocking publish-release:
::error::BUILD_IDENTITY constant missing or unexpected value in
dist/mac-arm64/Orca.app/Contents/Resources/app.asar
The verifier printed no context sample, because the string
`BUILD_IDENTITY` does not occur anywhere in the shipped bundle at all.
#17527 added `minify: 'oxc'` to the main bundle, so oxc renames the
module-local `const BUILD_IDENTITY` to a short identifier.
`BUILD_IDENTITY_RE` keys off the literal name and therefore cannot match a
production bundle. `MINIFIED_TELEMETRY_RE` matches the adjacent injected
identity/key pair instead, which survives renaming.
#11019 created these patterns without that fallback, and its own comment
predicted this exact failure if minification were ever enabled on the main
bundle. The fallback was written on the v1.4.197 release branch in
35f1b0ebb9 and never merged back to main, so main has never been able to
verify a minified bundle.
Verified against a real local bundle built with the release env vars
(ORCA_BUILD_IDENTITY=stable, ORCA_POSTHOG_WRITE_KEY=phc_...): the bundle
does not contain "BUILD_IDENTITY"; both the narrowed and the widened
BUILD_IDENTITY_RE fail; MINIFIED_TELEMETRY_RE matches and recovers
identity=stable plus the write key.
(cherry picked from commit 39c3e44cd1)
This commit is contained in:
@@ -1,2 +1,6 @@
|
||||
export const BUILD_IDENTITY_RE = /\b(?:const|let|var)\s+BUILD_IDENTITY\s*=\s*"(rc|stable)"/
|
||||
export const WRITE_KEY_RE = /\b(?:const|let|var)\s+WRITE_KEY\s*=\s*"(phc_[A-Za-z0-9_-]+)"/
|
||||
// The unminified bundle keeps these names. Production minification may rename
|
||||
// them, but the injected identity and key remain adjacent in the declaration.
|
||||
export const BUILD_IDENTITY_RE = /\b(?:const|let|var)\s+BUILD_IDENTITY\s*=\s*["`](rc|stable)["`]/
|
||||
export const WRITE_KEY_RE = /\b(?:const|let|var)\s+WRITE_KEY\s*=\s*["`](phc_[A-Za-z0-9_-]+)["`]/
|
||||
export const MINIFIED_TELEMETRY_RE =
|
||||
/\b(?:const|let|var)\s+[$\w]+\s*=\s*["'`](rc|stable)["'`][\s\S]{0,200}?[,$]\s*[$\w]+\s*=\s*["'`](phc_[A-Za-z0-9_-]+)["'`]/
|
||||
|
||||
@@ -38,7 +38,11 @@ import { join, resolve } from 'node:path'
|
||||
// `node_modules`). If electron-builder ever drops it, promote this to a
|
||||
// direct devDependency in package.json.
|
||||
import { extractFile, listPackage } from '@electron/asar'
|
||||
import { BUILD_IDENTITY_RE, WRITE_KEY_RE } from './telemetry-bundle-constant-patterns.mjs'
|
||||
import {
|
||||
BUILD_IDENTITY_RE,
|
||||
MINIFIED_TELEMETRY_RE,
|
||||
WRITE_KEY_RE
|
||||
} from './telemetry-bundle-constant-patterns.mjs'
|
||||
|
||||
// Why resolve from import.meta.url instead of cwd: a release runner (or a
|
||||
// developer debugging locally) may invoke this script from a non-root cwd.
|
||||
@@ -156,8 +160,14 @@ function verifyAsar(asarPath) {
|
||||
|
||||
const buildIdentityMatch = BUILD_IDENTITY_RE.exec(indexJs)
|
||||
const writeKeyMatch = WRITE_KEY_RE.exec(indexJs)
|
||||
const minifiedTelemetryMatch = MINIFIED_TELEMETRY_RE.exec(indexJs)
|
||||
|
||||
if (!buildIdentityMatch) {
|
||||
// Rolldown renames module-local constants in production output. In that
|
||||
// form, verify the adjacent injected identity/key declaration instead.
|
||||
const verifiedIdentity = buildIdentityMatch?.[1] ?? minifiedTelemetryMatch?.[1]
|
||||
const verifiedWriteKey = writeKeyMatch?.[1] ?? minifiedTelemetryMatch?.[2]
|
||||
|
||||
if (!verifiedIdentity) {
|
||||
console.error(`::error::BUILD_IDENTITY constant missing or unexpected value in ${asarPath}`)
|
||||
const sample = indexJs.match(/.{0,80}BUILD_IDENTITY.{0,80}/g)?.slice(0, 5) ?? []
|
||||
for (const line of sample) {
|
||||
@@ -165,7 +175,7 @@ function verifyAsar(asarPath) {
|
||||
}
|
||||
return null
|
||||
}
|
||||
if (!writeKeyMatch) {
|
||||
if (!verifiedWriteKey) {
|
||||
console.error(`::error::PostHog WRITE_KEY missing from ${asarPath}`)
|
||||
const sample = indexJs.match(/.{0,80}WRITE_KEY.{0,80}/g)?.slice(0, 5) ?? []
|
||||
for (const line of sample) {
|
||||
@@ -174,7 +184,7 @@ function verifyAsar(asarPath) {
|
||||
return null
|
||||
}
|
||||
|
||||
return { asarPath, buildIdentity: buildIdentityMatch[1], writeKey: writeKeyMatch[1] }
|
||||
return { asarPath, buildIdentity: verifiedIdentity, writeKey: verifiedWriteKey }
|
||||
}
|
||||
|
||||
// Why verify every match (not just the first): macOS dual-arch produces one
|
||||
|
||||
Reference in New Issue
Block a user