diff --git a/CHANGELOG.md b/CHANGELOG.md index 78dd550e82..8aa5f21d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This is the log of notable changes to EAS CLI and related packages. ### 🎉 New features - Load `.env` variables even when `--environment` is specified for `deploy` command. Conflicts will be highlighted by a warning message. ([#2783](https://github.com/expo/eas-cli/pull/2783) by [@kitten](https://github.com/kitten)) +- Silence all non-command output in non-interactive mode of eas env:exec. ([#2800](https://github.com/expo/eas-cli/pull/2800) by [@wschurman](https://github.com/wschurman)) ### 🐛 Bug fixes diff --git a/packages/eas-cli/src/commands/env/exec.ts b/packages/eas-cli/src/commands/env/exec.ts index 554a9bcced..1a30824df2 100644 --- a/packages/eas-cli/src/commands/env/exec.ts +++ b/packages/eas-cli/src/commands/env/exec.ts @@ -53,9 +53,10 @@ export default class EnvExec extends EasCommand { }, ]; + private isNonInteractive: boolean = false; + async runAsync(): Promise { const { flags, args } = await this.parse(EnvExec); - const parsedFlags = this.sanitizeFlagsAndArgs(flags, args); const { @@ -65,6 +66,8 @@ export default class EnvExec extends EasCommand { nonInteractive: parsedFlags.nonInteractive, }); + this.isNonInteractive = parsedFlags.nonInteractive; + const environment = parsedFlags.environment ?? (await promptVariableEnvironmentAsync({ nonInteractive: parsedFlags.nonInteractive })); @@ -72,12 +75,20 @@ export default class EnvExec extends EasCommand { graphqlClient, projectId, environment, + nonInteractive: parsedFlags.nonInteractive, }); - await this.runCommandWithEnvVarsAsync({ - command: parsedFlags.command, - environmentVariables, - }); + if (parsedFlags.nonInteractive) { + await this.runCommandNonInteractiveWithEnvVarsAsync({ + command: parsedFlags.command, + environmentVariables, + }); + } else { + await this.runCommandWithEnvVarsAsync({ + command: parsedFlags.command, + environmentVariables, + }); + } } private sanitizeFlagsAndArgs( @@ -103,6 +114,33 @@ export default class EnvExec extends EasCommand { }; } + private async runCommandNonInteractiveWithEnvVarsAsync({ + command, + environmentVariables, + }: { + command: string; + environmentVariables: Record; + }): Promise { + await spawnAsync('bash', ['-c', command], { + stdio: 'inherit', + env: { + ...process.env, + ...environmentVariables, + }, + }); + } + + // eslint-disable-next-line async-protect/async-suffix + protected override async catch(err: Error): Promise { + // when in non-interactive, make the behavior of this command a pure passthrough, outputting only the subprocess' stdout and stderr and exiting with the + // sub-command's exit status + if (this.isNonInteractive) { + process.exitCode = process.exitCode ?? (err as any).status ?? 1; + } else { + await super.catch(err); + } + } + private async runCommandWithEnvVarsAsync({ command, environmentVariables, @@ -147,10 +185,12 @@ export default class EnvExec extends EasCommand { graphqlClient, projectId, environment, + nonInteractive, }: { graphqlClient: ExpoGraphqlClient; projectId: string; environment: EnvironmentVariableEnvironment; + nonInteractive: boolean; }): Promise> { const environmentVariablesQueryResult = await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, { @@ -162,18 +202,20 @@ export default class EnvExec extends EasCommand { ({ value }) => !!value ); - if (nonSecretEnvironmentVariables.length > 0) { - Log.log( - `Environment variables with visibility "Plain text" and "Sensitive" loaded from the "${environment.toLowerCase()}" environment on EAS: ${nonSecretEnvironmentVariables - .map(e => e.name) - .join(', ')}.` - ); - } else { - Log.log( - `No environment variables with visibility "Plain text" and "Sensitive" found for the "${environment.toLowerCase()}" environment on EAS.` - ); + if (!nonInteractive) { + if (nonSecretEnvironmentVariables.length > 0) { + Log.log( + `Environment variables with visibility "Plain text" and "Sensitive" loaded from the "${environment.toLowerCase()}" environment on EAS: ${nonSecretEnvironmentVariables + .map(e => e.name) + .join(', ')}.` + ); + } else { + Log.log( + `No environment variables with visibility "Plain text" and "Sensitive" found for the "${environment.toLowerCase()}" environment on EAS.` + ); + } + Log.newLine(); } - Log.newLine(); const environmentVariables: Record = {}; for (const { name, value } of nonSecretEnvironmentVariables) {