Skip to content

Commit ef8d6d0

Browse files
authored
[eas-cli] Adhere to .easignore even if requireCommit is true (#2942)
# Why #2925 (comment) # How Delete files from `.easignore` even if `requireCommit` is `true`. Instead of erroring, print a warning. # Test Plan Adjusted tests.
1 parent 6ba59a3 commit ef8d6d0

File tree

3 files changed

+100
-21
lines changed

3 files changed

+100
-21
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ This is the log of notable changes to EAS CLI and related packages.
66

77
### 🛠 Breaking changes
88

9+
- Add support for `.easignore` when `requireCommit` is set to `true`. ([#2942](https://github.com/expo/eas-cli/pull/2942) by [@sjchmiela](https://github.com/sjchmiela))
10+
- Up to 15.0.0, if `requireCommit` was `true`, `.easignore` was silently ignored.
11+
- Versions 15.0.0-15.0.13 started using `.easignore` to skip files from being bundled into a tarball when `requireCommit` was `true`. This was an unexpected change in behavior.
12+
- To clear this up, versions 15.0.13-15.0.15 were erroring if `.easignore` was present when `requireCommit` was `true`.
13+
- `[email protected]` formalizes the 15.0.0-15.0.13 behavior by adhering to `.easignore` even when `requireCommit` is set to `true`.
14+
- If you know what you're doing and you want to suppress a warning printed, you can do so by setting `EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING` environment variable to `true`.
15+
916
### 🎉 New features
1017

1118
- Add requestId to ApiV2Error. ([#2941](https://github.com/expo/eas-cli/pull/2941) by [@wschurman](https://github.com/wschurman))

packages/eas-cli/src/vcs/clients/__tests__/git.test.ts

+83-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from 'fs/promises';
33
import os from 'os';
44
import path from 'path';
55

6+
import Log from '../../../log';
67
import GitClient from '../git';
78

89
describe('git', () => {
@@ -242,19 +243,91 @@ describe('git', () => {
242243
).resolves.not.toThrow();
243244
});
244245

245-
it('does not allow .easignore if requireCommit is true', async () => {
246-
const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
247-
await spawnAsync('git', ['init'], { cwd: repoRoot });
248-
const vcs = new GitClient({
249-
requireCommit: true,
250-
maybeCwdOverride: repoRoot,
246+
describe('when requireCommit is true', () => {
247+
it('adheres to .easignore', async () => {
248+
const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
249+
await spawnAsync('git', ['init'], { cwd: repoRoot });
250+
const vcs = new GitClient({
251+
requireCommit: true,
252+
maybeCwdOverride: repoRoot,
253+
});
254+
255+
const warn = jest.spyOn(Log, 'warn');
256+
257+
await fs.writeFile(`${repoRoot}/.easignore`, '*easignored*\n');
258+
await fs.writeFile(`${repoRoot}/.gitignore`, '*gitignored*\n');
259+
260+
await fs.writeFile(`${repoRoot}/easignored-file.txt`, 'file');
261+
await fs.writeFile(`${repoRoot}/nonignored-file.txt`, 'file');
262+
await fs.writeFile(`${repoRoot}/gitignored-file.txt`, 'file');
263+
await spawnAsync('git', ['add', '.'], { cwd: repoRoot });
264+
await spawnAsync('git', ['commit', '-m', 'tmp commit'], { cwd: repoRoot });
265+
266+
const copyRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
267+
await expect(vcs.makeShallowCopyAsync(copyRoot)).resolves.not.toThrow();
268+
269+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('.easignore'));
270+
271+
await expect(fs.stat(path.join(copyRoot, 'easignored-file.txt'))).rejects.toThrow('ENOENT');
272+
await expect(fs.stat(path.join(copyRoot, 'gitignored-file.txt'))).rejects.toThrow('ENOENT');
273+
await expect(fs.stat(path.join(copyRoot, 'nonignored-file.txt'))).resolves.not.toThrow();
251274
});
252275

253-
await fs.writeFile(`${repoRoot}/.easignore`, '*easignored*\n');
276+
it('prints a warning only once if .easignore exists', async () => {
277+
const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
278+
await spawnAsync('git', ['init'], { cwd: repoRoot });
279+
const vcs = new GitClient({
280+
requireCommit: true,
281+
maybeCwdOverride: repoRoot,
282+
});
254283

255-
await spawnAsync('git', ['add', '.'], { cwd: repoRoot });
256-
await spawnAsync('git', ['commit', '-m', 'tmp commit'], { cwd: repoRoot });
284+
const warn = jest.spyOn(Log, 'warn');
285+
286+
await fs.writeFile(`${repoRoot}/.easignore`, '*easignored*\n');
287+
await spawnAsync('git', ['add', '.'], { cwd: repoRoot });
288+
await spawnAsync('git', ['commit', '-m', 'tmp commit'], { cwd: repoRoot });
289+
290+
const copyRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
291+
await expect(vcs.makeShallowCopyAsync(copyRoot)).resolves.not.toThrow();
292+
293+
expect(warn).toHaveBeenCalledTimes(1);
294+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('.easignore'));
295+
296+
const anotherCopyRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
297+
await expect(vcs.makeShallowCopyAsync(anotherCopyRoot)).resolves.not.toThrow();
298+
299+
expect(warn).toHaveBeenCalledTimes(1);
300+
});
301+
302+
describe('when EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING is set', () => {
303+
beforeAll(() => {
304+
process.env.EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING = '1';
305+
});
306+
307+
afterAll(() => {
308+
delete process.env.EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING;
309+
});
310+
311+
it('does not print a warning', async () => {
312+
const repoRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
313+
await spawnAsync('git', ['init'], { cwd: repoRoot });
314+
const vcs = new GitClient({
315+
requireCommit: true,
316+
maybeCwdOverride: repoRoot,
317+
});
257318

258-
await expect(vcs.makeShallowCopyAsync(repoRoot)).rejects.toThrow('Detected ".easignore" file');
319+
const warn = jest.spyOn(Log, 'warn');
320+
warn.mockClear();
321+
322+
await fs.writeFile(`${repoRoot}/.easignore`, '*easignored*\n');
323+
await spawnAsync('git', ['add', '.'], { cwd: repoRoot });
324+
await spawnAsync('git', ['commit', '-m', 'tmp commit'], { cwd: repoRoot });
325+
326+
const copyRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-cli-git-test-'));
327+
await expect(vcs.makeShallowCopyAsync(copyRoot)).resolves.not.toThrow();
328+
329+
expect(warn).toHaveBeenCalledTimes(0);
330+
});
331+
});
259332
});
260333
});

packages/eas-cli/src/vcs/clients/git.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import spawnAsync from '@expo/spawn-async';
33
import { Errors } from '@oclif/core';
44
import chalk from 'chalk';
55
import fs from 'fs-extra';
6+
import getenv from 'getenv';
67
import path from 'path';
78

89
import Log, { learnMore } from '../../log';
@@ -18,6 +19,8 @@ import {
1819
import { EASIGNORE_FILENAME, Ignore, makeShallowCopyAsync } from '../local';
1920
import { Client } from '../vcs';
2021

22+
let hasWarnedAboutEasignoreInRequireCommit = false;
23+
2124
export default class GitClient extends Client {
2225
private readonly maybeCwdOverride?: string;
2326
public requireCommit: boolean;
@@ -165,18 +168,14 @@ export default class GitClient extends Client {
165168
const rootPath = await this.getRootPathAsync();
166169
const sourceEasignorePath = path.join(rootPath, EASIGNORE_FILENAME);
167170
const doesEasignoreExist = await fs.exists(sourceEasignorePath);
168-
if (this.requireCommit && doesEasignoreExist) {
169-
Log.error(
170-
`".easignore" file is not supported if you also have "requireCommit" set to "true" in "eas.json".`
171-
);
172-
Log.error(
173-
`Remove "${sourceEasignorePath}" and use ".gitignore" instead. ${learnMore(
174-
'https://expo.fyi/eas-build-archive'
175-
)}`
176-
);
177-
throw new Error(
178-
`Detected ".easignore" file ${sourceEasignorePath} while in "requireCommit = true" mode.`
171+
const shouldSuppressWarning =
172+
hasWarnedAboutEasignoreInRequireCommit ||
173+
getenv.boolish('EAS_SUPPRESS_REQUIRE_COMMIT_EASIGNORE_WARNING', false);
174+
if (this.requireCommit && doesEasignoreExist && !shouldSuppressWarning) {
175+
Log.warn(
176+
`You have "requireCommit: true" in "eas.json" and also ".easignore". If ".easignore" does remove files, note that the repository checked out in EAS will not longer be Git-clean.`
179177
);
178+
hasWarnedAboutEasignoreInRequireCommit = true;
180179
}
181180

182181
let gitRepoUri;

0 commit comments

Comments
 (0)