Skip to content

Commit

Permalink
Reverse order back for the returned paths (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisblossom authored and sindresorhus committed Jul 13, 2019
1 parent 902b594 commit 51662ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
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

0 comments on commit 51662ac

Please sign in to comment.