Skip to content
Merged
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
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ module.exports = async (patterns, {force, dryRun, cwd = process.cwd(), ...option
return file;
};

return pMap(files, mapper, options);
const removedFiles = await pMap(files, mapper, options);

removedFiles.reverse();

return removedFiles;
};

module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options} = {}) => {
Expand All @@ -60,7 +64,7 @@ module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options
const files = globby.sync(patterns, options)
.sort((a, b) => b.localeCompare(a));

return files.map(file => {
const removedFiles = files.map(file => {
file = path.resolve(cwd, file);

if (!force) {
Expand All @@ -73,4 +77,8 @@ module.exports.sync = (patterns, {force, dryRun, cwd = process.cwd(), ...options

return file;
});

removedFiles.reverse();

return removedFiles;
};
20 changes: 10 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ test('don\'t delete files, but return them - async', async t => {
});
exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']);
t.deepEqual(deletedFiles, [
path.join(t.context.tmp, '4.tmp'),
path.join(t.context.tmp, '2.tmp'),
path.join(t.context.tmp, '3.tmp'),
path.join(t.context.tmp, '2.tmp')
path.join(t.context.tmp, '4.tmp')
]);
});

Expand All @@ -103,9 +103,9 @@ test('don\'t delete files, but return them - sync', t => {
});
exists(t, ['1.tmp', '2.tmp', '3.tmp', '4.tmp', '.dot.tmp']);
t.deepEqual(deletedFiles, [
path.join(t.context.tmp, '4.tmp'),
path.join(t.context.tmp, '2.tmp'),
path.join(t.context.tmp, '3.tmp'),
path.join(t.context.tmp, '2.tmp')
path.join(t.context.tmp, '4.tmp')
]);
});

Expand All @@ -131,10 +131,10 @@ test('does not throw EINVAL - async', async t => {
});

const expected = [
path.resolve(t.context.tmp, 'a/b/c/nested.js'),
path.resolve(t.context.tmp, 'a/b/c'),
path.resolve(t.context.tmp, 'a'),
path.resolve(t.context.tmp, 'a/b'),
path.resolve(t.context.tmp, 'a')
path.resolve(t.context.tmp, 'a/b/c'),
path.resolve(t.context.tmp, 'a/b/c/nested.js')
];

t.deepEqual(removed, expected);
Expand Down Expand Up @@ -165,10 +165,10 @@ test('does not throw EINVAL - sync', t => {
});

const expected = [
path.resolve(t.context.tmp, 'a/b/c/nested.js'),
path.resolve(t.context.tmp, 'a/b/c'),
path.resolve(t.context.tmp, 'a'),
path.resolve(t.context.tmp, 'a/b'),
path.resolve(t.context.tmp, 'a')
path.resolve(t.context.tmp, 'a/b/c'),
path.resolve(t.context.tmp, 'a/b/c/nested.js')
];

t.deepEqual(removed, expected);
Expand Down