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

fix(#106): concatenate ignorefile from root to leaf, acquire ignorefile type from leaf to root. #107

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 7 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => {
Expand Down