From 0c380985ab7d933826424d78732fc03b22d5f9f7 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Fri, 21 Feb 2020 13:00:23 +0200 Subject: [PATCH] Revert regression caused by #68 (#75) --- index.js | 6 ++---- package.json | 2 +- test.js | 10 +--------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index eb887d5..398cbe0 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -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`); } diff --git a/package.json b/package.json index f58b62e..87d71d4 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test.js b/test.js index f61ed75..4d440af 100644 --- a/test.js +++ b/test.js @@ -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 => {