From 9cff6da0af6d94466cd63242803206a71467f3be Mon Sep 17 00:00:00 2001 From: Bunyanuch Saengnet <53788417+bunysae@users.noreply.github.com> Date: Sat, 19 Mar 2022 17:39:12 +0000 Subject: [PATCH] Fix error "glob pattern string required" (#616) Co-authored-by: Itai Steinherz Co-authored-by: Sindre Sorhus --- integration-test | 2 +- source/npm/util.js | 4 ++++ test/npmignore.js | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/integration-test b/integration-test index ae82745e..b2492e19 160000 --- a/integration-test +++ b/integration-test @@ -1 +1 @@ -Subproject commit ae82745e85ff662a569d64c896cb53b80091e654 +Subproject commit b2492e190f3864f96955a7acb4349bb9722530b9 diff --git a/source/npm/util.js b/source/npm/util.js index 9b5f0d0d..1443cc01 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -167,6 +167,10 @@ async function getFilesIgnoredByDotnpmignore(pkg, fileList) { } function filterFileList(globArray, fileList) { + if (globArray.length === 0) { + return []; + } + const globString = globArray.length > 1 ? `{${globArray.filter(singlePath => excludeGitAndNodeModulesPaths(singlePath))}}` : globArray[0]; return fileList.filter(minimatch.filter(globString, {matchBase: true, dot: true})); // eslint-disable-line unicorn/no-fn-reference-in-iterator } diff --git a/test/npmignore.js b/test/npmignore.js index 90ee91ed..8bb40c97 100644 --- a/test/npmignore.js +++ b/test/npmignore.js @@ -152,3 +152,23 @@ test('first time published files - ignore strategy is not used', async t => { }); t.deepEqual(await testedModule.getFirstTimePublishedFiles({name: 'no ignore strategy'}, newFiles), ['source/ignore.txt', 'source/pay_attention.txt', 'test/file.txt']); }); + +test('first time published files - empty files property', async t => { + const testedModule = proxyquire('../source/npm/util', { + 'pkg-dir': + { + sync: () => path.resolve('test', 'fixtures', 'package') + } + }); + t.deepEqual(await testedModule.getFirstTimePublishedFiles({files: []}, newFiles), []); +}); + +test('first time published files - .npmignore excludes everything', async t => { + const testedModule = proxyquire('../source/npm/util', { + 'pkg-dir': + { + sync: () => path.resolve('test', 'fixtures', 'npmignore') + } + }); + t.deepEqual(await testedModule.getFirstTimePublishedFiles({name: 'excluded everything'}, ['source/ignore.txt']), []); +});