Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glob for nested directories #80

Merged
merged 3 commits into from Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -25,6 +25,9 @@ module.exports = (paths, options) => pTry(() => {
}

paths = paths
.filter(filePath => !paths.some(
otherPath => filePath !== otherPath && path.dirname(filePath) === otherPath)
medusalix marked this conversation as resolved.
Show resolved Hide resolved
)
medusalix marked this conversation as resolved.
Show resolved Hide resolved
.map(filePath => path.resolve(filePath))
.filter(filePath => {
try {
Expand Down
28 changes: 28 additions & 0 deletions test.js
Expand Up @@ -168,3 +168,31 @@ test('non-existent files', async t => {
t.false(fs.existsSync('fixture-enoent'));
await t.notThrowsAsync(trash('fixture-enoent'));
});

test('glob with nested directories', async t => {
const dir1 = 'foo';
const file1 = path.join('foo', 'bar.txt');
const file2 = path.join('foo', 'baz.txt');
const dir2 = path.join('foo', 'bar');
const dir3 = path.join('foo', 'baz');
const file3 = path.join(dir1, 'foo.txt');
const file4 = path.join(dir2, 'bar.txt');

fs.mkdirSync(dir1);
fs.mkdirSync(dir2);
fs.mkdirSync(dir3);
fs.writeFileSync(file1, '');
fs.writeFileSync(file2, '');
fs.writeFileSync(file3, '');
fs.writeFileSync(file4, '');
t.true(fs.existsSync(file1));
t.true(fs.existsSync(file2));
t.true(fs.existsSync(file3));
t.true(fs.existsSync(file4));

await trash(`${dir1}/**`, {glob: true});

t.false(fs.existsSync(dir1));
t.false(fs.existsSync(dir2));
t.false(fs.existsSync(dir3));
});