Skip to content

Commit 9cff6da

Browse files
bunysaeitaisteinherzsindresorhus
authored
Fix error "glob pattern string required" (#616)
Co-authored-by: Itai Steinherz <itaisteinherz@gmail.com> Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 20117a4 commit 9cff6da

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

integration-test

source/npm/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ async function getFilesIgnoredByDotnpmignore(pkg, fileList) {
167167
}
168168

169169
function filterFileList(globArray, fileList) {
170+
if (globArray.length === 0) {
171+
return [];
172+
}
173+
170174
const globString = globArray.length > 1 ? `{${globArray.filter(singlePath => excludeGitAndNodeModulesPaths(singlePath))}}` : globArray[0];
171175
return fileList.filter(minimatch.filter(globString, {matchBase: true, dot: true})); // eslint-disable-line unicorn/no-fn-reference-in-iterator
172176
}

test/npmignore.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,23 @@ test('first time published files - ignore strategy is not used', async t => {
152152
});
153153
t.deepEqual(await testedModule.getFirstTimePublishedFiles({name: 'no ignore strategy'}, newFiles), ['source/ignore.txt', 'source/pay_attention.txt', 'test/file.txt']);
154154
});
155+
156+
test('first time published files - empty files property', async t => {
157+
const testedModule = proxyquire('../source/npm/util', {
158+
'pkg-dir':
159+
{
160+
sync: () => path.resolve('test', 'fixtures', 'package')
161+
}
162+
});
163+
t.deepEqual(await testedModule.getFirstTimePublishedFiles({files: []}, newFiles), []);
164+
});
165+
166+
test('first time published files - .npmignore excludes everything', async t => {
167+
const testedModule = proxyquire('../source/npm/util', {
168+
'pkg-dir':
169+
{
170+
sync: () => path.resolve('test', 'fixtures', 'npmignore')
171+
}
172+
});
173+
t.deepEqual(await testedModule.getFirstTimePublishedFiles({name: 'excluded everything'}, ['source/ignore.txt']), []);
174+
});

0 commit comments

Comments
 (0)