[eas-cli] Fix fingerprint commands corrupting --json output with --environment#3870
[eas-cli] Fix fingerprint commands corrupting --json output with --environment#3870nossila wants to merge 1 commit into
Conversation
…vironment `fingerprint:generate` and `fingerprint:compare` called enableJsonOutput() after getContextAsync(), but the ProjectConfig context eagerly loads server-side environment variables — logging the "Environment variables with visibility ... loaded from the ... environment on EAS: ..." line — before the stdout->stderr redirect was installed. That line leaked into stdout and broke JSON parsing. Enable JSON output before resolving context so the redirect is active while env vars load.
|
Subscribed to pull request
Generated by CodeMention |
|
Related prior art: #3659 fixed a different cause of corrupted This PR addresses an independent, in-process cause: |
|
@quinlanj would you be able to review? You own most of the fingerprint command code, so you're the natural reviewer here. cc @wschurman / @Mookiies |
|
Workaround for affected releases (until this is merged/released): use # Broken: leading "Environment variables with visibility ..." line corrupts stdout
eas fingerprint:generate -p ios --environment preview --json --non-interactive | jq -r '.hash'
# Works: stdout is clean JSON
eas fingerprint:generate -p ios --build-profile preview --json --non-interactive | jq -r '.hash'Why it works: the bug only triggers with Note: For reference, this bug is present in every release for the |
Why
Running
eas fingerprint:generate --platform ios --environment preview --json --non-interactive(orfingerprint:comparewith--environment) emits aneas-clilog line to stdout before the JSON, so the output is not valid JSON and tools likejqfail to parse it:What's going on
In
--jsonmode,src/utils/json.tsredirectsprocess.stdout.write → process.stderr.writeso progress logs don't pollute the final JSON, and onlyprintJsonOnlyOutput()writes to the real stdout.But in both
fingerprint:generateandfingerprint:compare,enableJsonOutput()was called aftergetContextAsync(). When--environmentis set, theProjectConfigcontext (PrivateProjectConfigContextField) eagerly loads the server-side environment variables during context resolution, andloadServerSideEnvironmentVariablesAsync()logs theEnvironment variables with visibility ...line viaLog.log→console.log→process.stdout.write. Because that happens before the redirect is installed, the line lands on the real stdout and corrupts the JSON. (The value is cached, so the latergetServerSideEnvironmentVariablesAsync()call doesn't re-log it — the context load is the only emitter.)This is a separate, in-process cause from the subprocess-output corruption fixed in #3659; that PR set
silent: truefor@expo/fingerprintsubprocesses and does not touch this ordering.How
Move the
if (json) { enableJsonOutput(); }block to beforegetContextAsync()in both commands, so the stdout→stderr redirect is active while the context loads (and logs) the server-side environment variables. Thejsonflag is already resolved earlier, so this is safe. Added a CHANGELOG bug-fix entry.Test Plan
yarn typecheck— passes.yarn lint/yarn fmt:check— pass (0 errors in touched files).Manual reproduction:
With the fix, the env-var log is written to stderr and stdout contains only the JSON, so
jq -r '.hash'succeeds. Redirecting stderr to/dev/null(2>/dev/null) leaves valid JSON.