From 4a57cd4daa669843054b1efb51ac7962bd0f841a Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Fri, 9 Dec 2022 19:41:02 +0100 Subject: [PATCH 1/3] Fixes exception in a top path edge case The gitignore is throwing an exception when dealing with absolute paths if that path is the very same as the working directory. This is the case when both `expandDirectories: false` and `onlyFiles: false` are set and the input is `.` and the `cwd` is set to an absolute path. I ran across this when using `globby` in a project of mine and I reproduced it with a test case here and then fixed it. --- ignore.js | 2 +- tests/globby.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ignore.js b/ignore.js index c6172f9..def6466 100644 --- a/ignore.js +++ b/ignore.js @@ -52,7 +52,7 @@ const getIsIgnoredPredicate = (files, cwd) => { return fileOrDirectory => { fileOrDirectory = toPath(fileOrDirectory); fileOrDirectory = toRelativePath(fileOrDirectory, cwd); - return ignores.ignores(slash(fileOrDirectory)); + return fileOrDirectory && ignores.ignores(slash(fileOrDirectory)); }; }; diff --git a/tests/globby.js b/tests/globby.js index 2bc8e17..3166820 100644 --- a/tests/globby.js +++ b/tests/globby.js @@ -190,6 +190,16 @@ test('expandDirectories and ignores option', async t => { }), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); }); +test('absolute:true, expandDirectories:false, onlyFiles:false, gitignore:true and top level folder', async t => { + t.deepEqual(await runGlobby(t, '.', { + absolute: true, + cwd: path.resolve(temporary), + expandDirectories: false, + gitignore: true, + onlyFiles: false, + }), [path.resolve(temporary)]); +}); + test.serial.failing('relative paths and ignores option', async t => { process.chdir(temporary); for (const cwd of getPathValues(process.cwd())) { From b9b5eca930acd810b006676931ad3362fce16c6d Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Sat, 10 Dec 2022 12:25:14 +0100 Subject: [PATCH 2/3] Fix feedback --- ignore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignore.js b/ignore.js index def6466..7de494a 100644 --- a/ignore.js +++ b/ignore.js @@ -52,7 +52,7 @@ const getIsIgnoredPredicate = (files, cwd) => { return fileOrDirectory => { fileOrDirectory = toPath(fileOrDirectory); fileOrDirectory = toRelativePath(fileOrDirectory, cwd); - return fileOrDirectory && ignores.ignores(slash(fileOrDirectory)); + return fileOrDirectory ? ignores.ignores(slash(fileOrDirectory)) : false; }; }; From 6cc9ed3b317a2b8089b564ae75c368b20f2abcd0 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Sat, 10 Dec 2022 12:28:57 +0100 Subject: [PATCH 3/3] Fix tests on windows --- tests/globby.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/globby.js b/tests/globby.js index 3166820..487b239 100644 --- a/tests/globby.js +++ b/tests/globby.js @@ -191,13 +191,16 @@ test('expandDirectories and ignores option', async t => { }); test('absolute:true, expandDirectories:false, onlyFiles:false, gitignore:true and top level folder', async t => { - t.deepEqual(await runGlobby(t, '.', { + const result = await runGlobby(t, '.', { absolute: true, cwd: path.resolve(temporary), expandDirectories: false, gitignore: true, onlyFiles: false, - }), [path.resolve(temporary)]); + }); + + t.is(result.length, 1); + t.truthy(result[0].endsWith(temporary)); }); test.serial.failing('relative paths and ignores option', async t => {