From cfacfc84aed226406b5956986e4fa963ef013321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 11 Jun 2019 09:00:59 +0200 Subject: [PATCH] Return copied file paths (#46) --- index.d.ts | 4 ++-- index.js | 1 + index.test-d.ts | 16 ++++++++-------- test.js | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index e87f9cc..834072a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -56,7 +56,7 @@ declare namespace cpy { on( event: 'progress', handler: (progress: ProgressData) => void - ): Promise; + ): Promise; } } @@ -82,7 +82,7 @@ declare const cpy: { files: string | ReadonlyArray, destination: string, options?: cpy.Options - ): Promise & cpy.ProgressEmitter; + ): Promise & cpy.ProgressEmitter; // TODO: Remove this for the next major release, refactor the whole definition to: // declare function cpy( diff --git a/index.js b/index.js index 8f2e559..a57ab9d 100644 --- a/index.js +++ b/index.js @@ -88,6 +88,7 @@ const cpy = (src, dest, options = {}) => { }); } }) + .then(() => to) .catch(error => { throw new CpyError(`Cannot copy from \`${from}\` to \`${to}\`: ${error.message}`, error); }); diff --git a/index.test-d.ts b/index.test-d.ts index 3a3e5da..c6a6500 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -2,29 +2,29 @@ import {expectType} from 'tsd'; import cpy = require('.'); import {ProgressEmitter, ProgressData} from '.'; -expectType & ProgressEmitter>( +expectType & ProgressEmitter>( cpy(['source/*.png', '!source/goat.png'], 'destination') ); -expectType & ProgressEmitter>( +expectType & ProgressEmitter>( cpy('foo.js', 'destination', {rename: 'foobar'}) ); -expectType & ProgressEmitter>( +expectType & ProgressEmitter>( cpy('foo.js', 'destination', {rename: basename => `prefix-${basename}`}) ); -expectType & ProgressEmitter>( +expectType & ProgressEmitter>( cpy('foo.js', 'destination', {cwd: '/'}) ); -expectType & ProgressEmitter>( +expectType & ProgressEmitter>( cpy('foo.js', 'destination', {parents: true}) ); -expectType & ProgressEmitter>( +expectType & ProgressEmitter>( cpy('foo.js', 'destination', {expandDirectories: true}) ); -expectType & ProgressEmitter>( +expectType & ProgressEmitter>( cpy('foo.js', 'destination', {overwrite: false}) ); -expectType>( +expectType>( cpy('foo.js', 'destination').on('progress', progress => { expectType(progress); diff --git a/test.js b/test.js index f786521..279ced5 100644 --- a/test.js +++ b/test.js @@ -221,3 +221,17 @@ test('returns the event emitter on early rejection', t => { t.is(typeof rejectedPromise.on, 'function'); rejectedPromise.catch(() => {}); }); + +test('returns destination path', async t => { + fs.mkdirSync(t.context.tmp); + fs.mkdirSync(path.join(t.context.tmp, 'cwd')); + fs.writeFileSync(path.join(t.context.tmp, 'cwd/foo'), 'lorem ipsum'); + fs.writeFileSync(path.join(t.context.tmp, 'cwd/bar'), 'dolor sit amet'); + + const to = await cpy(['foo', 'bar'], t.context.tmp, {cwd: path.join(t.context.tmp, 'cwd')}); + + t.deepEqual(to, [ + path.join(t.context.tmp, 'foo'), + path.join(t.context.tmp, 'bar') + ]); +});