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

Reverse order back for the returned paths #99

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions index.js
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
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