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

Throw if the given source file does not exist #68

Merged
merged 13 commits into from Sep 22, 2019
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -3,6 +3,7 @@ const EventEmitter = require('events');
const path = require('path');
const arrify = require('arrify');
const globby = require('globby');
const hasGlob = require('has-glob');
const cpFile = require('cp-file');
const CpyError = require('./cpy-error');

Expand Down Expand Up @@ -50,7 +51,7 @@ module.exports = (source, destination, options = {}) => {
throw new CpyError(`Cannot glob \`${source}\`: ${error.message}`, error);
}

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

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -45,6 +45,7 @@
"arrify": "^2.0.1",
"cp-file": "^7.0.0",
"globby": "^9.2.0",
"has-glob": "^1.0.0",
"nested-error-stacks": "^2.1.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions test.js
Expand Up @@ -151,6 +151,12 @@ 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));
whitecrownclown marked this conversation as resolved.
Show resolved Hide resolved
});

test('reports copy progress of single file', async t => {
fs.mkdirSync(t.context.tmp);
fs.mkdirSync(path.join(t.context.tmp, 'cwd'));
Expand Down