From af5d139b8e2bb49a3033d4a68ab85f3447c50198 Mon Sep 17 00:00:00 2001 From: Rick Date: Sun, 11 Feb 2024 17:47:54 +0800 Subject: [PATCH] Fix `expandDirectories.extension` option (#263) --- index.js | 2 +- tests/globby.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 450559a..1847350 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ const getDirectoryGlob = ({directoryPath, files, extensions}) => { const extensionGlob = extensions?.length > 0 ? `.${extensions.length > 1 ? `{${extensions.join(',')}}` : extensions[0]}` : ''; return files ? files.map(file => nodePath.posix.join(directoryPath, `**/${nodePath.extname(file) ? file : `${file}${extensionGlob}`}`)) - : [nodePath.posix.join(directoryPath, `**${extensionGlob ? `/${extensionGlob}` : ''}`)]; + : [nodePath.posix.join(directoryPath, `**${extensionGlob ? `/*${extensionGlob}` : ''}`)]; }; const directoryToGlob = async (directoryPaths, { diff --git a/tests/globby.js b/tests/globby.js index 127b0f0..e2067a6 100644 --- a/tests/globby.js +++ b/tests/globby.js @@ -165,6 +165,11 @@ test('expandDirectories option', async t => { }, ignore: ['**/b.tmp'], }), ['tmp/a.tmp']); + t.deepEqual(await runGlobby(t, temporary, { + expandDirectories: { + extensions: ['tmp'], + }, + }), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); }); test('expandDirectories:true and onlyFiles:true option', async t => {