Skip to content

Commit

Permalink
Revert regression caused by #68 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitecrownclown committed Feb 21, 2020
1 parent 14d5991 commit 0c38098
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
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

0 comments on commit 0c38098

Please sign in to comment.