Skip to content

Commit

Permalink
🐛 Filter out any node_modules folder that begins with a .
Browse files Browse the repository at this point in the history
As mentioned in #11 even though we were ignoring `.bin`, `.cache` was falling through our check and we should actually ignore any node_modules folder that starts with a `.` because there are no packages/organizations that start with a `.`
  • Loading branch information
obahareth committed Jul 5, 2019
1 parent 6de44df commit c8bfcb6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/modules-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,17 @@ export class ModulesChecker {
.filter(isDirectory)
}

const getLeafFolderName = (path: string): string => {
const needle = 'node_modules/'
const indexOfLastSlash = path.lastIndexOf(needle)
return path.substr(indexOfLastSlash + needle.length)
}

let nodeModules = getDirectories(nodeModulesPath)
.filter(entry => !entry.endsWith('.bin'))
.filter(entry => {
const leafFolderName = getLeafFolderName(entry)
return !leafFolderName.startsWith('.')
})
.map(entry => {
// If this is a scope (folder starts with @), return all
// folders inside it (scoped packages)
Expand All @@ -170,11 +179,9 @@ export class ModulesChecker {
// Remove path from all strings
// e.g. turn bla/bla/node_modules/@babel/core
// into @babel/core
nodeModules = flatten(nodeModules).map((entry: string) => {
const needle = 'node_modules/'
const indexOfLastSlash = entry.lastIndexOf(needle)
return entry.substr(indexOfLastSlash + needle.length)
})
nodeModules = flatten(nodeModules).map((entry: string) =>
getLeafFolderName(entry)
)

return nodeModules
}
Expand Down

0 comments on commit c8bfcb6

Please sign in to comment.