diff --git a/index.js b/index.js index 4abb713..8efd4df 100644 --- a/index.js +++ b/index.js @@ -118,15 +118,14 @@ const preprocessDestinationPath = ({entry, destination, options}) => { @param {string|Function} rename */ const renameFile = (source, rename) => { - const filename = path.basename(source, path.extname(source)); - const fileExtension = path.extname(source); const directory = path.dirname(source); if (typeof rename === 'string') { return path.join(directory, rename); } if (typeof rename === 'function') { - return path.join(directory, `${rename(filename)}${fileExtension}`); + const filename = path.basename(source); + return path.join(directory, rename(filename)); } return source; diff --git a/test.js b/test.js index 4c0c01a..bd10338 100644 --- a/test.js +++ b/test.js @@ -215,6 +215,25 @@ test('rename filenames using a function', async t => { ); }); +test('rename function receives the basename argument with the file extension', async t => { + fs.mkdirSync(t.context.tmp); + fs.writeFileSync(path.join(t.context.tmp, 'foo.js'), ''); + fs.writeFileSync(path.join(t.context.tmp, 'foo.ts'), ''); + + const visited = []; + await cpy(['foo.js', 'foo.ts'], 'destination/subdir', { + cwd: t.context.tmp, + rename(basename) { + visited.push(basename); + return basename; + }, + }); + + t.is(visited.length, 2); + t.true(visited.includes('foo.js')); + t.true(visited.includes('foo.ts')); +}); + test('flatten directory tree', async t => { fs.mkdirSync(t.context.tmp); fs.mkdirSync(path.join(t.context.tmp, 'source'));