diff --git a/.changeset/dependency-notice-tty.md b/.changeset/dependency-notice-tty.md new file mode 100644 index 0000000000..24ddb8d1cd --- /dev/null +++ b/.changeset/dependency-notice-tty.md @@ -0,0 +1,5 @@ +--- +'eas-cli': patch +--- + +Print the notice about eas-cli in project dependencies only when stderr is a terminal, so programs that read stderr get the command's error. diff --git a/packages/eas-cli/src/commandUtils/context/contextUtils/__tests__/findProjectDirAndVerifyProjectSetupAsync-test.ts b/packages/eas-cli/src/commandUtils/context/contextUtils/__tests__/findProjectDirAndVerifyProjectSetupAsync-test.ts index 1dcb9492a0..f23c695b13 100644 --- a/packages/eas-cli/src/commandUtils/context/contextUtils/__tests__/findProjectDirAndVerifyProjectSetupAsync-test.ts +++ b/packages/eas-cli/src/commandUtils/context/contextUtils/__tests__/findProjectDirAndVerifyProjectSetupAsync-test.ts @@ -11,8 +11,16 @@ jest.mock('fs'); jest.mock('../../../../prompts'); +const originalStderrIsTTY = process.stderr.isTTY; + beforeEach(() => { jest.resetAllMocks(); + // The dependency notice prints once per process and only to a terminal, so keep it unspent. + process.stderr.isTTY = false; +}); + +afterAll(() => { + process.stderr.isTTY = originalStderrIsTTY; }); describe(findProjectRootAsync, () => { @@ -115,3 +123,32 @@ describe(findProjectDirAndVerifyProjectSetupAsync, () => { await expect(findProjectDirAndVerifyProjectSetupAsync({ cwd: '/app' })).resolves.not.toThrow(); }); }); + +describe('eas-cli dependency notice', () => { + beforeEach(() => { + vol.reset(); + vol.fromJSON( + { + './eas.json': JSON.stringify({}), + './package.json': JSON.stringify({ devDependencies: { 'eas-cli': '*' } }), + }, + '/app' + ); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('prints the notice only when stderr is a terminal', async () => { + const warn = jest.spyOn(console, 'warn').mockImplementation(() => {}); + + process.stderr.isTTY = false; + await findProjectDirAndVerifyProjectSetupAsync({ cwd: '/app' }); + expect(warn).not.toHaveBeenCalled(); + + process.stderr.isTTY = true; + await findProjectDirAndVerifyProjectSetupAsync({ cwd: '/app' }); + expect(warn).toHaveBeenCalledWith(expect.stringContaining('in your project dependencies')); + }); +}); diff --git a/packages/eas-cli/src/commandUtils/context/contextUtils/findProjectDirAndVerifyProjectSetupAsync.ts b/packages/eas-cli/src/commandUtils/context/contextUtils/findProjectDirAndVerifyProjectSetupAsync.ts index 77a939f37f..f03b202286 100644 --- a/packages/eas-cli/src/commandUtils/context/contextUtils/findProjectDirAndVerifyProjectSetupAsync.ts +++ b/packages/eas-cli/src/commandUtils/context/contextUtils/findProjectDirAndVerifyProjectSetupAsync.ts @@ -127,7 +127,8 @@ export async function findProjectDirAndVerifyProjectSetupAsync({ } = {}): Promise { const projectDir = await findProjectRootAsync({ cwd }); await applyCliConfigAsync(projectDir); - if (!ranEnsureEasCliIsNotInDependencies) { + // The notice is advice for a person. Programs that run eas-cli read stderr for its errors. + if (!ranEnsureEasCliIsNotInDependencies && process.stderr.isTTY) { ranEnsureEasCliIsNotInDependencies = true; await ensureEasCliIsNotInDependenciesAsync(projectDir); }