Skip to content

Commit a2929ad

Browse files
authored
[eas-cli] Improve DX of Ignore (#2877)
<!-- If this PR requires a changelog entry, add it by commenting the PR with the command `/changelog-entry [breaking-change|new-feature|bug-fix|chore] [message]`. --> <!-- You can skip the changelog check by labeling the PR with "no changelog". --> # Why `[email protected]` doesn't interpret `.easignore` right because I haven't initialized the `Ignore` class properly. # How Make it so it's not possible to use `Ignore` without initializing it. # Test Plan Tests should pass.
1 parent 6deee68 commit a2929ad

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

packages/eas-cli/src/vcs/__tests__/local-test.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ describe(Ignore, () => {
1818
'/root'
1919
);
2020

21-
const ignore = new Ignore('/root');
22-
await ignore.initIgnoreAsync();
21+
const ignore = await Ignore.createAsync('/root');
2322
expect(ignore.ignores('aaa')).toBe(true);
2423
expect(ignore.ignores('bbb')).toBe(false);
2524
expect(ignore.ignores('dir/aaa')).toBe(true);
@@ -36,8 +35,7 @@ describe(Ignore, () => {
3635
'/root'
3736
);
3837

39-
const ignore = new Ignore('/root');
40-
await ignore.initIgnoreAsync();
38+
const ignore = await Ignore.createAsync('/root');
4139
expect(ignore.ignores('aaa')).toBe(false);
4240
expect(ignore.ignores('bbb')).toBe(false);
4341
expect(ignore.ignores('ccc')).toBe(true);
@@ -54,8 +52,7 @@ describe(Ignore, () => {
5452
'/root'
5553
);
5654

57-
const ignore = new Ignore('/root');
58-
await ignore.initIgnoreAsync();
55+
const ignore = await Ignore.createAsync('/root');
5956
expect(ignore.ignores('aaa')).toBe(true);
6057
expect(ignore.ignores('bbb')).toBe(false);
6158
expect(ignore.ignores('node_modules/aaa')).toBe(true);
@@ -72,16 +69,14 @@ describe(Ignore, () => {
7269
'/root'
7370
);
7471

75-
const ignore = new Ignore('/root');
76-
await ignore.initIgnoreAsync();
72+
const ignore = await Ignore.createAsync('/root');
7773
expect(ignore.ignores('dir/ccc')).toBe(true);
7874
});
7975

8076
it('ignores .git', async () => {
8177
vol.fromJSON({}, '/root');
8278

83-
const ignore = new Ignore('/root');
84-
await ignore.initIgnoreAsync();
79+
const ignore = await Ignore.createAsync('/root');
8580
expect(ignore.ignores('.git')).toBe(true);
8681
});
8782

@@ -93,8 +88,7 @@ describe(Ignore, () => {
9388
'/root'
9489
);
9590

96-
const ignore = new Ignore('/root');
97-
await ignore.initIgnoreAsync();
91+
const ignore = await Ignore.createAsync('/root');
9892
expect(() => ignore.ignores('dir/test')).not.toThrowError();
9993
});
10094
});

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ export default class GitClient extends Client {
299299

300300
const easIgnorePath = path.join(rootPath, EASIGNORE_FILENAME);
301301
if (await fs.exists(easIgnorePath)) {
302-
const ignore = new Ignore(rootPath);
303-
await ignore.initIgnoreAsync();
302+
const ignore = await Ignore.createAsync(rootPath);
304303
const wouldNotBeCopiedToClone = ignore.ignores(filePath);
305304
const wouldBeDeletedFromClone =
306305
(

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export default class NoVcsClient extends Client {
1212
}
1313

1414
public override async isFileIgnoredAsync(filePath: string): Promise<boolean> {
15-
const ignore = new Ignore(getRootPath());
16-
await ignore.initIgnoreAsync();
15+
const ignore = await Ignore.createAsync(getRootPath());
1716
return ignore.ignores(filePath);
1817
}
1918

packages/eas-cli/src/vcs/local.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ export function getRootPath(): string {
3232
export class Ignore {
3333
private ignoreMapping: (readonly [string, SingleFileIgnore])[] = [];
3434

35-
constructor(private readonly rootDir: string) {}
35+
private constructor(private readonly rootDir: string) {}
36+
37+
static async createAsync(rootDir: string): Promise<Ignore> {
38+
const ignore = new Ignore(rootDir);
39+
await ignore.initIgnoreAsync();
40+
return ignore;
41+
}
3642

3743
public async initIgnoreAsync(): Promise<void> {
3844
const easIgnorePath = path.join(this.rootDir, EASIGNORE_FILENAME);
@@ -75,8 +81,7 @@ export class Ignore {
7581
}
7682

7783
export async function makeShallowCopyAsync(src: string, dst: string): Promise<void> {
78-
const ignore = new Ignore(src);
79-
await ignore.initIgnoreAsync();
84+
const ignore = await Ignore.createAsync(src);
8085
await fs.copy(src, dst, {
8186
filter: (srcFilePath: string) => {
8287
if (srcFilePath === src) {

0 commit comments

Comments
 (0)