diff --git a/lib/index.js b/lib/index.js index e4a2e76..ca7b2e6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,11 +33,14 @@ const fs = require('fs') const glob = require('glob') const globify = pattern => pattern.split('\\').join('/') -const readOutOfTreeIgnoreFiles = (root, rel, result = '') => { - for (const file of ['.gitignore', '.npmignore']) { +const readOutOfTreeIgnoreFiles = (root, rel, result = '', ignorefileNames = ['.npmignore', '.gitignore']) => { + + for (const file of ignorefileNames) { try { const ignoreContent = fs.readFileSync(path.join(root, file), { encoding: 'utf8' }) - result += ignoreContent + '\n' + result = ignoreContent + '\n' + result; + ignorefileNames=[file] + break } catch (err) { // we ignore ENOENT errors completely because we don't care if the file doesn't exist // but we throw everything else because failing to read a file that does exist is @@ -57,7 +60,7 @@ const readOutOfTreeIgnoreFiles = (root, rel, result = '') => { const newRoot = path.join(root, firstRel) const newRel = path.relative(newRoot, path.join(root, rel)) - return readOutOfTreeIgnoreFiles(newRoot, newRel, result) + return readOutOfTreeIgnoreFiles(newRoot, newRel, result, ignorefileNames) } const pathHasPkg = (input) => {