From 20117a49c7e4e144c62bf070ea0f8e5ab1759e02 Mon Sep 17 00:00:00 2001 From: Roy Revelt Date: Sat, 19 Mar 2022 17:30:14 +0000 Subject: [PATCH] Fix "pattern is too long" error when running `np` (#633) --- source/npm/util.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index 237bbe35..9b5f0d0d 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -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 }