Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude node_modules and .git subpaths from minimatch input string #633

Merged
merged 1 commit into from
Mar 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions source/npm/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,20 @@ function npmignoreExistsInPackageRootDir() {
return fs.existsSync(path.resolve(rootDir, '.npmignore'));
}

function excludeGitAndNodeModulesPaths(singlePath) {
return !singlePath.startsWith('.git/') && !singlePath.startsWith('node_modules/');
}

async function getFilesIgnoredByDotnpmignore(pkg, fileList) {
const allowList = await ignoreWalker({
const allowList = (await ignoreWalker({
path: pkgDir.sync(),
ignoreFiles: ['.npmignore']
});
})).filter(singlePath => excludeGitAndNodeModulesPaths(singlePath));
return fileList.filter(minimatch.filter(getIgnoredFilesGlob(allowList, pkg.directories), {matchBase: true, dot: true}));
}

function filterFileList(globArray, fileList) {
const globString = globArray.length > 1 ? `{${globArray}}` : globArray[0];
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