Skip to content

Commit

Permalink
Fix error "glob pattern string required" (#616)
Browse files Browse the repository at this point in the history
Co-authored-by: Itai Steinherz <[email protected]>
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2022
1 parent 20117a4 commit 9cff6da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion integration-test
4 changes: 4 additions & 0 deletions source/npm/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions test/npmignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']), []);
});

0 comments on commit 9cff6da

Please sign in to comment.