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

Revert regression caused by #68 #75

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
6 changes: 2 additions & 4 deletions index.js
Expand Up @@ -5,7 +5,7 @@ const os = require('os');
const pAll = require('p-all');
const arrify = require('arrify');
const globby = require('globby');
const isGlob = require('is-glob');
const hasGlob = require('has-glob');
const cpFile = require('cp-file');
const junk = require('junk');
const CpyError = require('./cpy-error');
Expand Down Expand Up @@ -70,9 +70,7 @@ module.exports = (source, destination, {
throw new CpyError(`Cannot glob \`${source}\`: ${error.message}`, error);
}

const sourcePaths = source.filter(value => !isGlob(value));

if (files.length === 0 || (sourcePaths.length > 0 && !sourcePaths.every(value => files.includes(value)))) {
if (files.length === 0 && !hasGlob(source)) {
throw new CpyError(`Cannot copy \`${source}\`: the file doesn't exist`);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -46,7 +46,7 @@
"arrify": "^2.0.1",
"cp-file": "^7.0.0",
"globby": "^9.2.0",
"is-glob": "^4.0.1",
"has-glob": "^1.0.0",
"junk": "^3.1.0",
"nested-error-stacks": "^2.1.0",
"p-all": "^2.1.0"
Expand Down
10 changes: 1 addition & 9 deletions test.js
Expand Up @@ -159,15 +159,7 @@ test('throws on multiple non-existing files', async t => {
test('does not throw when not matching any file on glob pattern', async t => {
fs.mkdirSync(t.context.tmp);

await t.notThrowsAsync(cpy(['*.js'], t.context.tmp));
});

test('throws on mixed path and glob if path does not exist', async t => {
fs.mkdirSync(t.context.tmp);

await t.throwsAsync(cpy(['*', 'no-file'], t.context.tmp), {
instanceOf: CpyError
});
await t.notThrowsAsync(cpy(['*.nonexistent'], t.context.tmp));
});

test('junk files are ignored', async t => {
Expand Down