Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/eas-cli/src/vcs/__tests__/local-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ describe(Ignore, () => {
expect(ignore.ignores('dir/bbb')).toBe(true);
});

it('matches nested .gitignore prefixes against Windows-style relative paths', async () => {
vol.fromJSON(
{
'packages/app/.gitignore': 'ignored.txt',
},
'/root'
);

const ignore = await Ignore.createForCopyingAsync('/root');
expect(ignore.ignores(String.raw`packages\app\ignored.txt`)).toBe(true);
});

it('ignores .gitignore files if .easignore is present', async () => {
vol.fromJSON(
{
Expand Down Expand Up @@ -111,4 +123,17 @@ describe(Ignore, () => {
const ignore = await Ignore.createForCopyingAsync('/root');
expect(() => ignore.ignores('dir/test')).not.toThrowError();
});

it('treats directory rules as directories when checking copy filters', async () => {
vol.fromJSON(
{
'.gitignore': 'dist/\n',
},
'/root'
);

const ignore = await Ignore.createForCopyingAsync('/root');
expect(ignore.ignores('dist', { isDirectory: true })).toBe(true);
expect(ignore.ignores('dist/index.js')).toBe(true);
});
});
22 changes: 19 additions & 3 deletions packages/eas-cli/src/vcs/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,29 @@ node_modules
});
}

public ignores(relativePath: string): boolean {
public ignores(relativePath: string, options: { isDirectory?: boolean } = {}): boolean {
const normalizedPath = normalizeIgnorePath(relativePath, options);
for (const [prefix, ignore] of this.ignoreMapping) {
if (relativePath.startsWith(prefix) && ignore.ignores(relativePath.slice(prefix.length))) {
const normalizedPrefix = normalizeIgnorePath(prefix);
if (
normalizedPath.startsWith(normalizedPrefix) &&
ignore.ignores(normalizedPath.slice(normalizedPrefix.length))
) {
return true;
}
}
return false;
}
}

function normalizeIgnorePath(relativePath: string, options: { isDirectory?: boolean } = {}): string {
const normalizedPath = relativePath.replace(/\\/g, '/');
if (options.isDirectory && normalizedPath && !normalizedPath.endsWith('/')) {
return `${normalizedPath}/`;
}
return normalizedPath;
}

export async function makeShallowCopyAsync(_src: string, dst: string): Promise<void> {
// `node:fs` on Windows adds a namespace prefix (e.g. `\\?\`) to the path provided
// to the `filter` function in `fs.cp`. We need to ensure that we compare the right paths
Expand All @@ -114,8 +127,11 @@ export async function makeShallowCopyAsync(_src: string, dst: string): Promise<v
if (srcFilePath === src) {
return true;
}
const stats = fsExtra.lstatSync(srcFilePath);
const relativePath = path.relative(src, srcFilePath);
const shouldCopyTheItem = !ignore.ignores(relativePath);
const shouldCopyTheItem = !ignore.ignores(relativePath, {
isDirectory: stats.isDirectory(),
});

Log.debug(shouldCopyTheItem ? 'copying' : 'skipping', {
src,
Expand Down
Loading