posthog-react-native 4.66.3 → 4.67.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,17 +98,17 @@ plugins.withId('com.android.application') {
98
98
  }
99
99
 
100
100
  // How the release a build belongs to gets associated with the exceptions
101
- // it reports. `symbol-set` (the default) stamps the release onto the
102
- // uploaded source maps; `event` uploads them release-independent and lets
103
- // each event resolve its own release from the $app_namespace /
104
- // $app_version / $app_build the SDK already sends, which the release
105
- // coordinates below are built from. Passed only outside the default mode,
106
- // so a symbol-set build keeps working against a posthog-cli predating the
107
- // flag.
101
+ // it reports. `event` (the default) uploads the source maps
102
+ // release-independent and lets each event resolve its own release from the
103
+ // $app_namespace / $app_version / $app_build the SDK already sends, which
104
+ // the release coordinates below are built from. `symbol-set` stamps the
105
+ // release onto the uploaded maps instead. The --release-mode flag itself is
106
+ // resolved per exec in PostHogCli.releaseModeArgs, where an old posthog-cli
107
+ // fails an explicit mode but only softens the implicit default.
108
108
  def posthogReleaseMode = resolvePostHogReleaseMode(project)
109
- def posthogReleaseModeArgs = []
110
- if (posthogReleaseMode != null && posthogReleaseMode != "symbol-set") {
111
- posthogReleaseModeArgs.addAll(["--release-mode", posthogReleaseMode])
109
+ def posthogReleaseModeExplicit = posthogReleaseMode != null
110
+ if (posthogReleaseMode == null) {
111
+ posthogReleaseMode = "event"
112
112
  }
113
113
 
114
114
  // posthog.dotenvFile (gradle.properties): dotenv file with POSTHOG_CLI_*
@@ -142,15 +142,14 @@ plugins.withId('com.android.application') {
142
142
 
143
143
  doFirst {
144
144
  def cliPackage = PostHogCli.resolveCliPackagePath(rootDirFile, reactRoot)
145
- if (!posthogReleaseModeArgs.isEmpty() && System.getenv("POSTHOG_SKIP_CLI_VERSION_CHECK") != "1") {
146
- def cliVersion = PostHogCli.resolveVersion([*osCompatibility, cliPackage])
147
- if (cliVersion == null) {
148
- throw new GradleException("Could not determine the posthog-cli version, which posthog.releaseMode '${posthogReleaseMode}' needs. Upgrade: npm install -g @posthog/cli@latest")
149
- }
150
- if (!PostHogCli.meetsMinimumVersion(cliVersion, PostHogCli.MIN_RELEASE_MODE_VERSION)) {
151
- throw new GradleException("posthog.releaseMode '${posthogReleaseMode}' needs posthog-cli >= ${PostHogCli.MIN_RELEASE_MODE_VERSION} (found ${cliVersion}). Upgrade: npm install -g @posthog/cli@latest")
152
- }
153
- }
145
+ // Resolved once per execution and carried on the task, so doLast does
146
+ // not spawn a second `posthog-cli --version`. Execution-time task state
147
+ // is safe under the configuration cache, which serializes each action's
148
+ // captured state separately. Not a static: a Gradle daemon lives for
149
+ // hours, and a memo there would miss a CLI upgrade.
150
+ def posthogReleaseModeArgs = PostHogCli.releaseModeArgs(
151
+ [*osCompatibility, cliPackage], posthogReleaseMode, posthogReleaseModeExplicit, logger)
152
+ it.ext.posthogReleaseModeArgs = posthogReleaseModeArgs
154
153
  def args = [cliPackage]
155
154
  args.addAll(["hermes", "clone",
156
155
  "--minified-map-path", packagerSourcemapOutput, // The path to a sourcemap
@@ -168,16 +167,15 @@ plugins.withId('com.android.application') {
168
167
  // posthog-cli reads POSTHOG_RELEASE_MODE itself when
169
168
  // --release-mode is absent, which it deliberately is in symbol-set
170
169
  // mode. Pin the resolved mode so a daemon that inherited the
171
- // variable cannot override an explicit posthog.releaseMode.
172
- if (posthogReleaseMode != null) {
173
- environment "POSTHOG_RELEASE_MODE", posthogReleaseMode
174
- }
170
+ // variable cannot override what this build resolved.
171
+ environment "POSTHOG_RELEASE_MODE", posthogReleaseMode
175
172
  commandLine(*osCompatibility, *args)
176
173
  }
177
174
  }
178
175
 
179
176
  doLast {
180
177
  def cliPackage = PostHogCli.resolveCliPackagePath(rootDirFile, reactRoot)
178
+ def posthogReleaseModeArgs = it.ext.posthogReleaseModeArgs
181
179
  def args = [cliPackage]
182
180
  args.addAll(["hermes", "upload",
183
181
  "--directory", sourcemapOutput.getParent() // The path to a sourcemap that should be uploaded.
@@ -192,9 +190,7 @@ plugins.withId('com.android.application') {
192
190
  if (posthogDotenvFilePath != null) {
193
191
  environment "POSTHOG_CLI_DOTENV_FILE", posthogDotenvFilePath
194
192
  }
195
- if (posthogReleaseMode != null) {
196
- environment "POSTHOG_RELEASE_MODE", posthogReleaseMode
197
- }
193
+ environment "POSTHOG_RELEASE_MODE", posthogReleaseMode
198
194
  commandLine(*osCompatibility, *args)
199
195
  }
200
196
  }
@@ -346,6 +342,34 @@ abstract class PostHogCli {
346
342
  }
347
343
  return true
348
344
  }
345
+
346
+ /**
347
+ * The --release-mode arguments for one exec, after the version floor. Symbol-set passes no
348
+ * flag, so it keeps working against a posthog-cli predating it. Event needs the floor: an
349
+ * explicitly configured mode fails the build on an old CLI, while the implicit default only
350
+ * warns and returns no flag, so the upload binds the maps the way builds did before the
351
+ * default changed.
352
+ */
353
+ static List releaseModeArgs(List cliCommand, String mode, boolean explicit, def logger) {
354
+ if (mode == "symbol-set") {
355
+ return []
356
+ }
357
+ if (System.getenv("POSTHOG_SKIP_CLI_VERSION_CHECK") == "1") {
358
+ return ["--release-mode", mode]
359
+ }
360
+ def cliVersion = resolveVersion(cliCommand)
361
+ if (cliVersion != null && meetsMinimumVersion(cliVersion, MIN_RELEASE_MODE_VERSION)) {
362
+ return ["--release-mode", mode]
363
+ }
364
+ if (explicit) {
365
+ if (cliVersion == null) {
366
+ throw new org.gradle.api.GradleException("Could not determine the posthog-cli version, which posthog.hermesReleaseMode '${mode}' needs. Upgrade: npm install -g @posthog/cli@latest")
367
+ }
368
+ throw new org.gradle.api.GradleException("posthog.hermesReleaseMode '${mode}' needs posthog-cli >= ${MIN_RELEASE_MODE_VERSION} (found ${cliVersion}). Upgrade: npm install -g @posthog/cli@latest")
369
+ }
370
+ logger.warn("[PostHog] posthog-cli ${cliVersion ?: 'unknown'} predates release mode '${mode}' (needs >= ${MIN_RELEASE_MODE_VERSION}). Uploading Hermes source maps bound to the release. Upgrade: npm install -g @posthog/cli@latest")
371
+ return []
372
+ }
349
373
  }
350
374
 
351
375
  def resolvePostHogReactNativeSDKPath(reactRoot) {
@@ -358,16 +382,26 @@ def resolvePostHogReactNativeSDKPath(reactRoot) {
358
382
  }
359
383
 
360
384
  /**
361
- * Release mode for this build: the `posthog.releaseMode` gradle property, then the
362
- * `POSTHOG_RELEASE_MODE` environment variable posthog-cli and the bundler plugins already read,
363
- * then null for the posthog-cli default. `com.posthog.android` reads the same property for the R8
364
- * mapping upload, so one entry covers both halves of an Android build.
385
+ * Release mode for the Hermes source map upload: the `posthog.hermesReleaseMode` gradle property,
386
+ * then the deprecated `posthog.releaseMode` property, then the `POSTHOG_RELEASE_MODE` environment
387
+ * variable posthog-cli and the bundler plugins already read, then null. Null means nothing
388
+ * configured a mode: the build applies the `event` default, and an old posthog-cli then softens it
389
+ * to a bound upload with a warning instead of failing the build. The preferred key is not
390
+ * `posthog.releaseMode`, because com.posthog.android below 1.6.0 reads that one for the R8 mapping
391
+ * upload and the mode must not reach it. This covers the JavaScript half of an Android build only.
365
392
  *
366
393
  * An unrecognized value fails the build rather than falling back, so a typo cannot silently leave
367
394
  * a build binding its source maps to a release it meant to keep independent.
368
395
  */
369
396
  static String resolvePostHogReleaseMode(Project project) {
370
- def value = project.findProperty("posthog.releaseMode")?.toString()?.trim()
397
+ def value = project.findProperty("posthog.hermesReleaseMode")?.toString()?.trim()
398
+ if (!value) {
399
+ def legacy = project.findProperty("posthog.releaseMode")?.toString()?.trim()
400
+ if (legacy) {
401
+ project.logger.warn("[PostHog] posthog.releaseMode is deprecated for the Hermes source map upload. Rename the property to posthog.hermesReleaseMode.")
402
+ value = legacy
403
+ }
404
+ }
371
405
  if (!value) {
372
406
  value = System.getenv("POSTHOG_RELEASE_MODE")?.trim()
373
407
  }
@@ -375,7 +409,7 @@ static String resolvePostHogReleaseMode(Project project) {
375
409
  return null
376
410
  }
377
411
  if (!(value in ["symbol-set", "event"])) {
378
- throw new GradleException("posthog.releaseMode must be one of symbol-set, event, was '${value}'")
412
+ throw new GradleException("posthog.hermesReleaseMode must be one of symbol-set, event, was '${value}'")
379
413
  }
380
414
  return value
381
415
  }